@@ -189,6 +189,25 @@ qx.Class.define("osparc.share.Collaborators", {
189
189
return control || this . base ( arguments , id ) ;
190
190
} ,
191
191
192
+ __canIShare : function ( ) {
193
+ if ( this . _resourceType === "study" && this . _serializedDataCopy [ "workspaceId" ] ) {
194
+ // Access Rights are set at workspace level
195
+ return false ;
196
+ }
197
+ let canIShare = false ;
198
+ switch ( this . _resourceType ) {
199
+ case "study" :
200
+ case "template" :
201
+ case "service" :
202
+ canIShare = osparc . service . Utils . canIWrite ( this . _serializedDataCopy [ "accessRights" ] ) ;
203
+ break ;
204
+ case "workspace" :
205
+ canIShare = osparc . share . CollaboratorsWorkspace . canIDelete ( this . _serializedDataCopy [ "myAccessRights" ] ) ;
206
+ break ;
207
+ }
208
+ return canIShare ;
209
+ } ,
210
+
192
211
__canIChangePermissions : function ( ) {
193
212
if ( this . _resourceType === "study" && this . _serializedDataCopy [ "workspaceId" ] ) {
194
213
// Access Rights are set at workspace level
@@ -227,7 +246,7 @@ qx.Class.define("osparc.share.Collaborators", {
227
246
} ,
228
247
229
248
__buildLayout : function ( ) {
230
- if ( this . __canIChangePermissions ( ) ) {
249
+ if ( this . __canIShare ( ) ) {
231
250
this . __addCollaborators = this . _createChildControlImpl ( "add-collaborator" ) ;
232
251
}
233
252
this . _createChildControlImpl ( "collaborators-list" ) ;
@@ -330,22 +349,22 @@ qx.Class.define("osparc.share.Collaborators", {
330
349
} ,
331
350
332
351
__getLeaveStudyButton : function ( ) {
352
+ const myGid = osparc . auth . Data . getInstance ( ) . getGroupId ( ) ;
333
353
if (
334
354
( this . _resourceType === "study" ) &&
335
- // check the study is shared
336
- ( Object . keys ( this . _serializedDataCopy [ "accessRights" ] ) . length > 1 ) &&
355
+ // check if I'm part of the access rights (not through an organization)
356
+ Object . keys ( this . _serializedDataCopy [ "accessRights" ] ) . includes ( myGid . toString ( ) ) &&
337
357
// check also user is not "prjOwner". Backend will silently not let the frontend remove that user.
338
358
( this . _serializedDataCopy [ "prjOwner" ] !== osparc . auth . Data . getInstance ( ) . getEmail ( ) )
339
359
) {
340
- const myGid = osparc . auth . Data . getInstance ( ) . getGroupId ( ) ;
341
360
const leaveButton = new qx . ui . form . Button ( this . tr ( "Leave" ) + " " + osparc . product . Utils . getStudyAlias ( {
342
361
firstUpperCase : true
343
362
} ) ) . set ( {
344
363
allowGrowX : false ,
345
364
visibility : Object . keys ( this . _serializedDataCopy [ "accessRights" ] ) . includes ( myGid . toString ( ) ) ? "visible" : "excluded"
346
365
} ) ;
347
366
leaveButton . addListener ( "execute" , ( ) => {
348
- let msg = this . _serializedDataCopy [ "name" ] + " " + this . tr ( "will no longer be listed." ) ;
367
+ let msg = `" ${ this . _serializedDataCopy [ "name" ] } " ` + this . tr ( "will no longer be listed." ) ;
349
368
if ( ! osparc . share . CollaboratorsStudy . checkRemoveCollaborator ( this . _serializedDataCopy , myGid ) ) {
350
369
msg += "<br>" ;
351
370
msg += this . tr ( "If you remove yourself, there won't be any other Owners." ) ;
@@ -357,8 +376,10 @@ qx.Class.define("osparc.share.Collaborators", {
357
376
win . open ( ) ;
358
377
win . addListener ( "close" , ( ) => {
359
378
if ( win . getConfirmed ( ) ) {
360
- this . _deleteMember ( { gid : myGid } ) ;
361
- qx . event . message . Bus . dispatchByName ( "reloadStudies" ) ;
379
+ this . _deleteMember ( { gid : myGid } )
380
+ . then ( ( ) => {
381
+ qx . event . message . Bus . dispatchByName ( "reloadStudies" ) ;
382
+ } ) ;
362
383
}
363
384
} , this ) ;
364
385
} , this ) ;
0 commit comments