Skip to content

Commit 20132e5

Browse files
committed
getLeaveStudyButton
1 parent 8add741 commit 20132e5

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

services/static-webserver/client/source/class/osparc/share/Collaborators.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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,14 +349,14 @@ 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 shared (not through an organization)
356+
(Object.keys(this._serializedDataCopy["accessRights"]).includes(myGid)) &&
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({

0 commit comments

Comments
 (0)