diff --git a/controllers/itemdetail.go b/controllers/itemdetail.go index 09774f3ff..95d393fb9 100644 --- a/controllers/itemdetail.go +++ b/controllers/itemdetail.go @@ -64,21 +64,31 @@ func (idc *ItemDetailController) Get() { if sessionUserID != nil { - idc.Data["Username"] = idc.GetSession("username") - idc.Data["UserId"] = sessionUserID.(int) + userID := sessionUserID.(int) - roleList, err := dao.GetUserProjectRoles(models.User{UserID: sessionUserID.(int)}, projectID) + idc.Data["Username"] = idc.GetSession("username") + idc.Data["UserId"] = userID + + roleList, err := dao.GetUserProjectRoles(models.User{UserID: userID}, projectID) if err != nil { beego.Error("Error occurred in GetUserProjectRoles:", err) idc.CustomAbort(http.StatusInternalServerError, "Internal error.") } - if project.Public == 0 && len(roleList) == 0 { + isAdmin, err := dao.IsAdminRole(userID) + if err != nil { + beego.Error("Error occurred in IsAdminRole:", err) + idc.CustomAbort(http.StatusInternalServerError, "Internal error.") + } + + if !isAdmin && (project.Public == 0 && len(roleList) == 0) { idc.Redirect("/registry/project", http.StatusFound) return } - if len(roleList) > 0 { + if isAdmin { + idc.Data["RoleId"] = models.SYSADMIN + } else if len(roleList) > 0 { idc.Data["RoleId"] = roleList[0].RoleID } } diff --git a/static/resources/js/item-detail.js b/static/resources/js/item-detail.js index 55173002d..4b4477cd7 100644 --- a/static/resources/js/item-detail.js +++ b/static/resources/js/item-detail.js @@ -152,7 +152,7 @@ jQuery(function(){ url: "/api/projects/" + $("#projectId").val() + "/members/current", type: "get", success: function(data, status, xhr){ - if(xhr && xhr.status == 200 && data.roles.length > 0){ + if(xhr && xhr.status == 200 && data.roles != null && data.roles.length > 0){ hasAuthorization = true; } }