Skip to content

Commit 8a65bde

Browse files
authored
Bugfix: Share study with Organization (ITISFoundation#2370)
* store org IDs in auth data * canGroupsWrite
1 parent 762494e commit 8a65bde

File tree

9 files changed

+62
-29
lines changed

9 files changed

+62
-29
lines changed

services/web/client/source/class/osparc/auth/Data.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ qx.Class.define("osparc.auth.Data", {
4343
check: "Number"
4444
},
4545

46+
/**
47+
* org IDs
48+
*/
49+
orgIds: {
50+
init: [],
51+
nullable: false,
52+
check: "Array"
53+
},
54+
4655
/**
4756
* Basic authentification with a token
4857
*/

services/web/client/source/class/osparc/auth/Manager.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ qx.Class.define("osparc.auth.Manager", {
148148
osparc.auth.Data.getInstance().setToken(profile.login);
149149
osparc.auth.Data.getInstance().setUserId(profile.id);
150150
osparc.auth.Data.getInstance().setGroupId(profile["groups"]["me"]["gid"]);
151+
if ("organizations" in profile["groups"]) {
152+
const orgIds = [];
153+
profile["groups"]["organizations"].forEach(org => orgIds.push(org["gid"]));
154+
osparc.auth.Data.getInstance().setOrgIds(orgIds);
155+
}
151156
osparc.data.Permissions.getInstance().setRole(profile.role);
152157
},
153158

services/web/client/source/class/osparc/component/metadata/QualityEditor.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,9 @@ qx.Class.define("osparc.component.metadata.QualityEditor", {
692692
if (osparc.utils.Resources.isService(this.__resourceData)) {
693693
return osparc.component.permissions.Service.canGroupWrite(this.__resourceData["access_rights"], myGid);
694694
}
695-
return osparc.component.permissions.Study.canGroupWrite(this.__resourceData["accessRights"], myGid);
695+
const orgIDs = osparc.auth.Data.getInstance().getOrgIds();
696+
orgIDs.push(myGid);
697+
return osparc.component.permissions.Study.canGroupsWrite(this.__resourceData["accessRights"], orgIDs);
696698
}
697699
return false;
698700
}

services/web/client/source/class/osparc/component/metadata/ServicesInStudy.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ qx.Class.define("osparc.component.metadata.ServicesInStudy", {
193193
column: this.self().gridPos.latestVersion
194194
});
195195

196-
if (osparc.data.Permissions.getInstance().canDo("study.service.update") && osparc.data.model.Study.canIWrite(this.__studyData["accessRights"])) {
196+
const myGroupId = osparc.auth.Data.getInstance().getGroupId();
197+
const orgIDs = osparc.auth.Data.getInstance().getOrgIds();
198+
orgIDs.push(myGroupId);
199+
const canIWrite = osparc.component.permissions.Study.canGroupsWrite(this.__studyData["accessRights"], orgIDs);
200+
if (osparc.data.Permissions.getInstance().canDo("study.service.update") && canIWrite) {
197201
const updateButton = new osparc.ui.form.FetchButton(null, "@MaterialIcons/update/14");
198202
updateButton.set({
199203
label: node["version"] === latestCompatibleMetadata["version"] ? this.tr("Up-to-date") : this.tr("Update"),

services/web/client/source/class/osparc/component/permissions/Study.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,7 @@ qx.Class.define("osparc.component.permissions.Study", {
4141
},
4242

4343
statics: {
44-
canGroupRead: function(accessRights, GID) {
45-
if (GID in accessRights) {
46-
return accessRights[GID]["read"];
47-
}
48-
return false;
49-
},
50-
canGroupWrite: function(accessRights, GID) {
44+
__canGroupWrite: function(accessRights, GID) {
5145
if (GID in accessRights) {
5246
return accessRights[GID]["write"];
5347
}
@@ -60,6 +54,15 @@ qx.Class.define("osparc.component.permissions.Study", {
6054
return false;
6155
},
6256

57+
canGroupsWrite: function(accessRights, GIDs) {
58+
let canWrite = false;
59+
for (let i=0; i<GIDs.length && !canWrite; i++) {
60+
// eslint-disable-next-line no-underscore-dangle
61+
canWrite = this.self().__canGroupWrite(accessRights, GIDs[i]);
62+
}
63+
return canWrite;
64+
},
65+
6366
getViewerAccessRight: function() {
6467
return {
6568
"read": true,

services/web/client/source/class/osparc/dashboard/StudyBrowserButtonItem.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,11 @@ qx.Class.define("osparc.dashboard.StudyBrowserButtonItem", {
454454

455455
__setStudyPermissions: function(accessRights) {
456456
const myGroupId = osparc.auth.Data.getInstance().getGroupId();
457+
const orgIDs = osparc.auth.Data.getInstance().getOrgIds();
458+
orgIDs.push(myGroupId);
459+
457460
const image = this.getChildControl("permission-icon");
458-
if (osparc.component.permissions.Study.canGroupWrite(accessRights, myGroupId)) {
461+
if (osparc.component.permissions.Study.canGroupsWrite(accessRights, orgIDs)) {
459462
image.exclude();
460463
} else {
461464
image.setSource(this.self().PERM_READ);

services/web/client/source/class/osparc/data/model/Study.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,6 @@ qx.Class.define("osparc.data.model.Study", {
223223
return osparc.component.permissions.Study.canGroupExecute(aceessRights, myGid);
224224
},
225225

226-
canIWrite: function(accessRights) {
227-
const myGid = osparc.auth.Data.getInstance().getGroupId();
228-
if (myGid) {
229-
return osparc.component.permissions.Study.canGroupWrite(accessRights, myGid);
230-
}
231-
return false;
232-
},
233-
234226
hasSlideshow: function(studyData) {
235227
if ("ui" in studyData && "slideshow" in studyData["ui"] && Object.keys(studyData["ui"]["slideshow"]).length) {
236228
return true;
@@ -250,8 +242,11 @@ qx.Class.define("osparc.data.model.Study", {
250242

251243
__applyAccessRights: function(value) {
252244
const myGid = osparc.auth.Data.getInstance().getGroupId();
245+
const orgIDs = osparc.auth.Data.getInstance().getOrgIds();
246+
orgIDs.push(myGid);
247+
253248
if (myGid) {
254-
const canIWrite = osparc.component.permissions.Study.canGroupWrite(value, myGid);
249+
const canIWrite = osparc.component.permissions.Study.canGroupsWrite(value, orgIDs);
255250
this.setReadOnly(!canIWrite);
256251
} else {
257252
this.setReadOnly(true);

services/web/client/source/class/osparc/desktop/StudyEditor.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,22 @@ qx.Class.define("osparc.desktop.StudyEditor", {
126126
study.openStudy()
127127
.then(() => {
128128
study.initStudy();
129-
const myGrpId = osparc.auth.Data.getInstance().getGroupId();
130-
if (osparc.component.permissions.Study.canGroupWrite(study.getAccessRights(), myGrpId)) {
131-
this.__startAutoSaveTimer();
132-
} else {
133-
const msg = this.tr("You do not have writing permissions.<br>Changes will not be saved");
134-
osparc.component.message.FlashMessenger.getInstance().logAs(msg, "INFO");
135-
}
129+
130+
osparc.data.Resources.get("organizations")
131+
.then(resp => {
132+
const myGroupId = osparc.auth.Data.getInstance().getGroupId();
133+
const orgs = resp["organizations"];
134+
const orgIDs = [myGroupId];
135+
orgs.forEach(org => orgIDs.push(org["gid"]));
136+
137+
if (osparc.component.permissions.Study.canGroupsWrite(study.getAccessRights(), orgIDs)) {
138+
this.__startAutoSaveTimer();
139+
} else {
140+
const msg = this.tr("You do not have writing permissions.<br>Changes will not be saved");
141+
osparc.component.message.FlashMessenger.getInstance().logAs(msg, "INFO");
142+
}
143+
});
144+
136145
switch (this.getPageContext()) {
137146
case "slideshow":
138147
this.__slideshowView.startSlides();
@@ -414,7 +423,9 @@ qx.Class.define("osparc.desktop.StudyEditor", {
414423

415424
updateStudyDocument: function(run = false) {
416425
const myGrpId = osparc.auth.Data.getInstance().getGroupId();
417-
if (!osparc.component.permissions.Study.canGroupWrite(this.getStudy().getAccessRights(), myGrpId)) {
426+
const orgIDs = osparc.auth.Data.getInstance().getOrgIds();
427+
orgIDs.push(myGrpId);
428+
if (!osparc.component.permissions.Study.canGroupsWrite(this.getStudy().getAccessRights(), orgIDs)) {
418429
return new Promise(resolve => {
419430
resolve();
420431
});

tests/e2e/portal-files/VTK_file.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ async function runTutorial () {
4141
const workbenchData = utils.extractWorkbenchData(studyData["data"]);
4242
const nodeIdViewer = workbenchData["nodeIds"][1];
4343
await tutorial.waitForServices(workbenchData["studyId"], [nodeIdViewer]);
44-
45-
// Some time for starting the service
4644
await utils.takeScreenshot(page, screenshotPrefix + 'service_started');
4745

46+
// Some time for setting up service's frontend
47+
await tutorial.waitFor(3000);
48+
4849
const iframeHandles = await page.$$("iframe");
4950
const iframes = [];
5051
for (let i=0; i<iframeHandles.length; i++) {

0 commit comments

Comments
 (0)