Skip to content

Commit e2370a6

Browse files
committed
canCollaboratorBeRemoved before removing
1 parent 0d04169 commit e2370a6

File tree

2 files changed

+17
-28
lines changed

2 files changed

+17
-28
lines changed

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

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,13 @@ qx.Class.define("osparc.share.Collaborators", {
335335
});
336336
item.addListener("removeMember", e => {
337337
const orgMember = e.getData();
338+
if (
339+
["study", "template"].includes(this._resourceType) &&
340+
!osparc.share.CollaboratorsStudy.canCollaboratorBeRemoved(this._serializedDataCopy, orgMember["gid"])
341+
) {
342+
const msg = "Nope";
343+
osparc.FlashMessenger.logError(msg);
344+
}
338345
this._deleteMember(orgMember, item);
339346
});
340347
}
@@ -349,11 +356,8 @@ qx.Class.define("osparc.share.Collaborators", {
349356
__getLeaveStudyButton: function() {
350357
const myGid = osparc.auth.Data.getInstance().getGroupId();
351358
if (
352-
(this._resourceType === "study") &&
353-
// check if I'm part of the access rights (not through an organization)
354-
Object.keys(this._serializedDataCopy["accessRights"]).includes(myGid.toString()) &&
355-
// check also user is not "prjOwner". Backend will silently not let the frontend remove that user.
356-
(this._serializedDataCopy["prjOwner"] !== osparc.auth.Data.getInstance().getEmail())
359+
["study", "template"].includes(this._resourceType) &&
360+
osparc.share.CollaboratorsStudy.canCollaboratorBeRemoved(this._serializedDataCopy, myGid)
357361
) {
358362
const leaveText = this.tr("Leave") + " " + osparc.product.Utils.getStudyAlias({
359363
firstUpperCase: true
@@ -363,29 +367,14 @@ qx.Class.define("osparc.share.Collaborators", {
363367
visibility: Object.keys(this._serializedDataCopy["accessRights"]).includes(myGid.toString()) ? "visible" : "excluded"
364368
});
365369
leaveButton.addListener("execute", () => {
366-
let msg = `"${this._serializedDataCopy["name"]}" ` + this.tr("will no longer be listed.");
367-
if (!osparc.share.CollaboratorsStudy.checkRemoveCollaborator(this._serializedDataCopy, myGid)) {
368-
msg += "<br>";
369-
msg += this.tr("If you remove yourself, there won't be any other Owners.");
370+
const collaborator = {
371+
gid: myGid,
372+
name: osparc.store.Groups.getInstance().getGroupMe().getLabel(),
370373
}
371-
const win = new osparc.ui.window.Confirmation(msg).set({
372-
caption: leaveText,
373-
confirmText: this.tr("Leave"),
374-
confirmAction: "delete"
375-
});
376-
win.open();
377-
win.addListener("close", () => {
378-
if (win.getConfirmed()) {
379-
const collaborator = {
380-
gid: myGid,
381-
name: osparc.store.Groups.getInstance().getGroupMe().getLabel(),
382-
}
383-
this._deleteMember(collaborator)
384-
.then(() => {
385-
qx.event.message.Bus.dispatchByName("reloadStudies");
386-
});
387-
}
388-
}, this);
374+
this._deleteMember(collaborator)
375+
.then(() => {
376+
qx.event.message.Bus.dispatchByName("reloadStudies");
377+
});
389378
}, this);
390379
return leaveButton;
391380
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ qx.Class.define("osparc.share.CollaboratorsStudy", {
9292
},
9393

9494
// checks that if the user to remove is an owner, there will still be another owner
95-
checkRemoveCollaborator: function(studyData, gid) {
95+
canCollaboratorBeRemoved: function(studyData, gid) {
9696
const ownerGids = this.__getDeleters(studyData);
9797
if (ownerGids.includes(gid.toString())) {
9898
return ownerGids.length > 1;

0 commit comments

Comments
 (0)