diff --git a/internal/services/configstore/api/project.go b/internal/services/configstore/api/project.go index 1f8b66c..31b6749 100644 --- a/internal/services/configstore/api/project.go +++ b/internal/services/configstore/api/project.go @@ -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, diff --git a/internal/services/configstore/api/projectgroup.go b/internal/services/configstore/api/projectgroup.go index a6a45e5..4bfdb63 100644 --- a/internal/services/configstore/api/projectgroup.go +++ b/internal/services/configstore/api/projectgroup.go @@ -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, diff --git a/internal/services/configstore/readdb/project.go b/internal/services/configstore/readdb/project.go index 44dcd03..4d20620 100644 --- a/internal/services/configstore/readdb/project.go +++ b/internal/services/configstore/readdb/project.go @@ -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 { diff --git a/internal/services/configstore/readdb/projectgroup.go b/internal/services/configstore/readdb/projectgroup.go index ab9af82..f1406e8 100644 --- a/internal/services/configstore/readdb/projectgroup.go +++ b/internal/services/configstore/readdb/projectgroup.go @@ -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 {