mirror of
https://github.com/miniflux/v2.git
synced 2025-09-15 18:57:04 +00:00
Add option to enable/disable keyboard shortcuts
This commit is contained in:
parent
3c8cc0b2b6
commit
4295a86e55
24 changed files with 183 additions and 112 deletions
106
storage/user.go
106
storage/user.go
|
@ -67,11 +67,14 @@ func (s *Storage) CreateUser(user *model.User) (err error) {
|
|||
}
|
||||
}
|
||||
|
||||
query := `INSERT INTO users
|
||||
(username, password, is_admin, extra)
|
||||
query := `
|
||||
INSERT INTO users
|
||||
(username, password, is_admin, extra)
|
||||
VALUES
|
||||
(LOWER($1), $2, $3, $4)
|
||||
RETURNING id, username, is_admin, language, theme, timezone, entry_direction`
|
||||
(LOWER($1), $2, $3, $4)
|
||||
RETURNING
|
||||
id, username, is_admin, language, theme, timezone, entry_direction, keyboard_shortcuts
|
||||
`
|
||||
|
||||
err = s.db.QueryRow(query, user.Username, password, user.IsAdmin, extra).Scan(
|
||||
&user.ID,
|
||||
|
@ -81,6 +84,7 @@ func (s *Storage) CreateUser(user *model.User) (err error) {
|
|||
&user.Theme,
|
||||
&user.Timezone,
|
||||
&user.EntryDirection,
|
||||
&user.KeyboardShortcuts,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create user: %v", err)
|
||||
|
@ -121,15 +125,19 @@ func (s *Storage) UpdateUser(user *model.User) error {
|
|||
return err
|
||||
}
|
||||
|
||||
query := `UPDATE users SET
|
||||
username=LOWER($1),
|
||||
password=$2,
|
||||
is_admin=$3,
|
||||
theme=$4,
|
||||
language=$5,
|
||||
timezone=$6,
|
||||
entry_direction=$7
|
||||
WHERE id=$8`
|
||||
query := `
|
||||
UPDATE users SET
|
||||
username=LOWER($1),
|
||||
password=$2,
|
||||
is_admin=$3,
|
||||
theme=$4,
|
||||
language=$5,
|
||||
timezone=$6,
|
||||
entry_direction=$7,
|
||||
keyboard_shortcuts=$8
|
||||
WHERE
|
||||
id=$9
|
||||
`
|
||||
|
||||
_, err = s.db.Exec(
|
||||
query,
|
||||
|
@ -140,20 +148,25 @@ func (s *Storage) UpdateUser(user *model.User) error {
|
|||
user.Language,
|
||||
user.Timezone,
|
||||
user.EntryDirection,
|
||||
user.KeyboardShortcuts,
|
||||
user.ID,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to update user: %v", err)
|
||||
}
|
||||
} else {
|
||||
query := `UPDATE users SET
|
||||
username=LOWER($1),
|
||||
is_admin=$2,
|
||||
theme=$3,
|
||||
language=$4,
|
||||
timezone=$5,
|
||||
entry_direction=$6
|
||||
WHERE id=$7`
|
||||
query := `
|
||||
UPDATE users SET
|
||||
username=LOWER($1),
|
||||
is_admin=$2,
|
||||
theme=$3,
|
||||
language=$4,
|
||||
timezone=$5,
|
||||
entry_direction=$6,
|
||||
keyboard_shortcuts=$7
|
||||
WHERE
|
||||
id=$8
|
||||
`
|
||||
|
||||
_, err := s.db.Exec(
|
||||
query,
|
||||
|
@ -163,6 +176,7 @@ func (s *Storage) UpdateUser(user *model.User) error {
|
|||
user.Language,
|
||||
user.Timezone,
|
||||
user.EntryDirection,
|
||||
user.KeyboardShortcuts,
|
||||
user.ID,
|
||||
)
|
||||
|
||||
|
@ -188,10 +202,15 @@ func (s *Storage) UserLanguage(userID int64) (language string) {
|
|||
// UserByID finds a user by the ID.
|
||||
func (s *Storage) UserByID(userID int64) (*model.User, error) {
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByID] userID=%d", userID))
|
||||
query := `SELECT
|
||||
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
|
||||
FROM users
|
||||
WHERE id = $1`
|
||||
query := `
|
||||
SELECT
|
||||
id, username, is_admin, theme, language, timezone, entry_direction, keyboard_shortcuts,
|
||||
last_login_at, extra
|
||||
FROM
|
||||
users
|
||||
WHERE
|
||||
id = $1
|
||||
`
|
||||
|
||||
return s.fetchUser(query, userID)
|
||||
}
|
||||
|
@ -199,10 +218,15 @@ func (s *Storage) UserByID(userID int64) (*model.User, error) {
|
|||
// UserByUsername finds a user by the username.
|
||||
func (s *Storage) UserByUsername(username string) (*model.User, error) {
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByUsername] username=%s", username))
|
||||
query := `SELECT
|
||||
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
|
||||
FROM users
|
||||
WHERE username=LOWER($1)`
|
||||
query := `
|
||||
SELECT
|
||||
id, username, is_admin, theme, language, timezone, entry_direction, keyboard_shortcuts,
|
||||
last_login_at, extra
|
||||
FROM
|
||||
users
|
||||
WHERE
|
||||
username=LOWER($1)
|
||||
`
|
||||
|
||||
return s.fetchUser(query, username)
|
||||
}
|
||||
|
@ -210,10 +234,15 @@ func (s *Storage) UserByUsername(username string) (*model.User, error) {
|
|||
// UserByExtraField finds a user by an extra field value.
|
||||
func (s *Storage) UserByExtraField(field, value string) (*model.User, error) {
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByExtraField] field=%s", field))
|
||||
query := `SELECT
|
||||
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
|
||||
FROM users
|
||||
WHERE extra->$1=$2`
|
||||
query := `
|
||||
SELECT
|
||||
id, username, is_admin, theme, language, timezone, entry_direction, keyboard_shortcuts,
|
||||
last_login_at, extra
|
||||
FROM
|
||||
users
|
||||
WHERE
|
||||
extra->$1=$2
|
||||
`
|
||||
|
||||
return s.fetchUser(query, field, value)
|
||||
}
|
||||
|
@ -230,6 +259,7 @@ func (s *Storage) fetchUser(query string, args ...interface{}) (*model.User, err
|
|||
&user.Language,
|
||||
&user.Timezone,
|
||||
&user.EntryDirection,
|
||||
&user.KeyboardShortcuts,
|
||||
&user.LastLoginAt,
|
||||
&extra,
|
||||
)
|
||||
|
@ -275,9 +305,12 @@ func (s *Storage) Users() (model.Users, error) {
|
|||
defer timer.ExecutionTime(time.Now(), "[Storage:Users]")
|
||||
query := `
|
||||
SELECT
|
||||
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
|
||||
FROM users
|
||||
ORDER BY username ASC`
|
||||
id, username, is_admin, theme, language, timezone, entry_direction, keyboard_shortcuts,
|
||||
last_login_at, extra
|
||||
FROM
|
||||
users
|
||||
ORDER BY username ASC
|
||||
`
|
||||
|
||||
rows, err := s.db.Query(query)
|
||||
if err != nil {
|
||||
|
@ -297,6 +330,7 @@ func (s *Storage) Users() (model.Users, error) {
|
|||
&user.Language,
|
||||
&user.Timezone,
|
||||
&user.EntryDirection,
|
||||
&user.KeyboardShortcuts,
|
||||
&user.LastLoginAt,
|
||||
&extra,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue