@@ -189,6 +189,25 @@ qx.Class.define("osparc.share.Collaborators", {
189189      return  control  ||  this . base ( arguments ,  id ) ; 
190190    } , 
191191
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+ 
192211    __canIChangePermissions : function ( )  { 
193212      if  ( this . _resourceType  ===  "study"  &&  this . _serializedDataCopy [ "workspaceId" ] )  { 
194213        // Access Rights are set at workspace level 
@@ -227,7 +246,7 @@ qx.Class.define("osparc.share.Collaborators", {
227246    } , 
228247
229248    __buildLayout : function ( )  { 
230-       if  ( this . __canIChangePermissions ( ) )  { 
249+       if  ( this . __canIShare ( ) )  { 
231250        this . __addCollaborators  =  this . _createChildControlImpl ( "add-collaborator" ) ; 
232251      } 
233252      this . _createChildControlImpl ( "collaborators-list" ) ; 
@@ -330,22 +349,22 @@ qx.Class.define("osparc.share.Collaborators", {
330349    } , 
331350
332351    __getLeaveStudyButton : function ( )  { 
352+       const  myGid  =  osparc . auth . Data . getInstance ( ) . getGroupId ( ) ; 
333353      if  ( 
334354        ( 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 ( ) )  && 
337357        // check also user is not "prjOwner". Backend will silently not let the frontend remove that user. 
338358        ( this . _serializedDataCopy [ "prjOwner" ]  !==  osparc . auth . Data . getInstance ( ) . getEmail ( ) ) 
339359      )  { 
340-         const  myGid  =  osparc . auth . Data . getInstance ( ) . getGroupId ( ) ; 
341360        const  leaveButton  =  new  qx . ui . form . Button ( this . tr ( "Leave" )  +  " "  +  osparc . product . Utils . getStudyAlias ( { 
342361          firstUpperCase : true 
343362        } ) ) . set ( { 
344363          allowGrowX : false , 
345364          visibility : Object . keys ( this . _serializedDataCopy [ "accessRights" ] ) . includes ( myGid . toString ( ) )  ? "visible"  : "excluded" 
346365        } ) ; 
347366        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." ) ; 
349368          if  ( ! osparc . share . CollaboratorsStudy . checkRemoveCollaborator ( this . _serializedDataCopy ,  myGid ) )  { 
350369            msg  +=  "<br>" ; 
351370            msg  +=  this . tr ( "If you remove yourself, there won't be any other Owners." ) ; 
@@ -357,8 +376,10 @@ qx.Class.define("osparc.share.Collaborators", {
357376          win . open ( ) ; 
358377          win . addListener ( "close" ,  ( )  =>  { 
359378            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+                 } ) ; 
362383            } 
363384          } ,  this ) ; 
364385        } ,  this ) ; 
0 commit comments