Skip to content

Commit

Permalink
Merge pull request #70 from Althaf66/Althaf66/EnhanceElevate
Browse files Browse the repository at this point in the history
feat: Created confirmation for elevating user to admin
  • Loading branch information
Vad1mo authored Sep 17, 2024
2 parents bee5b7b + b6baf48 commit b164280
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cmd/harbor/root/user/elevate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/goharbor/harbor-cli/pkg/api"
"github.com/goharbor/harbor-cli/pkg/prompt"
"github.com/goharbor/harbor-cli/pkg/views"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand All @@ -25,10 +26,12 @@ func ElevateUserCmd() *cobra.Command {
userId = prompt.GetUserIdFromUser()
}

// Todo : Ask for the confirmation before elevating the user to admin role

err = api.ElevateUser(userId)

confirm, err := views.ConfirmElevation()
if confirm {
err = api.ElevateUser(userId)
} else {
log.Error("Permission denied for elevate user to admin.")
}
if err != nil {
log.Errorf("failed to elevate user: %v", err)
}
Expand Down
21 changes: 21 additions & 0 deletions pkg/views/confirmation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package views

import (
"github.com/charmbracelet/huh"
log "github.com/sirupsen/logrus"
)

func ConfirmElevation() (bool, error) {
var confirm bool

err := huh.NewConfirm().
Title("Are you sure to elevate the user to admin role?").
Affirmative("Yes").
Negative("No").
Value(&confirm).Run()
if err != nil {
log.Fatal(err)
}

return confirm, nil
}

0 comments on commit b164280

Please sign in to comment.