configstore: report project/projectgroup owners
Return project and projectgroup owner type (user or org) and their id.
This commit is contained in:
parent
81d656b7a3
commit
af67198dec
|
@ -36,6 +36,8 @@ type Project struct {
|
|||
*types.Project
|
||||
|
||||
// dynamic data
|
||||
OwnerType types.ConfigType
|
||||
OwnerID string
|
||||
Path string
|
||||
ParentPath string
|
||||
GlobalVisibility types.Visibility
|
||||
|
@ -59,6 +61,11 @@ func projectsResponse(readDB *readdb.ReadDB, projects []*types.Project) ([]*Proj
|
|||
return err
|
||||
}
|
||||
|
||||
ownerType, ownerID, err := readDB.GetProjectOwnerID(tx, project)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// calculate global visibility
|
||||
visibility, err := getGlobalVisibility(readDB, tx, project.Visibility, &project.Parent)
|
||||
if err != nil {
|
||||
|
@ -69,6 +76,8 @@ func projectsResponse(readDB *readdb.ReadDB, projects []*types.Project) ([]*Proj
|
|||
// updated on create
|
||||
resProjects[i] = &Project{
|
||||
Project: project,
|
||||
OwnerType: ownerType,
|
||||
OwnerID: ownerID,
|
||||
Path: path.Join(pp, project.Name),
|
||||
ParentPath: pp,
|
||||
GlobalVisibility: visibility,
|
||||
|
|
|
@ -36,6 +36,8 @@ type ProjectGroup struct {
|
|||
*types.ProjectGroup
|
||||
|
||||
// dynamic data
|
||||
OwnerType types.ConfigType
|
||||
OwnerID string
|
||||
Path string
|
||||
ParentPath string
|
||||
GlobalVisibility types.Visibility
|
||||
|
@ -59,6 +61,11 @@ func projectGroupsResponse(readDB *readdb.ReadDB, projectGroups []*types.Project
|
|||
return err
|
||||
}
|
||||
|
||||
ownerType, ownerID, err := readDB.GetProjectGroupOwnerID(tx, projectGroup)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// calculate global visibility
|
||||
visibility, err := getGlobalVisibility(readDB, tx, projectGroup.Visibility, &projectGroup.Parent)
|
||||
if err != nil {
|
||||
|
@ -69,6 +76,8 @@ func projectGroupsResponse(readDB *readdb.ReadDB, projectGroups []*types.Project
|
|||
// updated on create
|
||||
resProjectGroups[i] = &ProjectGroup{
|
||||
ProjectGroup: projectGroup,
|
||||
OwnerType: ownerType,
|
||||
OwnerID: ownerID,
|
||||
Path: path.Join(pp, projectGroup.Name),
|
||||
ParentPath: pp,
|
||||
GlobalVisibility: visibility,
|
||||
|
|
|
@ -66,7 +66,6 @@ func (r *ReadDB) GetProjectPath(tx *db.Tx, project *types.Project) (string, erro
|
|||
}
|
||||
if pgroup == nil {
|
||||
return "", errors.Errorf("parent group %q for project %q doesn't exist", project.Parent.ID, project.ID)
|
||||
|
||||
}
|
||||
p, err := r.GetProjectGroupPath(tx, pgroup)
|
||||
if err != nil {
|
||||
|
@ -78,6 +77,17 @@ func (r *ReadDB) GetProjectPath(tx *db.Tx, project *types.Project) (string, erro
|
|||
return p, nil
|
||||
}
|
||||
|
||||
func (r *ReadDB) GetProjectOwnerID(tx *db.Tx, project *types.Project) (types.ConfigType, string, error) {
|
||||
pgroup, err := r.GetProjectGroup(tx, project.Parent.ID)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
if pgroup == nil {
|
||||
return "", "", errors.Errorf("parent group %q for project %q doesn't exist", project.Parent.ID, project.ID)
|
||||
}
|
||||
return r.GetProjectGroupOwnerID(tx, pgroup)
|
||||
}
|
||||
|
||||
func (r *ReadDB) GetProject(tx *db.Tx, projectRef string) (*types.Project, error) {
|
||||
projectRefType, err := common.ParsePathRef(projectRef)
|
||||
if err != nil {
|
||||
|
|
|
@ -134,6 +134,17 @@ func (r *ReadDB) GetProjectGroupPath(tx *db.Tx, group *types.ProjectGroup) (stri
|
|||
return p, nil
|
||||
}
|
||||
|
||||
func (r *ReadDB) GetProjectGroupOwnerID(tx *db.Tx, group *types.ProjectGroup) (types.ConfigType, string, error) {
|
||||
groups, err := r.GetProjectGroupHierarchy(tx, group)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
rootGroupType := groups[0].ParentType
|
||||
rootGroupID := groups[0].ParentID
|
||||
return rootGroupType, rootGroupID, nil
|
||||
}
|
||||
|
||||
func (r *ReadDB) GetProjectGroup(tx *db.Tx, projectGroupRef string) (*types.ProjectGroup, error) {
|
||||
groupRef, err := common.ParsePathRef(projectGroupRef)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue