photoprism/internal/commands/users_ls.go
Michael Mayer f5a8c5a45d Auth: Session and ACL enhancements #98 #1746
Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-09-28 09:01:17 +02:00

55 lines
1.4 KiB
Go

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"
)
// 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 {
cols := []string{"UID", "User Name", "Display Name", "Email", "Role", "Super Admin", "Web Login", "WebDAV", "Attributes"}
// 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(),
user.Name(),
user.FullName(),
user.Email(),
user.AclRole().String(),
report.Bool(user.SuperAdmin, report.Yes, report.No),
report.Bool(user.CanLogin, report.Enabled, report.Disabled),
report.Bool(user.CanSync, report.Enabled, report.Disabled),
user.Attr(),
}
}
result, err := report.Render(rows, cols, report.CliFormat(ctx))
fmt.Printf("\n%s\n", result)
return err
})
}