|
| 1 | +/* ************************************************************************ |
| 2 | +
|
| 3 | + osparc - the simcore frontend |
| 4 | +
|
| 5 | + https://osparc.io |
| 6 | +
|
| 7 | + Copyright: |
| 8 | + 2025 IT'IS Foundation, https://itis.swiss |
| 9 | +
|
| 10 | + License: |
| 11 | + MIT: https://opensource.org/licenses/MIT |
| 12 | +
|
| 13 | + Authors: |
| 14 | + * Odei Maiz (odeimaiz) |
| 15 | +
|
| 16 | +************************************************************************ */ |
| 17 | + |
| 18 | + |
| 19 | +qx.Class.define("osparc.share.CollaboratorsTag", { |
| 20 | + extend: osparc.share.Collaborators, |
| 21 | + |
| 22 | + /** |
| 23 | + * @param tag {osparc.data.model.Tag} |
| 24 | + */ |
| 25 | + construct: function(tag) { |
| 26 | + this.__tag = tag; |
| 27 | + this._resourceType = "tag"; |
| 28 | + |
| 29 | + const tagDataCopy = tag.serialize(); |
| 30 | + this.base(arguments, tagDataCopy, []); |
| 31 | + }, |
| 32 | + |
| 33 | + statics: { |
| 34 | + canIDelete: function(myAccessRights) { |
| 35 | + return myAccessRights["delete"]; |
| 36 | + }, |
| 37 | + |
| 38 | + getViewerAccessRight: function() { |
| 39 | + return { |
| 40 | + "read": true, |
| 41 | + "write": false, |
| 42 | + "delete": false |
| 43 | + }; |
| 44 | + }, |
| 45 | + |
| 46 | + getCollaboratorAccessRight: function() { |
| 47 | + return { |
| 48 | + "read": true, |
| 49 | + "write": true, |
| 50 | + "delete": false |
| 51 | + }; |
| 52 | + }, |
| 53 | + |
| 54 | + getOwnerAccessRight: function() { |
| 55 | + return { |
| 56 | + "read": true, |
| 57 | + "write": true, |
| 58 | + "delete": true |
| 59 | + }; |
| 60 | + } |
| 61 | + }, |
| 62 | + |
| 63 | + members: { |
| 64 | + __tag: null, |
| 65 | + |
| 66 | + _addEditors: function(gids) { |
| 67 | + if (gids.length === 0) { |
| 68 | + return; |
| 69 | + } |
| 70 | + |
| 71 | + const newCollaborators = {}; |
| 72 | + gids.forEach(gid => newCollaborators[gid] = this.self().getCollaboratorAccessRight()); |
| 73 | + osparc.store.Tags.getInstance().addCollaborators(this.__tag.getTagId(), newCollaborators) |
| 74 | + .then(() => { |
| 75 | + const text = this.tr("Tag successfully shared"); |
| 76 | + osparc.FlashMessenger.getInstance().logAs(text); |
| 77 | + this.fireDataEvent("updateAccessRights", this.__tag.serialize()); |
| 78 | + this._reloadCollaboratorsList(); |
| 79 | + }) |
| 80 | + .catch(err => { |
| 81 | + console.error(err); |
| 82 | + osparc.FlashMessenger.getInstance().logAs(this.tr("Something went wrong sharing the Tag"), "ERROR"); |
| 83 | + }); |
| 84 | + }, |
| 85 | + |
| 86 | + _deleteMember: function(collaborator, item) { |
| 87 | + if (item) { |
| 88 | + item.setEnabled(false); |
| 89 | + } |
| 90 | + |
| 91 | + osparc.store.Tags.getInstance().removeCollaborator(this.__tag.getTagId(), collaborator["gid"]) |
| 92 | + .then(() => { |
| 93 | + this.fireDataEvent("updateAccessRights", this.__tag.serialize()); |
| 94 | + osparc.FlashMessenger.getInstance().logAs(collaborator["name"] + this.tr(" successfully removed")); |
| 95 | + this._reloadCollaboratorsList(); |
| 96 | + }) |
| 97 | + .catch(err => { |
| 98 | + console.error(err); |
| 99 | + osparc.FlashMessenger.getInstance().logAs(this.tr("Something went wrong removing ") + collaborator["name"], "ERROR"); |
| 100 | + }) |
| 101 | + .finally(() => { |
| 102 | + if (item) { |
| 103 | + item.setEnabled(true); |
| 104 | + } |
| 105 | + }); |
| 106 | + }, |
| 107 | + |
| 108 | + __make: function(collaboratorGId, newAccessRights, successMsg, failureMsg, item) { |
| 109 | + item.setEnabled(false); |
| 110 | + |
| 111 | + osparc.store.Tags.getInstance().updateCollaborator(this.__tag.getTagId(), collaboratorGId, newAccessRights) |
| 112 | + .then(() => { |
| 113 | + this.fireDataEvent("updateAccessRights", this.__tag.serialize()); |
| 114 | + osparc.FlashMessenger.getInstance().logAs(successMsg); |
| 115 | + this._reloadCollaboratorsList(); |
| 116 | + }) |
| 117 | + .catch(err => { |
| 118 | + console.error(err); |
| 119 | + osparc.FlashMessenger.getInstance().logAs(failureMsg, "ERROR"); |
| 120 | + }) |
| 121 | + .finally(() => { |
| 122 | + if (item) { |
| 123 | + item.setEnabled(true); |
| 124 | + } |
| 125 | + }); |
| 126 | + }, |
| 127 | + |
| 128 | + _promoteToEditor: function(collaborator, item) { |
| 129 | + this.__make( |
| 130 | + collaborator["gid"], |
| 131 | + this.self().getCollaboratorAccessRight(), |
| 132 | + this.tr(`Successfully promoted to ${osparc.data.Roles.WORKSPACE[2].label}`), |
| 133 | + this.tr(`Something went wrong promoting to ${osparc.data.Roles.WORKSPACE[2].label}`), |
| 134 | + item |
| 135 | + ); |
| 136 | + }, |
| 137 | + |
| 138 | + _promoteToOwner: function(collaborator, item) { |
| 139 | + this.__make( |
| 140 | + collaborator["gid"], |
| 141 | + this.self().getOwnerAccessRight(), |
| 142 | + this.tr(`Successfully promoted to ${osparc.data.Roles.WORKSPACE[3].label}`), |
| 143 | + this.tr(`Something went wrong promoting to ${osparc.data.Roles.WORKSPACE[3].label}`), |
| 144 | + item |
| 145 | + ); |
| 146 | + }, |
| 147 | + |
| 148 | + _demoteToUser: async function(collaborator, item) { |
| 149 | + const groupId = collaborator["gid"]; |
| 150 | + const demoteToUser = (gid, itm) => { |
| 151 | + this.__make( |
| 152 | + gid, |
| 153 | + this.self().getViewerAccessRight(), |
| 154 | + this.tr(`Successfully demoted to ${osparc.data.Roles.WORKSPACE[1].label}`), |
| 155 | + this.tr(`Something went wrong demoting to ${osparc.data.Roles.WORKSPACE[1].label}`), |
| 156 | + itm |
| 157 | + ); |
| 158 | + }; |
| 159 | + |
| 160 | + const group = osparc.store.Groups.getInstance().getOrganization(groupId); |
| 161 | + if (group) { |
| 162 | + const msg = this.tr(`Demoting to ${osparc.data.Roles.WORKSPACE[1].label} will remove write access to all the members of the Organization. Are you sure?`); |
| 163 | + const win = new osparc.ui.window.Confirmation(msg).set({ |
| 164 | + caption: this.tr("Demote"), |
| 165 | + confirmAction: "delete", |
| 166 | + confirmText: this.tr("Yes") |
| 167 | + }); |
| 168 | + win.center(); |
| 169 | + win.open(); |
| 170 | + win.addListener("close", () => { |
| 171 | + if (win.getConfirmed()) { |
| 172 | + demoteToUser(groupId, item); |
| 173 | + } |
| 174 | + }, this); |
| 175 | + } else { |
| 176 | + demoteToUser(groupId, item); |
| 177 | + } |
| 178 | + }, |
| 179 | + |
| 180 | + _demoteToEditor: function(collaborator, item) { |
| 181 | + this.__make( |
| 182 | + collaborator["gid"], |
| 183 | + this.self().getCollaboratorAccessRight(), |
| 184 | + this.tr(`Successfully demoted to ${osparc.data.Roles.WORKSPACE[2].label}`), |
| 185 | + this.tr(`Something went wrong demoting to ${osparc.data.Roles.WORKSPACE[2].label}`), |
| 186 | + item |
| 187 | + ); |
| 188 | + } |
| 189 | + } |
| 190 | +}); |
0 commit comments