mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-28 03:27:41 +01:00
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package controllers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/vmware/harbor/dao"
|
|
"github.com/vmware/harbor/models"
|
|
"github.com/vmware/harbor/utils/log"
|
|
)
|
|
|
|
// NavigationHeaderController handles requests to /navigation_header
|
|
type NavigationHeaderController struct {
|
|
BaseController
|
|
}
|
|
|
|
// Get renders user's navigation header
|
|
func (nhc *NavigationHeaderController) Get() {
|
|
sessionUserID := nhc.GetSession("userId")
|
|
var hasLoggedIn bool
|
|
var isAdmin int
|
|
if sessionUserID != nil {
|
|
hasLoggedIn = true
|
|
userID := sessionUserID.(int)
|
|
u, err := dao.GetUser(models.User{UserID: userID})
|
|
if err != nil {
|
|
log.Errorf("Error occurred in GetUser, error: %v", err)
|
|
nhc.CustomAbort(http.StatusInternalServerError, "Internal error.")
|
|
}
|
|
if u == nil {
|
|
log.Warningf("User was deleted already, user id: %d, canceling request.", userID)
|
|
nhc.CustomAbort(http.StatusUnauthorized, "")
|
|
}
|
|
isAdmin = u.HasAdminRole
|
|
}
|
|
nhc.Data["HasLoggedIn"] = hasLoggedIn
|
|
nhc.Data["IsAdmin"] = isAdmin
|
|
nhc.TplName = "navigation-header.htm"
|
|
nhc.Render()
|
|
}
|