Updates for redirections when user is not an admin.

This commit is contained in:
kunw 2016-10-28 16:12:51 +08:00
parent 26b1df4bdb
commit 54696b1112
3 changed files with 19 additions and 11 deletions

View File

@ -1,9 +1,5 @@
package controllers
import (
"net/http"
)
// AccountSettingController handles request to /account_setting
type AccountSettingController struct {
BaseController
@ -19,6 +15,6 @@ func (asc *AccountSettingController) Get() {
if asc.AuthMode == "db_auth" || isAdminForLdap {
asc.Forward("page_title_account_setting", "account-settings.htm")
} else {
asc.CustomAbort(http.StatusForbidden, "")
asc.Redirect("/dashboard", 302)
}
}

View File

@ -1,5 +1,10 @@
package controllers
import (
"github.com/vmware/harbor/src/common/dao"
"github.com/vmware/harbor/src/common/utils/log"
)
// AdminOptionController handles requests to /admin_option
type AdminOptionController struct {
BaseController
@ -7,5 +12,16 @@ type AdminOptionController struct {
// Get renders the admin options page
func (aoc *AdminOptionController) Get() {
aoc.Forward("page_title_admin_option", "admin-options.htm")
sessionUserID, ok := aoc.GetSession("userId").(int)
if ok {
isAdmin, err := dao.IsAdminRole(sessionUserID)
if err != nil {
log.Errorf("Error occurred in IsAdminRole: %v", err)
}
if isAdmin {
aoc.Forward("page_title_admin_option", "admin-options.htm")
return
}
}
aoc.Redirect("/dashboard", 302)
}

View File

@ -1,9 +1,5 @@
package controllers
import (
"net/http"
)
// ChangePasswordController handles request to /change_password
type ChangePasswordController struct {
BaseController
@ -19,6 +15,6 @@ func (cpc *ChangePasswordController) Get() {
if cpc.AuthMode == "db_auth" || isAdminForLdap {
cpc.Forward("page_title_change_password", "change-password.htm")
} else {
cpc.CustomAbort(http.StatusForbidden, "")
cpc.Redirect("/dashboard", 302)
}
}