You've already forked filebrowser
mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-11-26 14:25:26 +08:00
- In the root command, all flags are now correctly available as environmental variables, except for `--config` flag. This was already supposed to be the case, but due to bugs in the implementation it didn't work properly. - All configuration options (unless I missed something) that are available as flags should now properly update the configuration when using the `config init` and `config set` commands. - Flag names are now consistently in the lowerCamelCase format. All flags that were in a different format have been updated in a backwards compatible way. For a transitionary period of at least 6 months, both will work: - `--dir-mode` --> `--dirMode` - `--hide-login-button` --> `--hideLoginButton` - `--create-user-dir` --> `--createUserDir` - `--minimum-password-length` --> `--minimumPasswordLength` - `--socket-perm` --> `--socketPerm` - `--disable-thumbnails` --> `--disableThumbnails` - `--disable-preview-resize` --> `--disablePreviewResize` - `--disable-exec` --> `--disableExec` - `--disable-type-detection-by-header` --> `--disableTypeDetectionByHeader` - `--img-processors` --> `--imageProcessors` - `--cache-dir` --> `--cacheDir` - `--token-expiration-time` --> `--tokenExpirationTime` - `--baseurl` --> `--baseURL`
110 lines
2.3 KiB
Go
110 lines
2.3 KiB
Go
package cmd
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/filebrowser/filebrowser/v2/settings"
|
|
"github.com/filebrowser/filebrowser/v2/users"
|
|
)
|
|
|
|
func init() {
|
|
usersCmd.AddCommand(usersUpdateCmd)
|
|
|
|
usersUpdateCmd.Flags().StringP("password", "p", "", "new password")
|
|
usersUpdateCmd.Flags().StringP("username", "u", "", "new username")
|
|
addUserFlags(usersUpdateCmd.Flags())
|
|
}
|
|
|
|
var usersUpdateCmd = &cobra.Command{
|
|
Use: "update <id|username>",
|
|
Short: "Updates an existing user",
|
|
Long: `Updates an existing user. Set the flags for the
|
|
options you want to change.`,
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: python(func(cmd *cobra.Command, args []string, d *pythonData) error {
|
|
flags := cmd.Flags()
|
|
username, id := parseUsernameOrID(args[0])
|
|
password, err := flags.GetString("password")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
newUsername, err := flags.GetString("username")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
s, err := d.store.Settings.Get()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var (
|
|
user *users.User
|
|
)
|
|
if id != 0 {
|
|
user, err = d.store.Users.Get("", id)
|
|
} else {
|
|
user, err = d.store.Users.Get("", username)
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
defaults := settings.UserDefaults{
|
|
Scope: user.Scope,
|
|
Locale: user.Locale,
|
|
ViewMode: user.ViewMode,
|
|
SingleClick: user.SingleClick,
|
|
Perm: user.Perm,
|
|
Sorting: user.Sorting,
|
|
Commands: user.Commands,
|
|
}
|
|
|
|
err = getUserDefaults(flags, &defaults, false)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user.Scope = defaults.Scope
|
|
user.Locale = defaults.Locale
|
|
user.ViewMode = defaults.ViewMode
|
|
user.SingleClick = defaults.SingleClick
|
|
user.Perm = defaults.Perm
|
|
user.Commands = defaults.Commands
|
|
user.Sorting = defaults.Sorting
|
|
user.LockPassword, err = flags.GetBool("lockPassword")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user.DateFormat, err = flags.GetBool("dateFormat")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user.HideDotfiles, err = flags.GetBool("hideDotfiles")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if newUsername != "" {
|
|
user.Username = newUsername
|
|
}
|
|
|
|
if password != "" {
|
|
user.Password, err = users.ValidateAndHashPwd(password, s.MinimumPasswordLength)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
err = d.store.Users.Update(user)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
printUsers([]*users.User{user})
|
|
return nil
|
|
}, pythonConfig{}),
|
|
}
|