Skip to content

Commit fbe8e31

Browse files
committed
CollaboratorsTag
1 parent 7b21119 commit fbe8e31

File tree

2 files changed

+193
-1
lines changed

2 files changed

+193
-1
lines changed

services/static-webserver/client/source/class/osparc/form/tag/TagItem.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ qx.Class.define("osparc.form.tag.TagItem", {
206206
},
207207

208208
__openAccessRights: function() {
209-
209+
const permissionsView = new osparc.share.CollaboratorsTag(this.getTag());
210+
const title = this.tr("Share Tag");
211+
osparc.ui.window.Window.popUpInWindow(permissionsView, title, 600, 600);
210212
},
211213

212214
/**
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
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

Comments
 (0)