configstore: report project/projectgroup owners

Return project and projectgroup owner type (user or org) and their id.
This commit is contained in:
Simone Gotti 2019-05-03 23:17:07 +02:00
parent 81d656b7a3
commit af67198dec
4 changed files with 40 additions and 1 deletions

View File

@ -36,6 +36,8 @@ type Project struct {
*types.Project *types.Project
// dynamic data // dynamic data
OwnerType types.ConfigType
OwnerID string
Path string Path string
ParentPath string ParentPath string
GlobalVisibility types.Visibility GlobalVisibility types.Visibility
@ -59,6 +61,11 @@ func projectsResponse(readDB *readdb.ReadDB, projects []*types.Project) ([]*Proj
return err return err
} }
ownerType, ownerID, err := readDB.GetProjectOwnerID(tx, project)
if err != nil {
return err
}
// calculate global visibility // calculate global visibility
visibility, err := getGlobalVisibility(readDB, tx, project.Visibility, &project.Parent) visibility, err := getGlobalVisibility(readDB, tx, project.Visibility, &project.Parent)
if err != nil { if err != nil {
@ -69,6 +76,8 @@ func projectsResponse(readDB *readdb.ReadDB, projects []*types.Project) ([]*Proj
// updated on create // updated on create
resProjects[i] = &Project{ resProjects[i] = &Project{
Project: project, Project: project,
OwnerType: ownerType,
OwnerID: ownerID,
Path: path.Join(pp, project.Name), Path: path.Join(pp, project.Name),
ParentPath: pp, ParentPath: pp,
GlobalVisibility: visibility, GlobalVisibility: visibility,

View File

@ -36,6 +36,8 @@ type ProjectGroup struct {
*types.ProjectGroup *types.ProjectGroup
// dynamic data // dynamic data
OwnerType types.ConfigType
OwnerID string
Path string Path string
ParentPath string ParentPath string
GlobalVisibility types.Visibility GlobalVisibility types.Visibility
@ -59,6 +61,11 @@ func projectGroupsResponse(readDB *readdb.ReadDB, projectGroups []*types.Project
return err return err
} }
ownerType, ownerID, err := readDB.GetProjectGroupOwnerID(tx, projectGroup)
if err != nil {
return err
}
// calculate global visibility // calculate global visibility
visibility, err := getGlobalVisibility(readDB, tx, projectGroup.Visibility, &projectGroup.Parent) visibility, err := getGlobalVisibility(readDB, tx, projectGroup.Visibility, &projectGroup.Parent)
if err != nil { if err != nil {
@ -69,6 +76,8 @@ func projectGroupsResponse(readDB *readdb.ReadDB, projectGroups []*types.Project
// updated on create // updated on create
resProjectGroups[i] = &ProjectGroup{ resProjectGroups[i] = &ProjectGroup{
ProjectGroup: projectGroup, ProjectGroup: projectGroup,
OwnerType: ownerType,
OwnerID: ownerID,
Path: path.Join(pp, projectGroup.Name), Path: path.Join(pp, projectGroup.Name),
ParentPath: pp, ParentPath: pp,
GlobalVisibility: visibility, GlobalVisibility: visibility,

View File

@ -66,7 +66,6 @@ func (r *ReadDB) GetProjectPath(tx *db.Tx, project *types.Project) (string, erro
} }
if pgroup == nil { if pgroup == nil {
return "", errors.Errorf("parent group %q for project %q doesn't exist", project.Parent.ID, project.ID) return "", errors.Errorf("parent group %q for project %q doesn't exist", project.Parent.ID, project.ID)
} }
p, err := r.GetProjectGroupPath(tx, pgroup) p, err := r.GetProjectGroupPath(tx, pgroup)
if err != nil { if err != nil {
@ -78,6 +77,17 @@ func (r *ReadDB) GetProjectPath(tx *db.Tx, project *types.Project) (string, erro
return p, nil 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) { func (r *ReadDB) GetProject(tx *db.Tx, projectRef string) (*types.Project, error) {
projectRefType, err := common.ParsePathRef(projectRef) projectRefType, err := common.ParsePathRef(projectRef)
if err != nil { if err != nil {

View File

@ -134,6 +134,17 @@ func (r *ReadDB) GetProjectGroupPath(tx *db.Tx, group *types.ProjectGroup) (stri
return p, nil 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) { func (r *ReadDB) GetProjectGroup(tx *db.Tx, projectGroupRef string) (*types.ProjectGroup, error) {
groupRef, err := common.ParsePathRef(projectGroupRef) groupRef, err := common.ParsePathRef(projectGroupRef)
if err != nil { if err != nil {