From 8ae5e46d63f89ff4680cb6164d9c609f051fba29 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Thu, 25 May 2017 14:44:05 +0800 Subject: [PATCH] refactor config API --- src/ui/api/config.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/ui/api/config.go b/src/ui/api/config.go index 0c0d0f0bb..42bac0e54 100644 --- a/src/ui/api/config.go +++ b/src/ui/api/config.go @@ -20,7 +20,6 @@ import ( "strconv" "github.com/vmware/harbor/src/common" - "github.com/vmware/harbor/src/common/api" "github.com/vmware/harbor/src/common/dao" "github.com/vmware/harbor/src/common/utils/log" "github.com/vmware/harbor/src/ui/config" @@ -91,20 +90,19 @@ var ( // ConfigAPI ... type ConfigAPI struct { - api.BaseAPI + BaseController } // Prepare validates the user func (c *ConfigAPI) Prepare() { - userID := c.ValidateUser() - isSysAdmin, err := dao.IsAdminRole(userID) - if err != nil { - log.Errorf("failed to check the role of user: %v", err) - c.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) + c.BaseController.Prepare() + if !c.SecurityCtx.IsAuthenticated() { + c.HandleUnauthorized() + return } - - if !isSysAdmin { - c.CustomAbort(http.StatusForbidden, http.StatusText(http.StatusForbidden)) + if !c.SecurityCtx.IsSysAdmin() { + c.HandleForbidden(c.SecurityCtx.GetUsername()) + return } }