Skip to content

Commit 30327ed

Browse files
authored
✨ [Frontend] Check if I can write_functions (#7888)
1 parent 975e587 commit 30327ed

File tree

7 files changed

+64
-19
lines changed

7 files changed

+64
-19
lines changed

services/static-webserver/client/source/class/osparc/dashboard/ResourceDetails.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
829829
},
830830

831831
__getCreateFunctionsPage: function() {
832-
if (osparc.utils.DisabledPlugins.isFunctionsDisabled()) {
832+
if (!osparc.data.Permissions.getInstance().checkFunctionPermissions("writeFunctions")) {
833833
return null;
834834
}
835835

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

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ qx.Class.define("osparc.data.Permissions", {
192192
},
193193

194194
members: {
195+
__permissions: null,
196+
__functionPermissions: null,
197+
195198
arePermissionsReady() {
196199
return this.getRole() !== null;
197200
},
@@ -276,19 +279,44 @@ qx.Class.define("osparc.data.Permissions", {
276279
return canDo;
277280
},
278281

279-
checkCanDo: function(action) {
280-
return new Promise((resolve, reject) => {
281-
osparc.data.Resources.get("permissions")
282-
.then(permissions => {
283-
const found = permissions.find(permission => permission["name"] === action);
284-
if (found) {
285-
resolve(found["allowed"]);
286-
} else {
287-
resolve(false);
288-
}
289-
})
290-
.catch(err => reject(err));
291-
});
282+
fetchPermissions: function() {
283+
osparc.data.Resources.get("permissions")
284+
.then(permissions => {
285+
this.__permissions = permissions;
286+
})
287+
.catch(err => console.error(err));
288+
},
289+
290+
checkMyGroupCanDo: function(action) {
291+
if (this.__permissions) {
292+
const found = this.__permissions.find(permission => permission["name"] === action);
293+
if (found) {
294+
return found["allowed"];
295+
}
296+
}
297+
return false;
298+
},
299+
300+
fetchFunctionPermissions: function() {
301+
osparc.data.Resources.get("functionPermissions")
302+
.then(functionPermissions => {
303+
this.__functionPermissions = functionPermissions;
304+
})
305+
.catch(err => console.error(err));
306+
},
307+
308+
checkFunctionPermissions: function(action) {
309+
if (osparc.utils.DisabledPlugins.isFunctionsDisabled()) {
310+
return false;
311+
}
312+
313+
if (
314+
this.__functionPermissions &&
315+
action in this.__functionPermissions
316+
) {
317+
return this.__functionPermissions[action];
318+
}
319+
return false;
292320
},
293321

294322
isTester: function() {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,18 @@ qx.Class.define("osparc.data.Resources", {
837837
}
838838
}
839839
},
840+
/*
841+
* FUNCTION PERMISSIONS
842+
*/
843+
"functionPermissions": {
844+
useCache: true,
845+
endpoints: {
846+
get: {
847+
method: "GET",
848+
url: statics.API + "/me/function-permissions"
849+
}
850+
}
851+
},
840852
/*
841853
* API-KEYS
842854
*/

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ qx.Class.define("osparc.desktop.MainPage", {
7070
preloadPromises.push(osparc.store.Products.getInstance().fetchUiConfig());
7171
preloadPromises.push(osparc.store.PollTasks.getInstance().fetchTasks());
7272
preloadPromises.push(osparc.store.Jobs.getInstance().fetchJobsLatest());
73+
preloadPromises.push(osparc.data.Permissions.getInstance().fetchPermissions());
74+
preloadPromises.push(osparc.data.Permissions.getInstance().fetchFunctionPermissions());
7375
Promise.all(preloadPromises)
7476
.then(() => {
7577
const mainStack = this.__createMainStack();

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,8 +1090,6 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
10901090
}
10911091

10921092
const nodeOptions = new osparc.widget.NodeOptions(node);
1093-
nodeOptions.buildLayout();
1094-
10951093
return nodeOptions;
10961094
},
10971095

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ qx.Class.define("osparc.store.Store", {
178178
check: "Array",
179179
init: []
180180
},
181+
functionPermissions: {
182+
check: "Object",
183+
init: {}
184+
},
181185
apiKeys: {
182186
check: "Array",
183187
init: []

services/static-webserver/client/source/class/osparc/widget/NodeOptions.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ qx.Class.define("osparc.widget.NodeOptions", {
3636
properties: {
3737
node: {
3838
check: "osparc.data.model.Node",
39-
nullable: false
39+
nullable: false,
40+
apply: "__buildLayout",
4041
}
4142
},
4243

@@ -46,7 +47,7 @@ qx.Class.define("osparc.widget.NodeOptions", {
4647
this.show();
4748
},
4849

49-
buildLayout: async function() {
50+
__buildLayout: function() {
5051
const node = this.getNode();
5152

5253
const sections = [];
@@ -83,7 +84,7 @@ qx.Class.define("osparc.widget.NodeOptions", {
8384

8485
// Update Resource Limits
8586
if (
86-
await osparc.data.Permissions.getInstance().checkCanDo("override_services_specifications") &&
87+
osparc.data.Permissions.getInstance().checkMyGroupCanDo("override_services_specifications") &&
8788
(node.isComputational() || node.isDynamic())
8889
) {
8990
const updateResourceLimitsView = new osparc.node.UpdateResourceLimitsView(node);

0 commit comments

Comments
 (0)