mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-05 01:59:44 +01:00
refactor email API
This commit is contained in:
parent
a901297859
commit
6ee64ba83a
@ -19,8 +19,6 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/vmware/harbor/src/common/api"
|
||||
"github.com/vmware/harbor/src/common/dao"
|
||||
"github.com/vmware/harbor/src/common/utils/email"
|
||||
"github.com/vmware/harbor/src/common/utils/log"
|
||||
"github.com/vmware/harbor/src/ui/config"
|
||||
@ -32,20 +30,20 @@ const (
|
||||
|
||||
// EmailAPI ...
|
||||
type EmailAPI struct {
|
||||
api.BaseAPI
|
||||
BaseController
|
||||
}
|
||||
|
||||
// Prepare ...
|
||||
func (e *EmailAPI) Prepare() {
|
||||
userID := e.ValidateUser()
|
||||
isSysAdmin, err := dao.IsAdminRole(userID)
|
||||
if err != nil {
|
||||
log.Errorf("failed to check the role of user: %v", err)
|
||||
e.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError))
|
||||
e.BaseController.Prepare()
|
||||
if !e.SecurityCtx.IsAuthenticated() {
|
||||
e.HandleUnauthorized()
|
||||
return
|
||||
}
|
||||
|
||||
if !isSysAdmin {
|
||||
e.CustomAbort(http.StatusForbidden, http.StatusText(http.StatusForbidden))
|
||||
if !e.SecurityCtx.IsSysAdmin() {
|
||||
e.HandleForbidden(e.SecurityCtx.GetUsername())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user