Skip to content

Commit 10618a4

Browse files
authored
Block studies that contain unknown (no permissions) services (ITISFoundation#2999)
1 parent 8d2d96c commit 10618a4

File tree

10 files changed

+189
-204
lines changed

10 files changed

+189
-204
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ qx.Class.define("osparc.component.metadata.ServicesInStudy", {
8585
this._populateLayout();
8686
})
8787
.catch(err => {
88-
osparc.component.message.FlashMessenger.getInstance().logAs(this.tr("Something went wrong updating the Service"), "ERROR");
89-
console.error(err);
88+
if ("message" in err) {
89+
osparc.component.message.FlashMessenger.getInstance().logAs(err.message, "ERROR");
90+
} else {
91+
osparc.component.message.FlashMessenger.getInstance().logAs(this.tr("Something went wrong updating the Service"), "ERROR");
92+
}
9093
})
9194
.finally(() => {
9295
if (fetchButton) {

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ qx.Class.define("osparc.component.metadata.ServicesInStudyUpdate", {
7070
column: this.self().GRID_POS.LATEST_VERSION
7171
});
7272

73-
const updateAllButton = this.__updateAllButton = new osparc.ui.form.FetchButton(this.tr("Update all"), "@MaterialIcons/update/14");
73+
const updateAllButton = this.__updateAllButton = new osparc.ui.form.FetchButton(this.tr("Update all"), "@MaterialIcons/update/14").set({
74+
appearance: "strong-button",
75+
visibility: "excluded"
76+
});
7477
this._add(updateAllButton, {
7578
row: 0,
7679
column: this.self().GRID_POS.UPDATE_BUTTON
@@ -80,6 +83,11 @@ qx.Class.define("osparc.component.metadata.ServicesInStudyUpdate", {
8083
_populateRows: function() {
8184
this.base(arguments);
8285

86+
const myGroupId = osparc.auth.Data.getInstance().getGroupId();
87+
const orgIDs = osparc.auth.Data.getInstance().getOrgIds();
88+
orgIDs.push(myGroupId);
89+
const canIWriteStudy = osparc.component.permissions.Study.canGroupsWrite(this._studyData["accessRights"], orgIDs);
90+
8391
const updatableServices = [];
8492
let i = 0;
8593
const workbench = this._studyData["workbench"];
@@ -115,11 +123,7 @@ qx.Class.define("osparc.component.metadata.ServicesInStudyUpdate", {
115123
column: this.self().GRID_POS.LATEST_VERSION
116124
});
117125

118-
const myGroupId = osparc.auth.Data.getInstance().getGroupId();
119-
const orgIDs = osparc.auth.Data.getInstance().getOrgIds();
120-
orgIDs.push(myGroupId);
121-
const canIWrite = osparc.component.permissions.Study.canGroupsWrite(this._studyData["accessRights"], orgIDs);
122-
if (osparc.data.Permissions.getInstance().canDo("study.service.update") && canIWrite) {
126+
if (osparc.data.Permissions.getInstance().canDo("study.service.update") && canIWriteStudy) {
123127
const updateButton = new osparc.ui.form.FetchButton(null, "@MaterialIcons/update/14");
124128
updateButton.set({
125129
label: updatable ? this.tr("Update") : this.tr("Up-to-date"),
@@ -136,11 +140,10 @@ qx.Class.define("osparc.component.metadata.ServicesInStudyUpdate", {
136140
}
137141
}
138142

139-
const updateAllButton = this.__updateAllButton;
140-
updateAllButton.addListener("execute", () => this.__updateAllServices(updatableServices, updateAllButton), this);
141-
updateAllButton.setEnabled(Boolean(updatableServices.length));
142-
if (updatableServices.length) {
143-
updateAllButton.setAppearance("strong-button");
143+
if (osparc.data.Permissions.getInstance().canDo("study.service.update") && canIWriteStudy) {
144+
const updateAllButton = this.__updateAllButton;
145+
updateAllButton.show();
146+
updateAllButton.addListener("execute", () => this.__updateAllServices(updatableServices, updateAllButton), this);
144147
}
145148
}
146149
}

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

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ qx.Class.define("osparc.dashboard.CardBase", {
335335
if (workbench === null) {
336336
return;
337337
}
338+
338339
const updateStudy = this.getChildControl("update-study");
339340
osparc.utils.Study.isWorkbenchUpdatable(workbench)
340341
.then(updatable => {
@@ -347,10 +348,100 @@ qx.Class.define("osparc.dashboard.CardBase", {
347348
updateStudy.addListener("pointerdown", e => e.stopPropagation());
348349
}
349350
});
351+
352+
osparc.utils.Study.getUnaccessibleServices(workbench)
353+
.then(unaccessibleServices => {
354+
if (unaccessibleServices.length) {
355+
this.setLocked(true);
356+
const image = "@FontAwesome5Solid/ban/";
357+
let toolTipText = this.tr("Service info missing");
358+
unaccessibleServices.forEach(unSrv => {
359+
toolTipText += "<br>" + unSrv.key + ":" + unSrv.version;
360+
});
361+
this._blockCard(image, toolTipText);
362+
}
363+
});
350364
},
351365

352366
_applyState: function(state) {
353-
throw new Error("Abstract method called!");
367+
const locked = ("locked" in state) ? state["locked"]["value"] : false;
368+
this.setLocked(locked);
369+
if (locked) {
370+
this.__setLockedStatus(state["locked"]);
371+
}
372+
},
373+
374+
__setLockedStatus: function(lockedStatus) {
375+
const status = lockedStatus["status"];
376+
const owner = lockedStatus["owner"];
377+
let toolTip = osparc.utils.Utils.firstsUp(owner["first_name"], owner["last_name"]);
378+
let image = null;
379+
switch (status) {
380+
case "CLOSING":
381+
image = "@FontAwesome5Solid/key/";
382+
toolTip += this.tr(" is closing it...");
383+
break;
384+
case "CLONING":
385+
image = "@FontAwesome5Solid/clone/";
386+
toolTip += this.tr(" is cloning it...");
387+
break;
388+
case "EXPORTING":
389+
image = osparc.component.task.Export.EXPORT_ICON+"/";
390+
toolTip += this.tr(" is exporting it...");
391+
break;
392+
case "OPENING":
393+
image = "@FontAwesome5Solid/key/";
394+
toolTip += this.tr(" is opening it...");
395+
break;
396+
case "OPENED":
397+
image = "@FontAwesome5Solid/lock/";
398+
toolTip += this.tr(" is using it.");
399+
break;
400+
default:
401+
image = "@FontAwesome5Solid/lock/";
402+
break;
403+
}
404+
this._blockCard(image, toolTip);
405+
},
406+
407+
_blockCard: function(lockImageSrc, toolTipText) {
408+
const lockImage = this.getChildControl("lock-status").getChildControl("image");
409+
lockImageSrc += this.classname.includes("Grid") ? "70" : "24";
410+
lockImage.setSource(lockImageSrc);
411+
if (toolTipText) {
412+
this.set({
413+
toolTipText
414+
});
415+
}
416+
},
417+
418+
_applyLocked: function(locked) {
419+
this.__enableCard(!locked);
420+
this.getChildControl("lock-status").set({
421+
opacity: 1.0,
422+
visibility: locked ? "visible" : "excluded"
423+
});
424+
},
425+
426+
__enableCard: function(enabled) {
427+
this.set({
428+
cursor: enabled ? "pointer" : "not-allowed"
429+
});
430+
431+
this._getChildren().forEach(item => {
432+
item.setOpacity(enabled ? 1.0 : 0.4);
433+
});
434+
435+
[
436+
"tick-selected",
437+
"tick-unselected",
438+
"menu-button"
439+
].forEach(childName => {
440+
const child = this.getChildControl(childName);
441+
child.set({
442+
enabled
443+
});
444+
});
354445
},
355446

356447
_applyFetching: function(value) {
@@ -487,7 +578,7 @@ qx.Class.define("osparc.dashboard.CardBase", {
487578
}
488579
},
489580

490-
destruct : function() {
581+
destruct: function() {
491582
this.removeListener("pointerover", this._onPointerOver, this);
492583
this.removeListener("pointerout", this._onPointerOut, this);
493584
}

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

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -296,81 +296,6 @@ qx.Class.define("osparc.dashboard.GridButtonItem", {
296296
}
297297
},
298298

299-
_applyState: function(state) {
300-
const locked = ("locked" in state) ? state["locked"]["value"] : false;
301-
this.setLocked(locked);
302-
if (locked) {
303-
this.__setLockedStatus(state["locked"]);
304-
}
305-
},
306-
307-
__setLockedStatus: function(lockedStatus) {
308-
const status = lockedStatus["status"];
309-
const owner = lockedStatus["owner"];
310-
const lock = this.getChildControl("lock-status");
311-
const lockImage = this.getChildControl("lock-status").getChildControl("image");
312-
let toolTipText = osparc.utils.Utils.firstsUp(owner["first_name"], owner["last_name"]);
313-
let source = null;
314-
switch (status) {
315-
case "CLOSING":
316-
source = "@FontAwesome5Solid/key/70";
317-
toolTipText += this.tr(" is closing it...");
318-
break;
319-
case "CLONING":
320-
source = "@FontAwesome5Solid/clone/70";
321-
toolTipText += this.tr(" is cloning it...");
322-
break;
323-
case "EXPORTING":
324-
source = osparc.component.task.Export.EXPORT_ICON+"/70";
325-
toolTipText += this.tr(" is exporting it...");
326-
break;
327-
case "OPENING":
328-
source = "@FontAwesome5Solid/key/70";
329-
toolTipText += this.tr(" is opening it...");
330-
break;
331-
case "OPENED":
332-
source = "@FontAwesome5Solid/lock/70";
333-
toolTipText += this.tr(" is using it.");
334-
break;
335-
default:
336-
source = "@FontAwesome5Solid/lock/70";
337-
break;
338-
}
339-
lock.set({
340-
toolTipText: toolTipText
341-
});
342-
lockImage.setSource(source);
343-
},
344-
345-
_applyLocked: function(locked) {
346-
this.__enableCard(!locked);
347-
this.getChildControl("lock-status").set({
348-
opacity: 1.0,
349-
visibility: locked ? "visible" : "excluded"
350-
});
351-
},
352-
353-
__enableCard: function(enabled) {
354-
this.set({
355-
cursor: enabled ? "pointer" : "not-allowed"
356-
});
357-
358-
this._getChildren().forEach(item => {
359-
item.setOpacity(enabled ? 1.0 : 0.4);
360-
});
361-
362-
[
363-
"tick-selected",
364-
"tick-unselected",
365-
"menu-button"
366-
].forEach(childName => {
367-
const child = this.getChildControl(childName);
368-
child.set({
369-
enabled
370-
});
371-
});
372-
},
373-
374299
// overridden
375300
_applyMenu: function(value, old) {
376301
const menuButton = this.getChildControl("menu-button");

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

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -301,78 +301,6 @@ qx.Class.define("osparc.dashboard.ListButtonItem", {
301301
menuButton.setMenu(value);
302302
}
303303
menuButton.setVisibility(value ? "visible" : "excluded");
304-
},
305-
306-
_applyState: function(state) {
307-
const locked = ("locked" in state) ? state["locked"]["value"] : false;
308-
this.setLocked(locked);
309-
if (locked) {
310-
this.__setLockedStatus(state["locked"]);
311-
}
312-
},
313-
314-
__setLockedStatus: function(lockedStatus) {
315-
const status = lockedStatus["status"];
316-
const owner = lockedStatus["owner"];
317-
const lock = this.getChildControl("lock-status");
318-
const lockImage = this.getChildControl("lock-status").getChildControl("image");
319-
let toolTipText = osparc.utils.Utils.firstsUp(owner["first_name"], owner["last_name"]);
320-
let source = null;
321-
switch (status) {
322-
case "CLOSING":
323-
source = "@FontAwesome5Solid/key/24";
324-
toolTipText += this.tr(" is closing it...");
325-
break;
326-
case "CLONING":
327-
source = "@FontAwesome5Solid/clone/24";
328-
toolTipText += this.tr(" is cloning it...");
329-
break;
330-
case "EXPORTING":
331-
source = osparc.component.task.Export.EXPORT_ICON+"/24";
332-
toolTipText += this.tr(" is exporting it...");
333-
break;
334-
case "OPENING":
335-
source = "@FontAwesome5Solid/key/24";
336-
toolTipText += this.tr(" is opening it...");
337-
break;
338-
case "OPENED":
339-
source = "@FontAwesome5Solid/lock/24";
340-
toolTipText += this.tr(" is using it.");
341-
break;
342-
default:
343-
source = "@FontAwesome5Solid/lock/24";
344-
break;
345-
}
346-
lock.set({
347-
toolTipText: toolTipText
348-
});
349-
lockImage.setSource(source);
350-
},
351-
352-
_applyLocked: function(locked) {
353-
this.__enableCard(!locked);
354-
this.getChildControl("icon").set({
355-
visibility: locked ? "excluded" : "visible"
356-
});
357-
this.getChildControl("lock-status").set({
358-
opacity: 1.0,
359-
visibility: locked ? "visible" : "excluded"
360-
});
361-
},
362-
363-
__enableCard: function(enabled) {
364-
this.set({
365-
cursor: enabled ? "pointer" : "not-allowed"
366-
});
367-
368-
this._getChildren().forEach(item => {
369-
item.setOpacity(enabled ? 1.0 : 0.4);
370-
});
371304
}
372-
},
373-
374-
destruct : function() {
375-
this.removeListener("pointerover", this._onPointerOver, this);
376-
this.removeListener("pointerout", this._onPointerOut, this);
377305
}
378306
});

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,9 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
671671
},
672672

673673
nodeSelected: function(nodeId) {
674+
if (!this.isPropertyInitialized("study")) {
675+
return;
676+
}
674677
const study = this.getStudy();
675678
if (nodeId === null || nodeId === undefined) {
676679
nodeId = study.getUuid();

0 commit comments

Comments
 (0)