Skip to content

Commit 11812a9

Browse files
authored
✨ Frontend: ask backend for override services specifications (#4446)
1 parent 56bda73 commit 11812a9

File tree

6 files changed

+39
-6
lines changed

6 files changed

+39
-6
lines changed

services/static-webserver/client/source/class/osparc/Application.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ qx.Class.define("osparc.Application", {
353353
// Invalidate the entire cache
354354
osparc.store.Store.getInstance().invalidate();
355355

356+
osparc.data.Resources.get("permissions");
357+
356358
osparc.data.Resources.getOne("profile")
357359
.then(profile => {
358360
this.__connectWebSocket();

services/static-webserver/client/source/class/osparc/component/node/UpdateResourceLimitsView.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,9 @@ qx.Class.define("osparc.component.node.UpdateResourceLimitsView", {
171171
this.fireEvent("limitsChanged");
172172
})
173173
.catch(err => {
174-
osparc.component.message.FlashMessenger.getInstance().logAs(this.tr("Something went wrong Updating the limits"), "ERROR");
175174
console.error(err);
175+
const msg = err.message || this.tr("Something went wrong updating the limits");
176+
osparc.component.message.FlashMessenger.getInstance().logAs(msg, "ERROR");
176177
})
177178
.finally(() => {
178179
this.__saveBtn.setFetching(false);

services/static-webserver/client/source/class/osparc/data/Permissions.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ qx.Class.define("osparc.data.Permissions", {
123123
"studies.template.create.all",
124124
"services.all.read",
125125
"services.all.reupdate",
126-
"services.all.updateLimits",
127126
"services.filePicker.read.all",
128127
"user.role.update",
129128
"user.clusters.create",
@@ -256,6 +255,21 @@ qx.Class.define("osparc.data.Permissions", {
256255
return canDo;
257256
},
258257

258+
checkCanDo: function(action) {
259+
return new Promise((resolve, reject) => {
260+
osparc.data.Resources.get("permissions")
261+
.then(permissions => {
262+
const found = permissions.find(permission => permission["name"] === action);
263+
if (found) {
264+
resolve(found["allowed"]);
265+
} else {
266+
resolve(false);
267+
}
268+
})
269+
.catch(err => reject(err));
270+
});
271+
},
272+
259273
isTester: function() {
260274
return ["admin", "tester"].includes(this.getRole());
261275
}

services/static-webserver/client/source/class/osparc/data/Resources.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,18 @@ qx.Class.define("osparc.data.Resources", {
431431
}
432432
}
433433
},
434+
/*
435+
* PERMISSIONS
436+
*/
437+
"permissions": {
438+
useCache: true,
439+
endpoints: {
440+
get: {
441+
method: "GET",
442+
url: statics.API + "/me/permissions"
443+
}
444+
}
445+
},
434446
/*
435447
* API-KEYS
436448
*/

services/static-webserver/client/source/class/osparc/desktop/WorkbenchView.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
10941094
});
10951095
},
10961096

1097-
__populateSecondPanelNode: function(node) {
1097+
__populateSecondPanelNode: async function(node) {
10981098
this.__settingsPage.getChildControl("button").show();
10991099
this.__outputsPage.getChildControl("button").show();
11001100
if (![this.__settingsPage, this.__outputsPage].includes(this.getChildControl("side-panel-right-tabs").getSelection()[0])) {
@@ -1123,14 +1123,14 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
11231123
outputFilesBtn.addListener("execute", () => osparc.component.node.BaseNodeView.openNodeDataManager(node));
11241124
this.__outputsPage.add(outputFilesBtn);
11251125

1126-
const showPage = this.__populateNodeOptionsPage(node);
1126+
const showPage = await this.__populateNodeOptionsPage(node);
11271127
// if it's deprecated or retired show the LifeCycleView right away
11281128
if (showPage && node.hasOutputs() && node.isDynamic() && (node.isDeprecated() || node.isRetired())) {
11291129
this.getChildControl("side-panel-right-tabs").setSelection([this.__nodeOptionsPage]);
11301130
}
11311131
},
11321132

1133-
__populateNodeOptionsPage: function(node) {
1133+
__populateNodeOptionsPage: async function(node) {
11341134
if (osparc.auth.Data.getInstance().isGuest()) {
11351135
return false;
11361136
}
@@ -1158,7 +1158,7 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
11581158
}
11591159

11601160
if (
1161-
osparc.data.Permissions.getInstance().canDo("services.all.updateLimits") &&
1161+
await osparc.data.Permissions.getInstance().checkCanDo("override_services_specifications") &&
11621162
(node.isComputational() || node.isDynamic())
11631163
) {
11641164
const updateResourceLimitsView = new osparc.component.node.UpdateResourceLimitsView(node);

services/static-webserver/client/source/class/osparc/store/Store.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ qx.Class.define("osparc.store.Store", {
104104
check: "Object",
105105
init: {}
106106
},
107+
permissions: {
108+
check: "Array",
109+
init: []
110+
},
107111
apiKeys: {
108112
check: "Array",
109113
init: []

0 commit comments

Comments
 (0)