Skip to content

Commit 4350ddd

Browse files
odeimaizjsaq007
authored andcommitted
🐛 [Frontend] Fix: Share and Leave Study (ITISFoundation#6401)
1 parent 0f511d2 commit 4350ddd

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

services/static-webserver/client/source/class/osparc/data/Roles.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ qx.Class.define("osparc.data.Roles", {
176176

177177
if (showWording) {
178178
const rolesText = new qx.ui.basic.Label(qx.locale.Manager.tr("Roles")).set({
179+
alignY: "middle",
179180
font: "text-13"
180181
});
181182
rolesLayout.add(rolesText);

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

Lines changed: 28 additions & 7 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,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);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ qx.Class.define("osparc.share.CollaboratorsStudy", {
152152
item.setEnabled(false);
153153
}
154154

155-
osparc.info.StudyUtils.removeCollaborator(this._serializedDataCopy, collaborator["gid"])
155+
return osparc.info.StudyUtils.removeCollaborator(this._serializedDataCopy, collaborator["gid"])
156156
.then(() => {
157157
this.fireDataEvent("updateAccessRights", this._serializedDataCopy);
158158
osparc.FlashMessenger.getInstance().logAs(this.tr("Member successfully removed"));

0 commit comments

Comments
 (0)