Skip to content

Commit df0b6c7

Browse files
authored
🐛 [Frontend] Do not allow to leave studies with no owners (ITISFoundation#7370)
1 parent ddbf7ee commit df0b6c7

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

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

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,21 @@ 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+
let msg = this.tr("Collaborator can't be removed:");
343+
msg += this._serializedDataCopy["name"] + this.tr(" needs at least one owner.");
344+
if (
345+
Object.keys(this._serializedDataCopy["accessRights"]).length === 1 &&
346+
Object.values(this._serializedDataCopy["accessRights"])[0]["delete"]
347+
) {
348+
msg += "<br>" + this.tr("You might want to delete it instead.");
349+
}
350+
osparc.FlashMessenger.logError(msg);
351+
return;
352+
}
338353
this._deleteMember(orgMember, item);
339354
});
340355
}
@@ -349,11 +364,8 @@ qx.Class.define("osparc.share.Collaborators", {
349364
__getLeaveStudyButton: function() {
350365
const myGid = osparc.auth.Data.getInstance().getGroupId();
351366
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())
367+
["study", "template"].includes(this._resourceType) &&
368+
osparc.share.CollaboratorsStudy.canCollaboratorBeRemoved(this._serializedDataCopy, myGid)
357369
) {
358370
const leaveText = this.tr("Leave") + " " + osparc.product.Utils.getStudyAlias({
359371
firstUpperCase: true
@@ -363,29 +375,14 @@ qx.Class.define("osparc.share.Collaborators", {
363375
visibility: Object.keys(this._serializedDataCopy["accessRights"]).includes(myGid.toString()) ? "visible" : "excluded"
364376
});
365377
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.");
378+
const collaborator = {
379+
gid: myGid,
380+
name: osparc.store.Groups.getInstance().getGroupMe().getLabel(),
370381
}
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);
382+
this._deleteMember(collaborator)
383+
.then(() => {
384+
qx.event.message.Bus.dispatchByName("reloadStudies");
385+
});
389386
}, this);
390387
return leaveButton;
391388
}

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)