Skip to content

Commit c85b55b

Browse files
committed
Check if user belongs to admin group for the specific project
1 parent 502c09c commit c85b55b

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

pkg/cbox/storage/eoswrapper/eoswrapper.go

+16-8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/Masterminds/sprig"
2828
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
2929
ctxpkg "github.com/cs3org/reva/pkg/ctx"
30+
"github.com/cs3org/reva/pkg/errtypes"
3031
"github.com/cs3org/reva/pkg/storage"
3132
"github.com/cs3org/reva/pkg/storage/fs/registry"
3233
"github.com/cs3org/reva/pkg/storage/utils/eosfs"
@@ -39,16 +40,15 @@ func init() {
3940
}
4041

4142
const (
42-
eosProjectsNamespace = "/eos/project"
43+
eosProjectsNamespace = "/eos/project/"
4344

4445
// We can use a regex for these, but that might have inferior performance
45-
projectSpaceGroupsPrefix = "cernbox-project-"
46-
projectSpaceAdminGroups = "-admins"
46+
projectSpaceGroupsPrefix = "cernbox-project-"
47+
projectSpaceAdminGroupsSuffix = "-admins"
4748
)
4849

4950
type wrapper struct {
5051
storage.FS
51-
config *eosfs.Config
5252
mountIDTemplate *template.Template
5353
}
5454

@@ -90,7 +90,7 @@ func New(m map[string]interface{}) (storage.FS, error) {
9090
return nil, err
9191
}
9292

93-
return &wrapper{FS: eos, config: c, mountIDTemplate: mountIDTemplate}, nil
93+
return &wrapper{FS: eos, mountIDTemplate: mountIDTemplate}, nil
9494
}
9595

9696
// We need to override the two methods, GetMD and ListFolder to fill the
@@ -142,13 +142,21 @@ func (w *wrapper) getMountID(ctx context.Context, r *provider.ResourceInfo) stri
142142
}
143143

144144
func (w *wrapper) setProjectSharingPermissions(ctx context.Context, r *provider.ResourceInfo) error {
145-
if strings.HasPrefix(w.config.Namespace, eosProjectsNamespace) {
145+
if strings.HasPrefix(r.Path, eosProjectsNamespace) {
146+
147+
// Extract project name from the path resembling /eos/project/c/cernbox/minutes/..
148+
path := strings.TrimPrefix(r.Path, eosProjectsNamespace)
149+
parts := strings.SplitN(path, "/", 3)
150+
if len(parts) != 3 {
151+
return errtypes.BadRequest("eoswrapper: path does not follow the allowed format")
152+
}
153+
adminGroup := projectSpaceGroupsPrefix + parts[1] + projectSpaceAdminGroupsSuffix
154+
146155
var userHasSharingAccess bool
147156
user := ctxpkg.ContextMustGetUser(ctx)
148157

149158
for _, g := range user.Groups {
150-
// Check if user is present in the admins groups
151-
if strings.HasPrefix(g, projectSpaceGroupsPrefix) && strings.HasSuffix(g, projectSpaceAdminGroups) {
159+
if g == adminGroup {
152160
userHasSharingAccess = true
153161
break
154162
}

0 commit comments

Comments
 (0)