CLI: Restore user accounts on demand #98

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer
2023-02-20 20:24:04 +01:00
parent 5f808cddb4
commit 7c63a86f80
8 changed files with 115 additions and 27 deletions

View File

@@ -3,13 +3,13 @@ package commands
import (
"fmt"
"github.com/photoprism/photoprism/pkg/rnd"
"github.com/manifoldco/promptui"
"github.com/urfave/cli"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/pkg/clean"
"github.com/photoprism/photoprism/pkg/rnd"
)
// UsersModCommand configures the command name, flags, and action.
@@ -46,6 +46,21 @@ func usersModAction(ctx *cli.Context) error {
return fmt.Errorf("user %s not found", clean.LogQuote(id))
}
// Check if account exists but is deleted.
if m.Deleted() {
prompt := promptui.Prompt{
Label: fmt.Sprintf("Restore user %s?", m.String()),
IsConfirm: true,
}
if _, err := prompt.Run(); err != nil {
return fmt.Errorf("user already exists")
}
m.DeletedAt = nil
log.Infof("user %s will be restored", m.String())
}
// Set values.
if err := m.SetValuesFromCli(ctx); err != nil {
return err