remove resharing

Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
jkoberg
2024-04-02 14:45:47 +02:00
parent b06767a020
commit b174b005e7
23 changed files with 128 additions and 182 deletions

View File

@@ -0,0 +1,5 @@
Enhancement: Remove resharing
Removed resharing feature from codebase
https://github.com/owncloud/ocis/pull/8762

View File

@@ -31,7 +31,6 @@ type Config struct {
UploadMaxChunkSize int `yaml:"upload_max_chunk_size" env:"FRONTEND_UPLOAD_MAX_CHUNK_SIZE" desc:"Sets the max chunk sizes in bytes for uploads via the clients." introductionVersion:"pre5.0"`
UploadHTTPMethodOverride string `yaml:"upload_http_method_override" env:"FRONTEND_UPLOAD_HTTP_METHOD_OVERRIDE" desc:"Advise TUS to replace PATCH requests by POST requests." introductionVersion:"pre5.0"`
DefaultUploadProtocol string `yaml:"default_upload_protocol" env:"FRONTEND_DEFAULT_UPLOAD_PROTOCOL" desc:"The default upload protocol to use in clients. Currently only 'tus' is available. See the developer API documentation for more details about TUS." introductionVersion:"pre5.0"`
EnableResharing bool `yaml:"enable_resharing" env:"OCIS_ENABLE_RESHARING;FRONTEND_ENABLE_RESHARING" desc:"Changing this value is NOT supported. Enables the support for re-sharing in the clients." introductionVersion:"pre5.0" deprecationVersion:"5.0" deprecationInfo:"Re-sharing will be removed in the future."`
EnableFederatedSharingIncoming bool `yaml:"enable_federated_sharing_incoming" env:"FRONTEND_ENABLE_FEDERATED_SHARING_INCOMING" desc:"Changing this value is NOT supported. Enables support for incoming federated sharing for clients. The backend behaviour is not changed." introductionVersion:"pre5.0"`
EnableFederatedSharingOutgoing bool `yaml:"enable_federated_sharing_outgoing" env:"FRONTEND_ENABLE_FEDERATED_SHARING_OUTGOING" desc:"Changing this value is NOT supported. Enables support for outgoing federated sharing for clients. The backend behaviour is not changed." introductionVersion:"pre5.0"`
SearchMinLength int `yaml:"search_min_length" env:"FRONTEND_SEARCH_MIN_LENGTH" desc:"Minimum number of characters to enter before a client should start a search for Share receivers. This setting can be used to customize the user experience if e.g too many results are displayed." introductionVersion:"pre5.0"`

View File

@@ -85,7 +85,6 @@ func DefaultConfig() *config.Config {
UploadMaxChunkSize: 1e+7,
UploadHTTPMethodOverride: "",
DefaultUploadProtocol: "tus",
EnableResharing: false,
DefaultLinkPermissions: 1,
SearchMinLength: 3,
Edition: "Community",

View File

@@ -229,7 +229,6 @@ func FrontendConfigFromStruct(cfg *config.Config, logger log.Logger) (map[string
},
"files_sharing": map[string]interface{}{
"api_enabled": true,
"resharing": cfg.EnableResharing,
"group_sharing": true,
"sharing_roles": true,
"deny_access": cfg.OCS.EnableDenials,

View File

@@ -33,8 +33,6 @@ type Config struct {
Keycloak Keycloak `yaml:"keycloak"`
ServiceAccount ServiceAccount `yaml:"service_account"`
FilesSharing FilesSharing `yaml:"files_sharing"`
Context context.Context `yaml:"-"`
}
@@ -151,8 +149,3 @@ type ServiceAccount struct {
ServiceAccountID string `yaml:"service_account_id" env:"OCIS_SERVICE_ACCOUNT_ID;GRAPH_SERVICE_ACCOUNT_ID" desc:"The ID of the service account the service should use. See the 'auth-service' service description for more details." introductionVersion:"5.0"`
ServiceAccountSecret string `yaml:"service_account_secret" env:"OCIS_SERVICE_ACCOUNT_SECRET;GRAPH_SERVICE_ACCOUNT_SECRET" desc:"The service account secret." introductionVersion:"5.0"`
}
// FilesSharing is the configuration for the files sharing
type FilesSharing struct {
EnableResharing bool `yaml:"enable_resharing" env:"OCIS_ENABLE_RESHARING;GRAPH_ENABLE_RESHARING" desc:"Changing this value is NOT supported. Enables the support for re-sharing." introductionVersion:"5.0" deprecationVersion:"5.0" deprecationInfo:"Resharing will be removed in the future."`
}

View File

@@ -107,9 +107,6 @@ func DefaultConfig() *config.Config {
Cluster: "ocis-cluster",
EnableTLS: false,
},
FilesSharing: config.FilesSharing{
EnableResharing: false,
},
}
}

View File

@@ -96,7 +96,7 @@ func (s DriveItemPermissionsService) Invite(ctx context.Context, resourceId stor
unifiedRolePermissions := []*libregraph.UnifiedRolePermission{{AllowedResourceActions: invite.LibreGraphPermissionsActions}}
for _, roleID := range invite.GetRoles() {
role, err := unifiedrole.NewUnifiedRoleFromID(roleID, s.config.FilesSharing.EnableResharing)
role, err := unifiedrole.NewUnifiedRoleFromID(roleID)
if err != nil {
s.logger.Debug().Err(err).Interface("role", invite.GetRoles()[0]).Msg("unable to convert requested role")
return libregraph.Permission{}, err
@@ -125,7 +125,7 @@ func (s DriveItemPermissionsService) Invite(ctx context.Context, resourceId stor
}
permission := &libregraph.Permission{}
if role := unifiedrole.CS3ResourcePermissionsToUnifiedRole(*cs3ResourcePermissions, condition, s.config.FilesSharing.EnableResharing); role != nil {
if role := unifiedrole.CS3ResourcePermissionsToUnifiedRole(*cs3ResourcePermissions, condition); role != nil {
permission.Roles = []string{role.GetId()}
}
@@ -246,7 +246,6 @@ func (s DriveItemPermissionsService) ListPermissions(ctx context.Context, itemID
unifiedrole.GetApplicableRoleDefinitionsForActions(
allowedActions,
condition,
s.config.FilesSharing.EnableResharing,
false,
),
),

View File

@@ -164,13 +164,13 @@ var _ = Describe("DriveItemPermissionsService", func() {
driveItemInvite.Recipients = []libregraph.DriveRecipient{
{ObjectId: libregraph.PtrString("1"), LibreGraphRecipientType: libregraph.PtrString("user")},
}
driveItemInvite.Roles = []string{unifiedrole.NewViewerUnifiedRole(true).GetId()}
driveItemInvite.Roles = []string{unifiedrole.NewViewerUnifiedRole().GetId()}
permission, err := driveItemPermissionsService.Invite(context.Background(), driveItemId, driveItemInvite)
Expect(err).ToNot(HaveOccurred())
Expect(permission.GetRoles()).To(HaveLen(1))
Expect(permission.GetRoles()[0]).To(Equal(unifiedrole.NewViewerUnifiedRole(true).GetId()))
Expect(permission.GetRoles()[0]).To(Equal(unifiedrole.NewViewerUnifiedRole().GetId()))
})
It("fails with wrong role", func() {
@@ -311,7 +311,7 @@ var _ = Describe("DriveItemPermissionsService", func() {
It("populates allowedValues for files that are not shared", func() {
statResponse.Info = &provider.ResourceInfo{
Id: &itemID,
PermissionSet: roleconversions.NewViewerRole(false).CS3ResourcePermissions(),
PermissionSet: roleconversions.NewViewerRole().CS3ResourcePermissions(),
}
gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(statResponse, nil)
gatewayClient.On("ListShares", mock.Anything, mock.Anything).Return(listSharesResponse, nil)
@@ -324,13 +324,13 @@ var _ = Describe("DriveItemPermissionsService", func() {
It("returns one permission per share", func() {
statResponse.Info = &provider.ResourceInfo{
Id: &itemID,
PermissionSet: roleconversions.NewEditorRole(false).CS3ResourcePermissions(),
PermissionSet: roleconversions.NewEditorRole().CS3ResourcePermissions(),
}
listSharesResponse.Shares = []*collaboration.Share{
{
Id: &collaboration.ShareId{OpaqueId: "1"},
Permissions: &collaboration.SharePermissions{
Permissions: roleconversions.NewViewerRole(false).CS3ResourcePermissions(),
Permissions: roleconversions.NewViewerRole().CS3ResourcePermissions(),
},
ResourceId: &provider.ResourceId{
StorageId: "1",
@@ -358,7 +358,7 @@ var _ = Describe("DriveItemPermissionsService", func() {
SpaceId: "spaceid",
OpaqueId: "public-share-opaqueid",
},
Permissions: &link.PublicSharePermissions{Permissions: roleconversions.NewViewerRole(false).CS3ResourcePermissions()},
Permissions: &link.PublicSharePermissions{Permissions: roleconversions.NewViewerRole().CS3ResourcePermissions()},
},
}
@@ -408,7 +408,7 @@ var _ = Describe("DriveItemPermissionsService", func() {
gatewayClient.On("ListPublicShares", mock.Anything, mock.Anything).Return(listPublicSharesResponse, nil)
statResponse.Info = &provider.ResourceInfo{
Id: listSpacesResponse.StorageSpaces[0].Root,
PermissionSet: roleconversions.NewViewerRole(false).CS3ResourcePermissions(),
PermissionSet: roleconversions.NewViewerRole().CS3ResourcePermissions(),
}
gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(statResponse, nil)
permissions, err := driveItemPermissionsService.ListSpaceRootPermissions(context.Background(), driveId)
@@ -586,7 +586,7 @@ var _ = Describe("DriveItemPermissionsService", func() {
},
},
Permissions: &collaboration.SharePermissions{
Permissions: roleconversions.NewViewerRole(true).CS3ResourcePermissions(),
Permissions: roleconversions.NewViewerRole().CS3ResourcePermissions(),
},
}
getShareMockResponse = &collaboration.GetShareResponse{
@@ -798,7 +798,7 @@ var _ = Describe("DriveItemPermissionsService", func() {
gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(statResponse, nil)
gatewayClient.On("GetUser", mock.Anything, mock.Anything).Return(getUserResponse, nil)
driveItemPermission.SetRoles([]string{unifiedrole.NewFileEditorUnifiedRole(false).GetId()})
driveItemPermission.SetRoles([]string{unifiedrole.NewFileEditorUnifiedRole().GetId()})
spaceId := provider.ResourceId{
StorageId: "1",
SpaceId: "2",
@@ -980,7 +980,7 @@ var _ = Describe("DriveItemPermissionsApi", func() {
ObjectId: libregraph.PtrString("1"),
LibreGraphRecipientType: libregraph.PtrString("user")},
},
Roles: []string{unifiedrole.NewViewerUnifiedRole(true).GetId()},
Roles: []string{unifiedrole.NewViewerUnifiedRole().GetId()},
}
})

View File

@@ -34,19 +34,17 @@ type DrivesDriveItemProvider interface {
// DrivesDriveItemService contains the production business logic for everything that relates to drives
type DrivesDriveItemService struct {
logger log.Logger
gatewaySelector pool.Selectable[gateway.GatewayAPIClient]
identityCache identity.IdentityCache
resharingEnabled bool
logger log.Logger
gatewaySelector pool.Selectable[gateway.GatewayAPIClient]
identityCache identity.IdentityCache
}
// NewDrivesDriveItemService creates a new DrivesDriveItemService
func NewDrivesDriveItemService(logger log.Logger, gatewaySelector pool.Selectable[gateway.GatewayAPIClient], identityCache identity.IdentityCache, resharing bool) (DrivesDriveItemService, error) {
func NewDrivesDriveItemService(logger log.Logger, gatewaySelector pool.Selectable[gateway.GatewayAPIClient], identityCache identity.IdentityCache) (DrivesDriveItemService, error) {
return DrivesDriveItemService{
logger: log.Logger{Logger: logger.With().Str("graph api", "DrivesDriveItemService").Logger()},
gatewaySelector: gatewaySelector,
identityCache: identityCache,
resharingEnabled: resharing,
logger: log.Logger{Logger: logger.With().Str("graph api", "DrivesDriveItemService").Logger()},
gatewaySelector: gatewaySelector,
identityCache: identityCache,
}, nil
}
@@ -211,8 +209,8 @@ func (s DrivesDriveItemService) MountShare(ctx context.Context, resourceID stora
return libregraph.DriveItem{}, errors.Join(errs...)
}
// As the accepted shares are all for the same resource they should collapse to a single drive-item
items, err := cs3ReceivedSharesToDriveItems(ctx, &s.logger, gatewayClient, s.identityCache, s.resharingEnabled, acceptedShares)
// As the accepted shares are all for the same resource they should collapse to a single driveitem
items, err := cs3ReceivedSharesToDriveItems(ctx, &s.logger, gatewayClient, s.identityCache, acceptedShares)
switch {
case err != nil:
return libregraph.DriveItem{}, nil

View File

@@ -47,7 +47,7 @@ var _ = Describe("DrivesDriveItemService", func() {
cache := identity.NewIdentityCache(identity.IdentityCacheWithGatewaySelector(gatewaySelector))
service, err := svc.NewDrivesDriveItemService(logger, gatewaySelector, cache, false)
service, err := svc.NewDrivesDriveItemService(logger, gatewaySelector, cache)
Expect(err).ToNot(HaveOccurred())
drivesDriveItemService = service
})

View File

@@ -165,7 +165,7 @@ func (g BaseGraphService) cs3SpacePermissionsToLibreGraph(ctx context.Context, s
p.SetExpirationDateTime(time.Unix(int64(exp.GetSeconds()), int64(exp.GetNanos())))
}
if role := unifiedrole.CS3ResourcePermissionsToUnifiedRole(*perm, unifiedrole.UnifiedRoleConditionOwner, false); role != nil {
if role := unifiedrole.CS3ResourcePermissionsToUnifiedRole(*perm, unifiedrole.UnifiedRoleConditionOwner); role != nil {
switch apiVersion {
case APIVersion_1:
if r := unifiedrole.GetLegacyName(*role); r != "" {
@@ -354,7 +354,6 @@ func (g BaseGraphService) cs3UserShareToPermission(ctx context.Context, share *c
role := unifiedrole.CS3ResourcePermissionsToUnifiedRole(
*share.GetPermissions().GetPermissions(),
condition,
g.config.FilesSharing.EnableResharing,
)
if role != nil {
perm.SetRoles([]string{role.GetId()})
@@ -627,7 +626,7 @@ func (g BaseGraphService) updateUserShare(ctx context.Context, permissionID stri
var permissionsUpdated, ok bool
if roles, ok = newPermission.GetRolesOk(); ok && len(roles) > 0 {
for _, roleID := range roles {
role, err := unifiedrole.NewUnifiedRoleFromID(roleID, g.config.FilesSharing.EnableResharing)
role, err := unifiedrole.NewUnifiedRoleFromID(roleID)
if err != nil {
g.logger.Debug().Err(err).Interface("role", role).Msg("unable to convert requested role")
return nil, err

View File

@@ -15,7 +15,7 @@ import (
// GetRoleDefinitions a list of permission roles than can be used when sharing with users or groups
func (g Graph) GetRoleDefinitions(w http.ResponseWriter, r *http.Request) {
render.Status(r, http.StatusOK)
render.JSON(w, r, unifiedrole.GetBuiltinRoleDefinitionList(g.config.FilesSharing.EnableResharing))
render.JSON(w, r, unifiedrole.GetBuiltinRoleDefinitionList())
}
// GetRoleDefinition a permission role than can be used when sharing with users or groups
@@ -27,7 +27,7 @@ func (g Graph) GetRoleDefinition(w http.ResponseWriter, r *http.Request) {
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "unescaping role id failed")
return
}
role, err := getRoleDefinition(roleID, g.config.FilesSharing.EnableResharing)
role, err := getRoleDefinition(roleID)
if err != nil {
logger.Debug().Str("roleID", roleID).Msg("could not get role: not found")
errorcode.ItemNotFound.Render(w, r, http.StatusNotFound, err.Error())
@@ -37,8 +37,8 @@ func (g Graph) GetRoleDefinition(w http.ResponseWriter, r *http.Request) {
render.JSON(w, r, role)
}
func getRoleDefinition(roleID string, resharing bool) (*libregraph.UnifiedRoleDefinition, error) {
roleList := unifiedrole.GetBuiltinRoleDefinitionList(resharing)
func getRoleDefinition(roleID string) (*libregraph.UnifiedRoleDefinition, error) {
roleList := unifiedrole.GetBuiltinRoleDefinitionList()
for _, role := range roleList {
if role != nil && role.Id != nil && *role.Id == roleID {
return role, nil

View File

@@ -199,7 +199,7 @@ func NewService(opts ...Option) (Graph, error) {
requireAdmin = options.RequireAdminMiddleware
}
drivesDriveItemService, err := NewDrivesDriveItemService(options.Logger, options.GatewaySelector, identityCache, options.Config.FilesSharing.EnableResharing)
drivesDriveItemService, err := NewDrivesDriveItemService(options.Logger, options.GatewaySelector, identityCache)
if err != nil {
return svc, err
}

View File

@@ -52,7 +52,7 @@ var _ = Describe("sharedbyme", func() {
)
expiration := time.Now()
editorResourcePermissions := conversions.NewEditorRole(true).CS3ResourcePermissions()
editorResourcePermissions := conversions.NewEditorRole().CS3ResourcePermissions()
userShare := collaboration.Share{
Id: &collaboration.ShareId{
OpaqueId: "share-id",
@@ -243,7 +243,6 @@ var _ = Describe("sharedbyme", func() {
cfg.TokenManager.JWTSecret = "loremipsum"
cfg.Commons = &shared.Commons{}
cfg.GRPCClientTLS = &shared.GRPCClientTLS{}
cfg.FilesSharing.EnableResharing = true
svc, _ = service.NewService(
service.Config(cfg),

View File

@@ -39,5 +39,5 @@ func (g Graph) listSharedWithMe(ctx context.Context) ([]libregraph.DriveItem, er
return nil, *errCode
}
return cs3ReceivedSharesToDriveItems(ctx, g.logger, gatewayClient, g.identityCache, g.config.FilesSharing.EnableResharing, listReceivedSharesResponse.GetShares())
return cs3ReceivedSharesToDriveItems(ctx, g.logger, gatewayClient, g.identityCache, listReceivedSharesResponse.GetShares())
}

View File

@@ -155,7 +155,7 @@ var _ = Describe("SharedWithMe", func() {
OpaqueId: "sh:are:id",
},
Permissions: &collaborationv1beta1.SharePermissions{
Permissions: roleconversions.NewViewerRole(true).CS3ResourcePermissions(),
Permissions: roleconversions.NewViewerRole().CS3ResourcePermissions(),
},
Creator: getUserResponseShareCreator.User.Id,
Ctime: utils.TSNow(),
@@ -351,29 +351,6 @@ var _ = Describe("SharedWithMe", func() {
Expect(jsonData.Get("file.mimeType").String()).To(Equal(resourceInfo.MimeType))
})
// that is resharing test. Please delete after disable resharing feature
// It("populates the driveItem.remoteItem.permissions properties", func() {
// resourceInfo := statResponse.Info
// resourceInfo.PermissionSet = roleconversions.NewViewerRole(false).CS3ResourcePermissions()
// svc.ListSharedWithMe(
// tape,
// httptest.NewRequest(http.MethodGet, "/graph/v1beta1/me/drive/sharedWithMe", nil),
// )
// driveitemJSON := gjson.Get(tape.Body.String(), "value.0")
// Expect(driveitemJSON.Get("@UI\\.Hidden").Exists()).To(BeTrue())
// Expect(driveitemJSON.Get("@UI\\.Hidden").Bool()).To(BeFalse())
// Expect(driveitemJSON.Get("@client\\.synchronize").Exists()).To(BeTrue())
// Expect(driveitemJSON.Get("@client\\.synchronize").Bool()).To(BeTrue())
// permissionsJSON := driveitemJSON.Get("remoteItem.permissions.0")
// Expect(permissionsJSON.Get("id").String()).To(Equal(listReceivedSharesResponse.Shares[0].Share.Id.OpaqueId))
// Expect(permissionsJSON.Get("roles.0").String()).To(Equal(unifiedrole.UnifiedRoleViewerID))
// Expect(permissionsJSON.Get("invitation.invitedBy.user.id").String()).To(Equal(getUserResponseShareCreator.User.Id.OpaqueId))
// })
It("returns shares created on project space", func() {
ownerID := &userv1beta1.UserId{
OpaqueId: "project-space-id",
@@ -406,7 +383,7 @@ var _ = Describe("SharedWithMe", func() {
OpaqueId: "sh:are:id2",
},
Permissions: &collaborationv1beta1.SharePermissions{
Permissions: roleconversions.NewViewerRole(true).CS3ResourcePermissions(),
Permissions: roleconversions.NewViewerRole().CS3ResourcePermissions(),
},
Creator: getUserResponseShareCreator.User.Id,
Ctime: utils.TSNow(),

View File

@@ -142,7 +142,6 @@ func cs3ReceivedSharesToDriveItems(ctx context.Context,
logger *log.Logger,
gatewayClient gateway.GatewayAPIClient,
identityCache identity.IdentityCache,
resharing bool,
receivedShares []*collaboration.ReceivedShare) ([]libregraph.DriveItem, error) {
ch := make(chan libregraph.DriveItem)
@@ -178,8 +177,7 @@ func cs3ReceivedSharesToDriveItems(ctx context.Context,
return errCode
}
driveItem, err := fillDriveItemPropertiesFromReceivedShare(ctx, logger, identityCache,
resharing, receivedShares)
driveItem, err := fillDriveItemPropertiesFromReceivedShare(ctx, logger, identityCache, receivedShares)
if err != nil {
return err
}
@@ -315,8 +313,7 @@ func cs3ReceivedSharesToDriveItems(ctx context.Context,
}
func fillDriveItemPropertiesFromReceivedShare(ctx context.Context, logger *log.Logger,
identityCache identity.IdentityCache, resharing bool,
receivedShares []*collaboration.ReceivedShare) (*libregraph.DriveItem, error) {
identityCache identity.IdentityCache, receivedShares []*collaboration.ReceivedShare) (*libregraph.DriveItem, error) {
driveItem := libregraph.NewDriveItem()
permissions := make([]libregraph.Permission, 0, len(receivedShares))
@@ -330,7 +327,7 @@ func fillDriveItemPropertiesFromReceivedShare(ctx context.Context, logger *log.L
oldestReceivedShare = receivedShare
}
permission, err := cs3ReceivedShareToLibreGraphPermissions(ctx, logger, identityCache, resharing, receivedShare)
permission, err := cs3ReceivedShareToLibreGraphPermissions(ctx, logger, identityCache, receivedShare)
if err != nil {
return driveItem, err
}
@@ -390,7 +387,7 @@ func fillDriveItemPropertiesFromReceivedShare(ctx context.Context, logger *log.L
}
func cs3ReceivedShareToLibreGraphPermissions(ctx context.Context, logger *log.Logger,
identityCache identity.IdentityCache, resharing bool, receivedShare *collaboration.ReceivedShare) (*libregraph.Permission, error) {
identityCache identity.IdentityCache, receivedShare *collaboration.ReceivedShare) (*libregraph.Permission, error) {
permission := libregraph.NewPermission()
if id := receivedShare.GetShare().GetId().GetOpaqueId(); id != "" {
permission.SetId(id)
@@ -404,7 +401,6 @@ func cs3ReceivedShareToLibreGraphPermissions(ctx context.Context, logger *log.Lo
role := unifiedrole.CS3ResourcePermissionsToUnifiedRole(
*permissionSet,
unifiedrole.UnifiedRoleConditionGrantee,
resharing,
)
if role != nil {

View File

@@ -69,8 +69,8 @@ var legacyNames map[string]string = map[string]string{
}
// NewViewerUnifiedRole creates a viewer role. `sharing` indicates if sharing permission should be added
func NewViewerUnifiedRole(sharing bool) *libregraph.UnifiedRoleDefinition {
r := conversions.NewViewerRole(sharing)
func NewViewerUnifiedRole() *libregraph.UnifiedRoleDefinition {
r := conversions.NewViewerRole()
return &libregraph.UnifiedRoleDefinition{
Id: proto.String(UnifiedRoleViewerID),
Description: proto.String("View and download."),
@@ -103,8 +103,8 @@ func NewSpaceViewerUnifiedRole() *libregraph.UnifiedRoleDefinition {
}
// NewEditorUnifiedRole creates an editor role. `sharing` indicates if sharing permission should be added
func NewEditorUnifiedRole(sharing bool) *libregraph.UnifiedRoleDefinition {
r := conversions.NewEditorRole(sharing)
func NewEditorUnifiedRole() *libregraph.UnifiedRoleDefinition {
r := conversions.NewEditorRole()
return &libregraph.UnifiedRoleDefinition{
Id: proto.String(UnifiedRoleEditorID),
Description: proto.String("View, download, upload, edit, add and delete."),
@@ -137,8 +137,8 @@ func NewSpaceEditorUnifiedRole() *libregraph.UnifiedRoleDefinition {
}
// NewFileEditorUnifiedRole creates a file-editor role
func NewFileEditorUnifiedRole(sharing bool) *libregraph.UnifiedRoleDefinition {
r := conversions.NewFileEditorRole(sharing)
func NewFileEditorUnifiedRole() *libregraph.UnifiedRoleDefinition {
r := conversions.NewFileEditorRole()
return &libregraph.UnifiedRoleDefinition{
Id: proto.String(UnifiedRoleFileEditorID),
Description: proto.String("View, download and edit."),
@@ -188,8 +188,8 @@ func NewManagerUnifiedRole() *libregraph.UnifiedRoleDefinition {
}
// NewUnifiedRoleFromID returns a unified role definition from the provided id
func NewUnifiedRoleFromID(id string, resharing bool) (*libregraph.UnifiedRoleDefinition, error) {
for _, definition := range GetBuiltinRoleDefinitionList(resharing) {
func NewUnifiedRoleFromID(id string) (*libregraph.UnifiedRoleDefinition, error) {
for _, definition := range GetBuiltinRoleDefinitionList() {
if definition.GetId() != id {
continue
}
@@ -200,13 +200,13 @@ func NewUnifiedRoleFromID(id string, resharing bool) (*libregraph.UnifiedRoleDef
return nil, errors.New("role not found")
}
func GetBuiltinRoleDefinitionList(resharing bool) []*libregraph.UnifiedRoleDefinition {
func GetBuiltinRoleDefinitionList() []*libregraph.UnifiedRoleDefinition {
return []*libregraph.UnifiedRoleDefinition{
NewViewerUnifiedRole(resharing),
NewViewerUnifiedRole(),
NewSpaceViewerUnifiedRole(),
NewEditorUnifiedRole(resharing),
NewEditorUnifiedRole(),
NewSpaceEditorUnifiedRole(),
NewFileEditorUnifiedRole(resharing),
NewFileEditorUnifiedRole(),
NewUploaderUnifiedRole(),
NewManagerUnifiedRole(),
}
@@ -214,8 +214,8 @@ func GetBuiltinRoleDefinitionList(resharing bool) []*libregraph.UnifiedRoleDefin
// GetApplicableRoleDefinitionsForActions returns a list of role definitions
// that match the provided actions and constraints
func GetApplicableRoleDefinitionsForActions(actions []string, constraints string, resharing, descending bool) []*libregraph.UnifiedRoleDefinition {
builtin := GetBuiltinRoleDefinitionList(resharing)
func GetApplicableRoleDefinitionsForActions(actions []string, constraints string, descending bool) []*libregraph.UnifiedRoleDefinition {
builtin := GetBuiltinRoleDefinitionList()
definitions := make([]*libregraph.UnifiedRoleDefinition, 0, len(builtin))
for _, definition := range builtin {
@@ -402,14 +402,14 @@ func GetLegacyName(role libregraph.UnifiedRoleDefinition) string {
// CS3ResourcePermissionsToUnifiedRole tries to find the UnifiedRoleDefinition that matches the supplied
// CS3 ResourcePermissions and constraints.
func CS3ResourcePermissionsToUnifiedRole(p provider.ResourcePermissions, constraints string, resharing bool) *libregraph.UnifiedRoleDefinition {
func CS3ResourcePermissionsToUnifiedRole(p provider.ResourcePermissions, constraints string) *libregraph.UnifiedRoleDefinition {
actionSet := map[string]struct{}{}
for _, action := range CS3ResourcePermissionsToLibregraphActions(p) {
actionSet[action] = struct{}{}
}
var res *libregraph.UnifiedRoleDefinition
for _, uRole := range GetBuiltinRoleDefinitionList(resharing) {
for _, uRole := range GetBuiltinRoleDefinitionList() {
matchFound := false
for _, uPerm := range uRole.GetRolePermissions() {
if uPerm.GetCondition() != constraints {
@@ -448,6 +448,10 @@ func displayName(role *conversions.Role) *string {
if role == nil {
return nil
}
// linter wants this to be a var
canEdit := "Can edit"
var displayName string
switch role.Name {
case conversions.RoleViewer:
@@ -455,11 +459,11 @@ func displayName(role *conversions.Role) *string {
case conversions.RoleSpaceViewer:
displayName = "Can view"
case conversions.RoleEditor:
displayName = "Can edit"
displayName = canEdit
case conversions.RoleSpaceEditor:
displayName = "Can edit"
displayName = canEdit
case conversions.RoleFileEditor:
displayName = "Can edit"
displayName = canEdit
case conversions.RoleUploader:
displayName = "Can upload"
case conversions.RoleManager:

View File

@@ -20,13 +20,13 @@ var _ = Describe("unifiedroles", func() {
func(legacyRole *rConversions.Role, unifiedRole *libregraph.UnifiedRoleDefinition, constraints string) {
cs3perm := legacyRole.CS3ResourcePermissions()
r := unifiedrole.CS3ResourcePermissionsToUnifiedRole(*cs3perm, constraints, true)
r := unifiedrole.CS3ResourcePermissionsToUnifiedRole(*cs3perm, constraints)
Expect(r.GetId()).To(Equal(unifiedRole.GetId()))
},
Entry(rConversions.RoleViewer, rConversions.NewViewerRole(true), unifiedrole.NewViewerUnifiedRole(true), unifiedrole.UnifiedRoleConditionGrantee),
Entry(rConversions.RoleEditor, rConversions.NewEditorRole(true), unifiedrole.NewEditorUnifiedRole(true), unifiedrole.UnifiedRoleConditionGrantee),
Entry(rConversions.RoleFileEditor, rConversions.NewFileEditorRole(true), unifiedrole.NewFileEditorUnifiedRole(true), unifiedrole.UnifiedRoleConditionGrantee),
Entry(rConversions.RoleViewer, rConversions.NewViewerRole(), unifiedrole.NewViewerUnifiedRole(), unifiedrole.UnifiedRoleConditionGrantee),
Entry(rConversions.RoleEditor, rConversions.NewEditorRole(), unifiedrole.NewEditorUnifiedRole(), unifiedrole.UnifiedRoleConditionGrantee),
Entry(rConversions.RoleFileEditor, rConversions.NewFileEditorRole(), unifiedrole.NewFileEditorUnifiedRole(), unifiedrole.UnifiedRoleConditionGrantee),
Entry(rConversions.RoleManager, rConversions.NewManagerRole(), unifiedrole.NewManagerUnifiedRole(), unifiedrole.UnifiedRoleConditionOwner),
Entry(rConversions.RoleSpaceViewer, rConversions.NewSpaceViewerRole(), unifiedrole.NewSpaceViewerUnifiedRole(), unifiedrole.UnifiedRoleConditionOwner),
Entry(rConversions.RoleSpaceEditor, rConversions.NewSpaceEditorRole(), unifiedrole.NewSpaceEditorUnifiedRole(), unifiedrole.UnifiedRoleConditionOwner),
@@ -49,11 +49,11 @@ var _ = Describe("unifiedroles", func() {
Expect(permsFromCS3).To(matcher)
},
Entry(rConversions.RoleViewer, rConversions.NewViewerRole(true), unifiedrole.NewViewerUnifiedRole(true), true),
Entry(rConversions.RoleEditor, rConversions.NewEditorRole(true), unifiedrole.NewEditorUnifiedRole(true), true),
Entry(rConversions.RoleFileEditor, rConversions.NewFileEditorRole(true), unifiedrole.NewFileEditorUnifiedRole(true), true),
Entry(rConversions.RoleViewer, rConversions.NewViewerRole(), unifiedrole.NewViewerUnifiedRole(), true),
Entry(rConversions.RoleEditor, rConversions.NewEditorRole(), unifiedrole.NewEditorUnifiedRole(), true),
Entry(rConversions.RoleFileEditor, rConversions.NewFileEditorRole(), unifiedrole.NewFileEditorUnifiedRole(), true),
Entry(rConversions.RoleManager, rConversions.NewManagerRole(), unifiedrole.NewManagerUnifiedRole(), true),
Entry("no match", rConversions.NewFileEditorRole(true), unifiedrole.NewManagerUnifiedRole(), false),
Entry("no match", rConversions.NewFileEditorRole(), unifiedrole.NewManagerUnifiedRole(), false),
)
DescribeTable("WeightRoleDefinitions",
@@ -66,25 +66,25 @@ var _ = Describe("unifiedroles", func() {
Entry("ascending",
[]*libregraph.UnifiedRoleDefinition{
unifiedrole.NewViewerUnifiedRole(false),
unifiedrole.NewFileEditorUnifiedRole(false),
unifiedrole.NewViewerUnifiedRole(),
unifiedrole.NewFileEditorUnifiedRole(),
},
false,
[]*libregraph.UnifiedRoleDefinition{
unifiedrole.NewViewerUnifiedRole(false),
unifiedrole.NewFileEditorUnifiedRole(false),
unifiedrole.NewViewerUnifiedRole(),
unifiedrole.NewFileEditorUnifiedRole(),
},
),
Entry("descending",
[]*libregraph.UnifiedRoleDefinition{
unifiedrole.NewViewerUnifiedRole(false),
unifiedrole.NewFileEditorUnifiedRole(false),
unifiedrole.NewViewerUnifiedRole(),
unifiedrole.NewFileEditorUnifiedRole(),
},
true,
[]*libregraph.UnifiedRoleDefinition{
unifiedrole.NewFileEditorUnifiedRole(false),
unifiedrole.NewViewerUnifiedRole(false),
unifiedrole.NewFileEditorUnifiedRole(),
unifiedrole.NewViewerUnifiedRole(),
},
),
)
@@ -108,9 +108,9 @@ var _ = Describe("unifiedroles", func() {
}
DescribeTable("GetApplicableRoleDefinitionsForActions",
func(givenActions []string, constraints string, resharing bool, expectedDefinitions []*libregraph.UnifiedRoleDefinition) {
func(givenActions []string, constraints string, expectedDefinitions []*libregraph.UnifiedRoleDefinition) {
generatedDefinitions := unifiedrole.GetApplicableRoleDefinitionsForActions(givenActions, constraints, resharing, false)
generatedDefinitions := unifiedrole.GetApplicableRoleDefinitionsForActions(givenActions, constraints, false)
Expect(len(generatedDefinitions)).To(Equal(len(expectedDefinitions)))
@@ -129,90 +129,82 @@ var _ = Describe("unifiedroles", func() {
Entry(
"ViewerUnifiedRole",
rolesToAction(unifiedrole.NewViewerUnifiedRole(false)),
rolesToAction(unifiedrole.NewViewerUnifiedRole()),
unifiedrole.UnifiedRoleConditionGrantee,
false,
[]*libregraph.UnifiedRoleDefinition{
unifiedrole.NewViewerUnifiedRole(false),
unifiedrole.NewViewerUnifiedRole(),
},
),
Entry(
"ViewerUnifiedRole | share",
rolesToAction(unifiedrole.NewViewerUnifiedRole(true)),
rolesToAction(unifiedrole.NewViewerUnifiedRole()),
unifiedrole.UnifiedRoleConditionGrantee,
true,
[]*libregraph.UnifiedRoleDefinition{
unifiedrole.NewViewerUnifiedRole(true),
unifiedrole.NewViewerUnifiedRole(),
},
),
Entry(
"NewFileEditorUnifiedRole",
rolesToAction(unifiedrole.NewFileEditorUnifiedRole(false)),
rolesToAction(unifiedrole.NewFileEditorUnifiedRole()),
unifiedrole.UnifiedRoleConditionGrantee,
false,
[]*libregraph.UnifiedRoleDefinition{
unifiedrole.NewViewerUnifiedRole(false),
unifiedrole.NewFileEditorUnifiedRole(false),
unifiedrole.NewViewerUnifiedRole(),
unifiedrole.NewFileEditorUnifiedRole(),
},
),
Entry(
"NewFileEditorUnifiedRole - share",
rolesToAction(unifiedrole.NewFileEditorUnifiedRole(true)),
rolesToAction(unifiedrole.NewFileEditorUnifiedRole()),
unifiedrole.UnifiedRoleConditionGrantee,
true,
[]*libregraph.UnifiedRoleDefinition{
unifiedrole.NewViewerUnifiedRole(true),
unifiedrole.NewFileEditorUnifiedRole(true),
unifiedrole.NewViewerUnifiedRole(),
unifiedrole.NewFileEditorUnifiedRole(),
},
),
Entry(
"NewEditorUnifiedRole",
rolesToAction(unifiedrole.NewEditorUnifiedRole(false)),
rolesToAction(unifiedrole.NewEditorUnifiedRole()),
unifiedrole.UnifiedRoleConditionGrantee,
false,
[]*libregraph.UnifiedRoleDefinition{
unifiedrole.NewUploaderUnifiedRole(),
unifiedrole.NewViewerUnifiedRole(false),
unifiedrole.NewFileEditorUnifiedRole(false),
unifiedrole.NewEditorUnifiedRole(false),
unifiedrole.NewViewerUnifiedRole(),
unifiedrole.NewFileEditorUnifiedRole(),
unifiedrole.NewEditorUnifiedRole(),
},
),
Entry(
"NewEditorUnifiedRole - share",
rolesToAction(unifiedrole.NewEditorUnifiedRole(true)),
rolesToAction(unifiedrole.NewEditorUnifiedRole()),
unifiedrole.UnifiedRoleConditionGrantee,
true,
[]*libregraph.UnifiedRoleDefinition{
unifiedrole.NewUploaderUnifiedRole(),
unifiedrole.NewViewerUnifiedRole(true),
unifiedrole.NewFileEditorUnifiedRole(true),
unifiedrole.NewEditorUnifiedRole(true),
unifiedrole.NewViewerUnifiedRole(),
unifiedrole.NewFileEditorUnifiedRole(),
unifiedrole.NewEditorUnifiedRole(),
},
),
Entry(
"GetBuiltinRoleDefinitionList",
rolesToAction(unifiedrole.GetBuiltinRoleDefinitionList(false)...),
rolesToAction(unifiedrole.GetBuiltinRoleDefinitionList()...),
unifiedrole.UnifiedRoleConditionGrantee,
false,
[]*libregraph.UnifiedRoleDefinition{
unifiedrole.NewUploaderUnifiedRole(),
unifiedrole.NewViewerUnifiedRole(false),
unifiedrole.NewFileEditorUnifiedRole(false),
unifiedrole.NewEditorUnifiedRole(false),
unifiedrole.NewViewerUnifiedRole(),
unifiedrole.NewFileEditorUnifiedRole(),
unifiedrole.NewEditorUnifiedRole(),
},
),
Entry(
"GetBuiltinRoleDefinitionList",
rolesToAction(unifiedrole.GetBuiltinRoleDefinitionList(false)...),
rolesToAction(unifiedrole.GetBuiltinRoleDefinitionList()...),
unifiedrole.UnifiedRoleConditionOwner,
false,
[]*libregraph.UnifiedRoleDefinition{
unifiedrole.NewSpaceViewerUnifiedRole(),
unifiedrole.NewSpaceEditorUnifiedRole(),
@@ -222,14 +214,13 @@ var _ = Describe("unifiedroles", func() {
Entry(
"GetBuiltinRoleDefinitionList - share",
rolesToAction(unifiedrole.GetBuiltinRoleDefinitionList(true)...),
rolesToAction(unifiedrole.GetBuiltinRoleDefinitionList()...),
unifiedrole.UnifiedRoleConditionGrantee,
true,
[]*libregraph.UnifiedRoleDefinition{
unifiedrole.NewUploaderUnifiedRole(),
unifiedrole.NewViewerUnifiedRole(true),
unifiedrole.NewFileEditorUnifiedRole(true),
unifiedrole.NewEditorUnifiedRole(true),
unifiedrole.NewViewerUnifiedRole(),
unifiedrole.NewFileEditorUnifiedRole(),
unifiedrole.NewEditorUnifiedRole(),
},
),
@@ -237,7 +228,6 @@ var _ = Describe("unifiedroles", func() {
"single",
[]string{unifiedrole.DriveItemQuotaRead},
unifiedrole.UnifiedRoleConditionGrantee,
true,
[]*libregraph.UnifiedRoleDefinition{},
),
@@ -245,7 +235,6 @@ var _ = Describe("unifiedroles", func() {
"mixed",
append(rolesToAction(unifiedrole.NewUploaderUnifiedRole()), unifiedrole.DriveItemQuotaRead),
unifiedrole.UnifiedRoleConditionGrantee,
true,
[]*libregraph.UnifiedRoleDefinition{
unifiedrole.NewUploaderUnifiedRole(),
},
@@ -255,29 +244,26 @@ var _ = Describe("unifiedroles", func() {
{
var newUnifiedRoleFromIDEntries []TableEntry
for _, resharing := range []bool{true, false} {
attachEntry := func(name, id string, definition *libregraph.UnifiedRoleDefinition, errors bool) {
e := Entry(
fmt.Sprintf("%s - resharing: %t", name, resharing),
id,
resharing,
definition,
errors,
)
attachEntry := func(name, id string, definition *libregraph.UnifiedRoleDefinition, errors bool) {
e := Entry(
fmt.Sprintf("%s", name),
id,
definition,
errors,
)
newUnifiedRoleFromIDEntries = append(newUnifiedRoleFromIDEntries, e)
}
for _, definition := range unifiedrole.GetBuiltinRoleDefinitionList(resharing) {
attachEntry(definition.GetDisplayName(), definition.GetId(), definition, false)
}
attachEntry("unknown", "123", nil, true)
newUnifiedRoleFromIDEntries = append(newUnifiedRoleFromIDEntries, e)
}
for _, definition := range unifiedrole.GetBuiltinRoleDefinitionList() {
attachEntry(definition.GetDisplayName(), definition.GetId(), definition, false)
}
attachEntry("unknown", "123", nil, true)
DescribeTable("NewUnifiedRoleFromID",
func(id string, resharing bool, expectedRole *libregraph.UnifiedRoleDefinition, expectError bool) {
role, err := unifiedrole.NewUnifiedRoleFromID(id, resharing)
func(id string, expectedRole *libregraph.UnifiedRoleDefinition, expectError bool) {
role, err := unifiedrole.NewUnifiedRoleFromID(id)
if expectError {
Expect(err).To(HaveOccurred())

View File

@@ -84,8 +84,8 @@ func rolesAndActions(sl validator.StructLevel, roles, actions []string, allowEmp
var availableRoles []string
var availableActions []string
for _, definition := range append(
unifiedrole.GetBuiltinRoleDefinitionList(true),
unifiedrole.GetBuiltinRoleDefinitionList(false)...,
unifiedrole.GetBuiltinRoleDefinitionList(),
unifiedrole.GetBuiltinRoleDefinitionList()...,
) {
if slices.Contains(availableRoles, definition.GetId()) {
continue

View File

@@ -21,8 +21,6 @@ type Config struct {
SkipUserGroupsInToken bool `yaml:"skip_user_groups_in_token" env:"SHARING_SKIP_USER_GROUPS_IN_TOKEN" desc:"Disables the loading of user's group memberships from the reva access token." introductionVersion:"pre5.0"`
EnableResharing bool `yaml:"enable_resharing" env:"OCIS_ENABLE_RESHARING;SHARING_ENABLE_RESHARING" desc:"Changing this value is NOT supported. Enables the support for resharing." introductionVersion:"5.0" deprecationVersion:"5.0" deprecationInfo:"Resharing will be removed in the future."`
UserSharingDriver string `yaml:"user_sharing_driver" env:"SHARING_USER_DRIVER" desc:"Driver to be used to persist shares. Supported values are 'jsoncs3', 'json', 'cs3' (deprecated) and 'owncloudsql'." introductionVersion:"pre5.0"`
UserSharingDrivers UserSharingDrivers `yaml:"user_sharing_drivers"`
PublicSharingDriver string `yaml:"public_sharing_driver" env:"SHARING_PUBLIC_DRIVER" desc:"Driver to be used to persist public shares. Supported values are 'jsoncs3', 'json' and 'cs3' (deprecated)." introductionVersion:"pre5.0"`

View File

@@ -35,7 +35,6 @@ func DefaultConfig() *config.Config {
Name: "sharing",
},
Reva: shared.DefaultRevaConfig(),
EnableResharing: false,
UserSharingDriver: "jsoncs3",
UserSharingDrivers: config.UserSharingDrivers{
JSON: config.UserSharingJSONDriver{

View File

@@ -86,7 +86,6 @@ func SharingConfigFromStruct(cfg *config.Config, logger log.Logger) (map[string]
},
},
},
"disable_resharing": !cfg.EnableResharing,
},
"publicshareprovider": map[string]interface{}{
"gateway_addr": cfg.Reva.Address,