mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-18 22:57:38 +01:00
Return role and repository count info in GET project API
This commit is contained in:
parent
340080f9a2
commit
a7a72f78bd
@ -199,6 +199,8 @@ func (p *ProjectAPI) Get() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.populateProperties(p.project)
|
||||||
|
|
||||||
p.Data["json"] = p.project
|
p.Data["json"] = p.project
|
||||||
p.ServeJSON()
|
p.ServeJSON()
|
||||||
}
|
}
|
||||||
@ -372,25 +374,7 @@ func (p *ProjectAPI) List() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, project := range result.Projects {
|
for _, project := range result.Projects {
|
||||||
if p.SecurityCtx.IsAuthenticated() {
|
p.populateProperties(project)
|
||||||
roles := p.SecurityCtx.GetProjectRoles(project.ProjectID)
|
|
||||||
if len(roles) != 0 {
|
|
||||||
project.Role = roles[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if project.Role == common.RoleProjectAdmin ||
|
|
||||||
p.SecurityCtx.IsSysAdmin() {
|
|
||||||
project.Togglable = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repos, err := dao.GetRepositoryByProjectName(project.Name)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("failed to get repositories of project %s: %v", project.Name, err)
|
|
||||||
p.CustomAbort(http.StatusInternalServerError, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
project.RepoCount = len(repos)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p.SetPaginationHeader(result.Total, page, size)
|
p.SetPaginationHeader(result.Total, page, size)
|
||||||
@ -398,6 +382,28 @@ func (p *ProjectAPI) List() {
|
|||||||
p.ServeJSON()
|
p.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *ProjectAPI) populateProperties(project *models.Project) {
|
||||||
|
if p.SecurityCtx.IsAuthenticated() {
|
||||||
|
roles := p.SecurityCtx.GetProjectRoles(project.ProjectID)
|
||||||
|
if len(roles) != 0 {
|
||||||
|
project.Role = roles[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
if project.Role == common.RoleProjectAdmin ||
|
||||||
|
p.SecurityCtx.IsSysAdmin() {
|
||||||
|
project.Togglable = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repos, err := dao.GetRepositoryByProjectName(project.Name)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("failed to get repositories of project %s: %v", project.Name, err)
|
||||||
|
p.CustomAbort(http.StatusInternalServerError, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
project.RepoCount = len(repos)
|
||||||
|
}
|
||||||
|
|
||||||
// Put ...
|
// Put ...
|
||||||
func (p *ProjectAPI) Put() {
|
func (p *ProjectAPI) Put() {
|
||||||
if !p.SecurityCtx.IsAuthenticated() {
|
if !p.SecurityCtx.IsAuthenticated() {
|
||||||
|
Loading…
Reference in New Issue
Block a user