From 1314ff92f5ac2183eab55190022c762800910450 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Wed, 24 May 2017 18:29:24 +0800 Subject: [PATCH] refactor sync registry API --- src/ui/api/internal.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/ui/api/internal.go b/src/ui/api/internal.go index d306eb921..1d3c45987 100644 --- a/src/ui/api/internal.go +++ b/src/ui/api/internal.go @@ -16,29 +16,23 @@ package api import ( "net/http" - - "github.com/vmware/harbor/src/common/dao" - "github.com/vmware/harbor/src/common/utils/log" - "github.com/vmware/harbor/src/common/api" ) // InternalAPI handles request of harbor admin... type InternalAPI struct { - api.BaseAPI + BaseController } // Prepare validates the URL and parms func (ia *InternalAPI) Prepare() { - var currentUserID int - currentUserID = ia.ValidateUser() - isAdmin, err := dao.IsAdminRole(currentUserID) - if err != nil { - log.Errorf("Error occurred in IsAdminRole:%v", err) - ia.CustomAbort(http.StatusInternalServerError, "Internal error.") + ia.BaseController.Prepare() + if !ia.SecurityCtx.IsAuthenticated() { + ia.HandleUnauthorized() + return } - if !isAdmin { - log.Error("Guests doesn't have the permisson to request harbor internal API.") - ia.CustomAbort(http.StatusForbidden, "Guests doesn't have the permisson to request harbor internal API.") + if !ia.SecurityCtx.IsSysAdmin() { + ia.HandleForbidden(ia.SecurityCtx.GetUsername()) + return } }