Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add secure view share role #4643

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/secure-view-share-role.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Secure viewer share role

A new share role "Secure viewer" has been added. This role only allows viewing resources, no downloading, editing or deleting.

https://github.com/cs3org/reva/pull/4643
16 changes: 16 additions & 0 deletions pkg/conversions/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ const (
RoleUploader = "uploader"
// RoleManager grants manager permissions on a resource. Semantically equivalent to co-owner.
RoleManager = "manager"
// RoleSecureViewer grants secure view permissions on a resource or space.
RoleSecureViewer = "secure-viewer"

// RoleUnknown is used for unknown roles.
RoleUnknown = "unknown"
Expand Down Expand Up @@ -159,6 +161,8 @@ func RoleFromName(name string) *Role {
return NewUploaderRole()
case RoleManager:
return NewManagerRole()
case RoleSecureViewer:
return NewSecureViewerRole()
default:
return NewUnknownRole()
}
Expand Down Expand Up @@ -363,6 +367,18 @@ func NewManagerRole() *Role {
}
}

// NewSecureViewerRole creates a secure viewer role
func NewSecureViewerRole() *Role {
return &Role{
Name: RoleSecureViewer,
cS3ResourcePermissions: &provider.ResourcePermissions{
micbar marked this conversation as resolved.
Show resolved Hide resolved
GetPath: true,
ListContainer: true,
Stat: true,
},
}
}

// RoleFromOCSPermissions tries to map ocs permissions to a role
// TODO: rethink using this. ocs permissions cannot be assigned 1:1 to roles
func RoleFromOCSPermissions(p Permissions, ri *provider.ResourceInfo) *Role {
Expand Down
15 changes: 15 additions & 0 deletions pkg/conversions/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ func TestSufficientPermissions(t *testing.T) {
Requested: RoleFromName("denied").CS3ResourcePermissions(),
Sufficient: false,
},
{
Existing: RoleFromName("secure-viewer").CS3ResourcePermissions(),
Requested: RoleFromName("secure-viewer").CS3ResourcePermissions(),
Sufficient: true,
},
{
Existing: RoleFromName("secure-viewer").CS3ResourcePermissions(),
Requested: RoleFromName("viewer").CS3ResourcePermissions(),
Sufficient: false,
},
{
Existing: RoleFromName("secure-viewer").CS3ResourcePermissions(),
Requested: RoleFromName("editor").CS3ResourcePermissions(),
Sufficient: false,
},
{
Existing: &providerv1beta1.ResourcePermissions{
// all permissions, used for personal space owners
Expand Down
Loading