diff --git a/internal/services/configstore/readdb/projectgroup.go b/internal/services/configstore/readdb/projectgroup.go index 1bbcf34..c52b8b9 100644 --- a/internal/services/configstore/readdb/projectgroup.go +++ b/internal/services/configstore/readdb/projectgroup.go @@ -116,23 +116,15 @@ func (r *ReadDB) GetProjectGroupPath(tx *db.Tx, group *types.ProjectGroup) (stri rootGroupID := groups[0].ParentID switch rootGroupType { case types.ConfigTypeOrg: - org, err := r.GetOrg(tx, rootGroupID) - if err != nil { - return "", errors.Wrapf(err, "failed to get org %q", rootGroupID) - } - if org == nil { - return "", errors.Errorf("cannot find org with id %q", rootGroupID) - } - p = path.Join("org", org.Name) + fallthrough case types.ConfigTypeUser: - user, err := r.GetUser(tx, rootGroupID) + var err error + p, err = r.GetPath(tx, rootGroupType, rootGroupID) if err != nil { - return "", errors.Wrapf(err, "failed to get user %q", rootGroupID) + return "", err } - if user == nil { - return "", errors.Errorf("cannot find user with id %q", rootGroupID) - } - p = path.Join("user", user.Name) + default: + return "", errors.Errorf("invalid root group type %q", rootGroupType) } for _, group := range groups { diff --git a/internal/services/configstore/readdb/resolve.go b/internal/services/configstore/readdb/resolve.go index b9feaa0..df92530 100644 --- a/internal/services/configstore/readdb/resolve.go +++ b/internal/services/configstore/readdb/resolve.go @@ -15,6 +15,8 @@ package readdb import ( + "path" + "github.com/pkg/errors" "github.com/sorintlab/agola/internal/db" "github.com/sorintlab/agola/internal/services/types" @@ -75,6 +77,24 @@ func (r *ReadDB) GetPath(tx *db.Tx, configType types.ConfigType, id string) (str if err != nil { return "", err } + case types.ConfigTypeOrg: + org, err := r.GetOrg(tx, id) + if err != nil { + return "", errors.Wrapf(err, "failed to get org %q", id) + } + if org == nil { + return "", errors.Errorf("cannot find org with id %q", id) + } + p = path.Join("org", org.Name) + case types.ConfigTypeUser: + user, err := r.GetUser(tx, id) + if err != nil { + return "", errors.Wrapf(err, "failed to get user %q", id) + } + if user == nil { + return "", errors.Errorf("cannot find user with id %q", id) + } + p = path.Join("user", user.Name) default: return "", errors.Errorf("config type %q doesn't provide a path", configType) }