mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-05 01:59:44 +01:00
Merge pull request #2381 from ywk253100/170525_config
Refactor config API
This commit is contained in:
commit
0ede4bca7b
@ -20,7 +20,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/vmware/harbor/src/common"
|
"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/dao"
|
||||||
"github.com/vmware/harbor/src/common/utils/log"
|
"github.com/vmware/harbor/src/common/utils/log"
|
||||||
"github.com/vmware/harbor/src/ui/config"
|
"github.com/vmware/harbor/src/ui/config"
|
||||||
@ -91,20 +90,19 @@ var (
|
|||||||
|
|
||||||
// ConfigAPI ...
|
// ConfigAPI ...
|
||||||
type ConfigAPI struct {
|
type ConfigAPI struct {
|
||||||
api.BaseAPI
|
BaseController
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare validates the user
|
// Prepare validates the user
|
||||||
func (c *ConfigAPI) Prepare() {
|
func (c *ConfigAPI) Prepare() {
|
||||||
userID := c.ValidateUser()
|
c.BaseController.Prepare()
|
||||||
isSysAdmin, err := dao.IsAdminRole(userID)
|
if !c.SecurityCtx.IsAuthenticated() {
|
||||||
if err != nil {
|
c.HandleUnauthorized()
|
||||||
log.Errorf("failed to check the role of user: %v", err)
|
return
|
||||||
c.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError))
|
|
||||||
}
|
}
|
||||||
|
if !c.SecurityCtx.IsSysAdmin() {
|
||||||
if !isSysAdmin {
|
c.HandleForbidden(c.SecurityCtx.GetUsername())
|
||||||
c.CustomAbort(http.StatusForbidden, http.StatusText(http.StatusForbidden))
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user