harbor/controllers/ng/dashboard.go

39 lines
906 B
Go
Raw Normal View History

2016-04-11 10:07:16 +02:00
package ng
import (
"net/http"
"github.com/vmware/harbor/dao"
"github.com/vmware/harbor/models"
"github.com/vmware/harbor/utils/log"
)
2016-05-23 09:43:15 +02:00
// DashboardController handles requests to /ng/dashboard
2016-04-11 10:07:16 +02:00
type DashboardController struct {
BaseController
}
2016-05-23 09:43:15 +02:00
// Get renders the dashboard page
2016-04-11 10:07:16 +02:00
func (dc *DashboardController) Get() {
sessionUserID := dc.GetSession("userId")
var isAdmin int
if sessionUserID != nil {
userID := sessionUserID.(int)
u, err := dao.GetUser(models.User{UserID: userID})
if err != nil {
log.Errorf("Error occurred in GetUser, error: %v", err)
dc.CustomAbort(http.StatusInternalServerError, "Internal error.")
}
if u == nil {
log.Warningf("User was deleted already, user id: %d, canceling request.", userID)
dc.CustomAbort(http.StatusUnauthorized, "")
}
isAdmin = u.HasAdminRole
}
dc.Data["IsAdmin"] = isAdmin
2016-04-11 10:07:16 +02:00
dc.Forward("Dashboard", "dashboard.htm")
}