configstore: resolve also org and user paths
This commit is contained in:
parent
2215aaebfa
commit
c7585a6152
@ -116,23 +116,15 @@ func (r *ReadDB) GetProjectGroupPath(tx *db.Tx, group *types.ProjectGroup) (stri
|
|||||||
rootGroupID := groups[0].ParentID
|
rootGroupID := groups[0].ParentID
|
||||||
switch rootGroupType {
|
switch rootGroupType {
|
||||||
case types.ConfigTypeOrg:
|
case types.ConfigTypeOrg:
|
||||||
org, err := r.GetOrg(tx, rootGroupID)
|
fallthrough
|
||||||
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)
|
|
||||||
case types.ConfigTypeUser:
|
case types.ConfigTypeUser:
|
||||||
user, err := r.GetUser(tx, rootGroupID)
|
var err error
|
||||||
|
p, err = r.GetPath(tx, rootGroupType, rootGroupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.Wrapf(err, "failed to get user %q", rootGroupID)
|
return "", err
|
||||||
}
|
}
|
||||||
if user == nil {
|
default:
|
||||||
return "", errors.Errorf("cannot find user with id %q", rootGroupID)
|
return "", errors.Errorf("invalid root group type %q", rootGroupType)
|
||||||
}
|
|
||||||
p = path.Join("user", user.Name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, group := range groups {
|
for _, group := range groups {
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
package readdb
|
package readdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sorintlab/agola/internal/db"
|
"github.com/sorintlab/agola/internal/db"
|
||||||
"github.com/sorintlab/agola/internal/services/types"
|
"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 {
|
if err != nil {
|
||||||
return "", err
|
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:
|
default:
|
||||||
return "", errors.Errorf("config type %q doesn't provide a path", configType)
|
return "", errors.Errorf("config type %q doesn't provide a path", configType)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user