diff --git a/services/static-webserver/client/source/class/osparc/component/share/Collaborators.js b/services/static-webserver/client/source/class/osparc/component/share/Collaborators.js index ff38c8a1faf..4ea6ca62252 100644 --- a/services/static-webserver/client/source/class/osparc/component/share/Collaborators.js +++ b/services/static-webserver/client/source/class/osparc/component/share/Collaborators.js @@ -195,7 +195,7 @@ qx.Class.define("osparc.component.share.Collaborators", { }); item.addListener("demoteToCollaborator", e => { const orgMember = e.getData(); - this._demoteToCollaborator(orgMember); + this._demoteToCollaborator(orgMember, item); }); item.addListener("removeMember", e => { const orgMember = e.getData(); diff --git a/services/static-webserver/client/source/class/osparc/component/share/CollaboratorsStudy.js b/services/static-webserver/client/source/class/osparc/component/share/CollaboratorsStudy.js index 35c15661307..96d9f4de05e 100644 --- a/services/static-webserver/client/source/class/osparc/component/share/CollaboratorsStudy.js +++ b/services/static-webserver/client/source/class/osparc/component/share/CollaboratorsStudy.js @@ -227,14 +227,37 @@ qx.Class.define("osparc.component.share.CollaboratorsStudy", { ); }, - _demoteToViewer: function(collaborator, item) { - this.__make( - collaborator["gid"], - this.self().getViewerAccessRight(), - this.tr("Collaborator successfully made Viewer"), - this.tr("Something went wrong making Collaborator Viewer"), - item - ); + _demoteToViewer: async function(collaborator, item) { + const groupId = collaborator["gid"]; + const demoteToViewer = (gid, itm) => { + this.__make( + gid, + this.self().getViewerAccessRight(), + this.tr("Collaborator successfully made Viewer"), + this.tr("Something went wrong making Collaborator Viewer"), + itm + ); + }; + + const groupData = await osparc.store.Store.getInstance().getGroup(groupId); + const isOrganization = (groupData && !("id" in groupData)); + const preferencesSettings = osparc.desktop.preferences.Preferences.getInstance(); + if (isOrganization && preferencesSettings.getConfirmDemoteOrgnaization()) { + const msg = this.tr("Demoting to Viewer will remove write access to all the members of the Organization. Are you sure?"); + const win = new osparc.ui.window.Confirmation(msg).set({ + confirmAction: "delete", + confirmText: this.tr("Yes") + }); + win.center(); + win.open(); + win.addListener("close", () => { + if (win.getConfirmed()) { + demoteToViewer(groupId, item); + } + }, this); + } else { + demoteToViewer(groupId, item); + } }, _demoteToCollaborator: function(collaborator, item) { diff --git a/services/static-webserver/client/source/class/osparc/desktop/preferences/Preferences.js b/services/static-webserver/client/source/class/osparc/desktop/preferences/Preferences.js index 5334bf4b713..a67d15932ad 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/preferences/Preferences.js +++ b/services/static-webserver/client/source/class/osparc/desktop/preferences/Preferences.js @@ -49,6 +49,13 @@ qx.Class.define("osparc.desktop.preferences.Preferences", { event: "changeConfirmDeleteStudy" }, + confirmDemoteOrgnaization: { + nullable: false, + init: true, + check: "Boolean", + event: "changeConfirmDemoteOrgnaization" + }, + confirmDeleteNode: { nullable: false, init: true, diff --git a/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ConfirmationsPage.js b/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ConfirmationsPage.js index 3bb0662507f..02ed9040d32 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ConfirmationsPage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ConfirmationsPage.js @@ -72,6 +72,11 @@ qx.Class.define("osparc.desktop.preferences.pages.ConfirmationsPage", { }, this); box.add(cbConfirmDeleteStudy); + const cbConfirmDemoteOrgnaization = new qx.ui.form.CheckBox(this.tr("Demote Organization collaboration")); + preferencesSettings.bind("confirmDemoteOrgnaization", cbConfirmDemoteOrgnaization, "value"); + cbConfirmDemoteOrgnaization.bind("value", preferencesSettings, "confirmDemoteOrgnaization"); + box.add(cbConfirmDemoteOrgnaization); + if (!(osparc.product.Utils.isProduct("tis") || osparc.product.Utils.isProduct("s4llite"))) { const cbConfirmDeleteNode = new qx.ui.form.CheckBox(this.tr("Delete a Node")); preferencesSettings.bind("confirmDeleteNode", cbConfirmDeleteNode, "value"); diff --git a/services/static-webserver/client/source/class/osparc/store/Store.js b/services/static-webserver/client/source/class/osparc/store/Store.js index 7665283a9f6..65018aa56e2 100644 --- a/services/static-webserver/client/source/class/osparc/store/Store.js +++ b/services/static-webserver/client/source/class/osparc/store/Store.js @@ -533,6 +533,20 @@ qx.Class.define("osparc.store.Store", { }); }, + getGroup: function(gid) { + return new Promise(resolve => { + this.getPotentialCollaborators() + .then(potentialCollaborators => { + let group = null; + if (gid in potentialCollaborators) { + group = potentialCollaborators[gid]; + } + resolve(group); + }) + .catch(() => resolve(null)); + }); + }, + __getOrgClassifiers: function(orgId, useCache = false) { const params = { url: {