Merge pull request #1960 from ywk253100/170407_role

Donot add projectadmin role to sysadmin when return roles, fix #1957
This commit is contained in:
Daniel Jiang 2017-04-07 19:16:33 +08:00 committed by GitHub
commit 9327fd2c66
2 changed files with 15 additions and 22 deletions

View File

@ -297,17 +297,14 @@ func (p *ProjectAPI) List() {
for i := 0; i < len(projectList); i++ {
if public != 1 {
if isAdmin {
projectList[i].Role = models.PROJECTADMIN
} else {
roles, err := dao.GetUserProjectRoles(p.userID, projectList[i].ProjectID)
if err != nil {
log.Errorf("failed to get user's project role: %v", err)
p.CustomAbort(http.StatusInternalServerError, "")
}
projectList[i].Role = roles[0].RoleID
roles, err := dao.GetUserProjectRoles(p.userID, projectList[i].ProjectID)
if err != nil {
log.Errorf("failed to get user's project role: %v", err)
p.CustomAbort(http.StatusInternalServerError, "")
}
if projectList[i].Role == models.PROJECTADMIN {
projectList[i].Role = roles[0].RoleID
if projectList[i].Role == models.PROJECTADMIN ||
isAdmin {
projectList[i].Togglable = true
}
}

View File

@ -78,20 +78,16 @@ func (s *SearchAPI) Get() {
}
if userID != dao.NonExistUserID {
if isSysAdmin {
p.Role = models.PROJECTADMIN
} else {
roles, err := dao.GetUserProjectRoles(userID, p.ProjectID)
if err != nil {
log.Errorf("failed to get user's project role: %v", err)
s.CustomAbort(http.StatusInternalServerError, "")
}
if len(roles) != 0 {
p.Role = roles[0].RoleID
}
roles, err := dao.GetUserProjectRoles(userID, p.ProjectID)
if err != nil {
log.Errorf("failed to get user's project role: %v", err)
s.CustomAbort(http.StatusInternalServerError, "")
}
if len(roles) != 0 {
p.Role = roles[0].RoleID
}
if p.Role == models.PROJECTADMIN {
if p.Role == models.PROJECTADMIN || isSysAdmin {
p.Togglable = true
}
}