@@ -69,8 +69,9 @@ type DriveItemPermissionsProvider interface {
6969// DriveItemPermissionsService contains the production business logic for everything that relates to permissions on drive items.
7070type DriveItemPermissionsService struct {
7171 BaseGraphService
72- tp trace.TracerProvider
73- identityBackend identity.Backend
72+ tp trace.TracerProvider
73+ identityBackend identity.Backend
74+ hasExternalSharePermission externalSharePermissionChecker
7475}
7576
7677type permissionType int
@@ -83,17 +84,26 @@ const (
8384 OCM
8485)
8586
87+ // supposed to return true if the user can share to users from other instances (multi-instance only)
88+ type externalSharePermissionChecker func (context.Context ) bool
89+
8690// NewDriveItemPermissionsService creates a new DriveItemPermissionsService
87- func NewDriveItemPermissionsService (logger log.Logger , gatewaySelector pool.Selectable [gateway.GatewayAPIClient ], identityCache identity.IdentityCache , config * config.Config , tp trace.TracerProvider , be identity.Backend ) (DriveItemPermissionsService , error ) {
91+ func NewDriveItemPermissionsService (logger log.Logger , gatewaySelector pool.Selectable [gateway.GatewayAPIClient ], identityCache identity.IdentityCache , config * config.Config , tp trace.TracerProvider , be identity.Backend , espc externalSharePermissionChecker ) (DriveItemPermissionsService , error ) {
92+ f := func (context.Context ) bool { return false }
93+ if espc != nil {
94+ f = espc
95+ }
96+
8897 return DriveItemPermissionsService {
8998 BaseGraphService : BaseGraphService {
9099 logger : & log.Logger {Logger : logger .With ().Str ("graph api" , "DrivesDriveItemService" ).Logger ()},
91100 gatewaySelector : gatewaySelector ,
92101 identityCache : identityCache ,
93102 config : config ,
94103 },
95- tp : tp ,
96- identityBackend : be ,
104+ tp : tp ,
105+ identityBackend : be ,
106+ hasExternalSharePermission : f ,
97107 }, nil
98108}
99109
@@ -193,7 +203,7 @@ func (s DriveItemPermissionsService) Invite(ctx context.Context, resourceId *sto
193203 default :
194204 user , err := s .identityCache .GetUser (ctx , objectID )
195205 if errors .Is (err , identity .ErrNotFound ) {
196- if s .config .MultiInstance .Enabled {
206+ if s .config .MultiInstance .Enabled && s . hasExternalSharePermission ( ctx ) {
197207 user , err = s .identityBackend .AddUser (ctx , objectID , s .config .MultiInstance .InstanceID )
198208 }
199209 if s .config .IncludeOCMSharees && err != nil {
0 commit comments