2022-09-28 09:01:17 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/dustin/go-humanize/english"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
|
|
|
"github.com/photoprism/photoprism/internal/query"
|
|
|
|
"github.com/photoprism/photoprism/pkg/report"
|
2022-10-14 02:48:23 +02:00
|
|
|
"github.com/photoprism/photoprism/pkg/txt"
|
2022-09-28 09:01:17 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// UsersListCommand configures the command name, flags, and action.
|
|
|
|
var UsersListCommand = cli.Command{
|
|
|
|
Name: "ls",
|
|
|
|
Usage: "Displays existing user accounts",
|
|
|
|
Flags: report.CliFlags,
|
|
|
|
Action: usersListAction,
|
|
|
|
}
|
|
|
|
|
|
|
|
// usersListAction displays existing user accounts.
|
|
|
|
func usersListAction(ctx *cli.Context) error {
|
|
|
|
return CallWithDependencies(ctx, func(conf *config.Config) error {
|
2023-03-09 15:12:10 +01:00
|
|
|
cols := []string{"UID", "Username", "Role", "Authentication", "Super Admin", "Web Login", "Last Login", "WebDAV"}
|
2022-09-28 09:01:17 +02:00
|
|
|
|
|
|
|
// Fetch users from database.
|
|
|
|
users := query.RegisteredUsers()
|
|
|
|
rows := make([][]string, len(users))
|
|
|
|
|
|
|
|
// Show log message.
|
|
|
|
log.Infof("found %s", english.Plural(len(users), "user", "users"))
|
|
|
|
|
|
|
|
// Display report.
|
|
|
|
for i, user := range users {
|
|
|
|
rows[i] = []string{
|
|
|
|
user.UID(),
|
2023-03-08 23:30:39 +01:00
|
|
|
user.Username(),
|
2023-03-09 15:12:10 +01:00
|
|
|
user.AclRole().Pretty(),
|
|
|
|
user.Provider().Pretty(),
|
2022-09-28 09:01:17 +02:00
|
|
|
report.Bool(user.SuperAdmin, report.Yes, report.No),
|
2022-10-13 22:11:02 +02:00
|
|
|
report.Bool(user.CanLogIn(), report.Enabled, report.Disabled),
|
2023-03-09 15:12:10 +01:00
|
|
|
txt.TimeStamp(user.LoginAt),
|
2022-10-13 22:11:02 +02:00
|
|
|
report.Bool(user.CanUseWebDAV(), report.Enabled, report.Disabled),
|
2022-09-28 09:01:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-10 16:34:07 +02:00
|
|
|
result, err := report.RenderFormat(rows, cols, report.CliFormat(ctx))
|
2022-09-28 09:01:17 +02:00
|
|
|
|
|
|
|
fmt.Printf("\n%s\n", result)
|
|
|
|
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
}
|