-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
475 additions
and
450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Copyright 2018-2023 CERN | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// In applying this license, CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
package memory | ||
|
||
import ( | ||
"context" | ||
"slices" | ||
|
||
"github.com/cs3org/reva/pkg/projects" | ||
"github.com/cs3org/reva/pkg/projects/manager/registry" | ||
"github.com/cs3org/reva/pkg/spaces" | ||
"github.com/cs3org/reva/pkg/utils/cfg" | ||
|
||
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" | ||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" | ||
conversions "github.com/cs3org/reva/internal/http/services/owncloud/ocs/conversions" | ||
) | ||
|
||
func init() { | ||
registry.Register("memory", New) | ||
} | ||
|
||
type SpaceDescription struct { | ||
StorageID string `mapstructure:"storage_id" validate:"required"` | ||
Path string `mapstructure:"path" validate:"required"` | ||
Name string `mapstructure:"name" validate:"required"` | ||
Type string `mapstructure:"type" validate:"required"` | ||
Owner string `mapstructure:"owner" validate:"required"` | ||
Readers string `mapstructure:"readers" validate:"required"` | ||
Writers string `mapstructure:"writers" validate:"required"` | ||
Admins string `mapstructure:"admins" validate:"required"` | ||
} | ||
|
||
type Config struct { | ||
Spaces []SpaceDescription `mapstructure:"spaces"` | ||
} | ||
|
||
type service struct { | ||
c *Config | ||
} | ||
|
||
func New(ctx context.Context, m map[string]any) (projects.Catalogue, error) { | ||
var c Config | ||
if err := cfg.Decode(m, &c); err != nil { | ||
return nil, err | ||
} | ||
return NewWithConfig(ctx, &c) | ||
} | ||
|
||
func NewWithConfig(ctx context.Context, c *Config) (projects.Catalogue, error) { | ||
return &service{c: c}, nil | ||
} | ||
|
||
func (s *service) StoreProject(ctx context.Context, owner *userpb.UserId, path, name string, quota *provider.Quota) error { | ||
panic("not yet implemented") | ||
} | ||
|
||
func (s *service) ListProjects(ctx context.Context, user *userpb.User) ([]*provider.StorageSpace, error) { | ||
projects := []*provider.StorageSpace{} | ||
for _, space := range s.c.Spaces { | ||
if perms, ok := projectBelongToUser(user, &space); ok { | ||
projects = append(projects, &provider.StorageSpace{ | ||
Id: &provider.StorageSpaceId{ | ||
OpaqueId: spaces.EncodeSpaceID(space.StorageID, space.Path), | ||
}, | ||
Owner: &userpb.User{ | ||
Id: &userpb.UserId{ | ||
OpaqueId: space.Owner, | ||
}, | ||
}, | ||
Name: space.Name, | ||
SpaceType: spaces.SpaceTypeProject.AsString(), | ||
RootInfo: &provider.ResourceInfo{ | ||
Path: space.Path, | ||
PermissionSet: perms, | ||
}, | ||
}) | ||
} | ||
} | ||
return projects, nil | ||
} | ||
|
||
func projectBelongToUser(user *userpb.User, project *SpaceDescription) (*provider.ResourcePermissions, bool) { | ||
if user.Id.OpaqueId == project.Owner { | ||
return conversions.NewManagerRole().CS3ResourcePermissions(), true | ||
} | ||
if slices.Contains(user.Groups, project.Admins) { | ||
return conversions.NewManagerRole().CS3ResourcePermissions(), true | ||
} | ||
if slices.Contains(user.Groups, project.Writers) { | ||
return conversions.NewEditorRole().CS3ResourcePermissions(), true | ||
} | ||
if slices.Contains(user.Groups, project.Readers) { | ||
return conversions.NewViewerRole().CS3ResourcePermissions(), true | ||
} | ||
return nil, false | ||
} | ||
|
||
var _ projects.Catalogue = (*service)(nil) |
Oops, something went wrong.