From f97108f32d4cc32794906b49a523f1107a3538e0 Mon Sep 17 00:00:00 2001 From: Althaf66 Date: Sat, 8 Jun 2024 13:17:48 +0530 Subject: [PATCH 1/4] created confirmation Signed-off-by: Althaf66 --- cmd/harbor/root/user/elevate.go | 11 +++++++---- pkg/views/confirmation.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 pkg/views/confirmation.go diff --git a/cmd/harbor/root/user/elevate.go b/cmd/harbor/root/user/elevate.go index 9369b9c7..974a25ba 100644 --- a/cmd/harbor/root/user/elevate.go +++ b/cmd/harbor/root/user/elevate.go @@ -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" ) @@ -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 := views.UserElevateConfirm() + 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) } diff --git a/pkg/views/confirmation.go b/pkg/views/confirmation.go new file mode 100644 index 00000000..4c10082a --- /dev/null +++ b/pkg/views/confirmation.go @@ -0,0 +1,28 @@ +package views + +import ( + "github.com/charmbracelet/huh" + log "github.com/sirupsen/logrus" +) + +func UserElevateConfirm() bool{ + 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 +} + + + + + + + \ No newline at end of file From 4667f2dd9d840fbd80ba24f5291ff29db133e07b Mon Sep 17 00:00:00 2001 From: Althaf66 Date: Sat, 8 Jun 2024 13:27:03 +0530 Subject: [PATCH 2/4] updated confirmation file Signed-off-by: Althaf66 --- cmd/harbor/root/user/elevate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/harbor/root/user/elevate.go b/cmd/harbor/root/user/elevate.go index 974a25ba..19bf5df9 100644 --- a/cmd/harbor/root/user/elevate.go +++ b/cmd/harbor/root/user/elevate.go @@ -26,7 +26,7 @@ func ElevateUserCmd() *cobra.Command { userId = prompt.GetUserIdFromUser() } - confirm := views.UserElevateConfirm() + confirm,err := views.ConfirmElevation() if confirm { err = api.ElevateUser(userId) } else { From a926e8495da42a144247553b00e10000a0143f9e Mon Sep 17 00:00:00 2001 From: Althaf66 Date: Sat, 8 Jun 2024 13:29:12 +0530 Subject: [PATCH 3/4] updated confirmation.go file. Signed-off-by: Althaf66 --- pkg/views/confirmation.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/views/confirmation.go b/pkg/views/confirmation.go index 4c10082a..71f9e291 100644 --- a/pkg/views/confirmation.go +++ b/pkg/views/confirmation.go @@ -5,7 +5,7 @@ import ( log "github.com/sirupsen/logrus" ) -func UserElevateConfirm() bool{ +func ConfirmElevation() (bool, error){ var confirm bool err := huh.NewConfirm(). @@ -17,7 +17,7 @@ func UserElevateConfirm() bool{ log.Fatal(err) } - return confirm + return confirm, nil } From b6baf48f4a69cbe9f38c74de8ce1f7205036d9ae Mon Sep 17 00:00:00 2001 From: Althaf66 Date: Sat, 8 Jun 2024 18:19:39 +0530 Subject: [PATCH 4/4] updated elevate cmd Signed-off-by: Althaf66 --- cmd/harbor/root/user/elevate.go | 2 +- pkg/views/confirmation.go | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/cmd/harbor/root/user/elevate.go b/cmd/harbor/root/user/elevate.go index 19bf5df9..25cc7299 100644 --- a/cmd/harbor/root/user/elevate.go +++ b/cmd/harbor/root/user/elevate.go @@ -26,7 +26,7 @@ func ElevateUserCmd() *cobra.Command { userId = prompt.GetUserIdFromUser() } - confirm,err := views.ConfirmElevation() + confirm, err := views.ConfirmElevation() if confirm { err = api.ElevateUser(userId) } else { diff --git a/pkg/views/confirmation.go b/pkg/views/confirmation.go index 71f9e291..8bbf7067 100644 --- a/pkg/views/confirmation.go +++ b/pkg/views/confirmation.go @@ -5,24 +5,17 @@ import ( log "github.com/sirupsen/logrus" ) -func ConfirmElevation() (bool, error){ +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() + 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 } - - - - - - - \ No newline at end of file