Skip to content

Commit c8626ef

Browse files
committed
1 parent 162e315 commit c8626ef

File tree

4 files changed

+284
-52
lines changed

4 files changed

+284
-52
lines changed

services/web/client/source/class/osparc/desktop/preferences/pages/SecurityPage.js

+97-52
Original file line numberDiff line numberDiff line change
@@ -24,82 +24,144 @@
2424
*/
2525

2626
qx.Class.define("osparc.desktop.preferences.pages.SecurityPage", {
27-
extend:osparc.desktop.preferences.pages.BasePage,
27+
extend: osparc.desktop.preferences.pages.BasePage,
2828

29-
construct: function() {
29+
construct: function () {
3030
const iconSrc = "@FontAwesome5Solid/shield-alt/24";
3131
const title = this.tr("Security");
3232
this.base(arguments, title, iconSrc);
3333

3434
this.add(this.__createPasswordSection());
35-
this.add(this.__createTokensSection());
35+
this.add(this.__createInternalTokensSection());
36+
this.add(this.__createExternalTokensSection());
37+
38+
this.__rebuildTokensList();
3639
},
3740

3841
members: {
39-
__tokensList: null,
42+
__internalTokensList: null,
43+
__externalTokensList: null,
4044

41-
__createTokensSection: function() {
45+
__createInternalTokensSection: function () {
4246
// layout
43-
const box = this._createSectionBox(this.tr("Access Tokens"));
47+
const box = this._createSectionBox(this.tr("oSPARC API Tokens"));
48+
49+
const label = this._createHelpLabel(this.tr(
50+
"Tokens to access oSPARC API."
51+
));
52+
box.add(label);
53+
54+
const tokensList = this.__internalTokensList = new qx.ui.container.Composite(new qx.ui.layout.VBox(8));
55+
box.add(tokensList);
56+
57+
const requestTokenBtn = this.__requestTokenBtn = new osparc.ui.form.FetchButton(this.tr("Create oSPARC Token")).set({
58+
allowGrowX: false
59+
});
60+
requestTokenBtn.addListener("execute", () => {
61+
this.__requestOsparcToken();
62+
}, this);
63+
box.add(requestTokenBtn);
64+
65+
return box;
66+
},
67+
68+
__requestOsparcToken: function () {
69+
if (!osparc.data.Permissions.getInstance().canDo("preferences.token.create", true)) {
70+
return;
71+
}
72+
73+
const createAPIKeyWindow = new osparc.desktop.preferences.window.CreateAPIKey("hello", "world");
74+
createAPIKeyWindow.addListener("finished", keyLabel => {
75+
const params = {
76+
data: {
77+
"service": "osparc",
78+
"keyLabel": keyLabel.getData()
79+
}
80+
};
81+
createAPIKeyWindow.close();
82+
this.__requestTokenBtn.setFetching(true);
83+
osparc.data.Resources.fetch("tokens", "post", params)
84+
.then(data => {
85+
this.__rebuildTokensList();
86+
const showAPIKeyWindow = new osparc.desktop.preferences.window.ShowAPIKey("hello", "world");
87+
showAPIKeyWindow.center();
88+
showAPIKeyWindow.open();
89+
console.log(data);
90+
})
91+
.catch(err => {
92+
osparc.component.message.FlashMessenger.getInstance().logAs(this.tr("Failed creating oSPARC API token"), "ERROR");
93+
console.error(err);
94+
})
95+
.finally(() => this.__requestTokenBtn.setFetching(false));
96+
}, this);
97+
createAPIKeyWindow.open();
98+
},
99+
100+
__createExternalTokensSection: function () {
101+
// layout
102+
const box = this._createSectionBox(this.tr("External service Tokens"));
44103

45104
const label = this._createHelpLabel(this.tr(
46105
"List of API tokens to access external services. Currently, \
47106
only DAT-Core API keys are supported."
48107
));
49108
box.add(label);
50109

51-
let linkBtn = new osparc.ui.form.LinkButton(this.tr("To DAT-Core"), "https://app.blackfynn.io");
110+
const linkBtn = new osparc.ui.form.LinkButton(this.tr("To DAT-Core"), "https://app.blackfynn.io");
52111
box.add(linkBtn);
53112

54-
const tokensList = this.__tokensList = new qx.ui.container.Composite(new qx.ui.layout.VBox(8));
113+
const tokensList = this.__externalTokensList = new qx.ui.container.Composite(new qx.ui.layout.VBox(8));
55114
box.add(tokensList);
56-
this.__rebuildTokensList();
57115

58116
return box;
59117
},
60118

61-
__rebuildTokensList: function() {
62-
this.__tokensList.removeAll();
119+
__rebuildTokensList: function () {
120+
this.__internalTokensList.removeAll();
121+
this.__externalTokensList.removeAll();
63122
osparc.data.Resources.get("tokens")
64123
.then(tokensList => {
65124
if (tokensList.length) {
66-
for (let i=0; i<tokensList.length; i++) {
125+
for (let i = 0; i < tokensList.length; i++) {
67126
const tokenForm = this.__createValidTokenForm(tokensList[i]);
68-
this.__tokensList.add(tokenForm);
127+
if (tokensList[i].service === "osparc") {
128+
this.__internalTokensList.add(tokenForm);
129+
} else {
130+
this.__externalTokensList.add(tokenForm);
131+
}
69132
}
70133
} else {
71134
const emptyForm = this.__createEmptyTokenForm();
72-
this.__tokensList.add(new qx.ui.form.renderer.Single(emptyForm));
135+
this.__externalTokensList.add(new qx.ui.form.renderer.Single(emptyForm));
73136
}
74137
})
75138
.catch(err => console.error(err));
76139
},
77140

78-
__createEmptyTokenForm: function() {
79-
let form = new qx.ui.form.Form();
141+
__createEmptyTokenForm: function () {
142+
const form = new qx.ui.form.Form();
80143

81144
// FIXME: for the moment this is fixed since it has to be a unique id
82-
let newTokenService = new qx.ui.form.TextField();
145+
const newTokenService = new qx.ui.form.TextField();
83146
newTokenService.set({
84147
value: "blackfynn-datcore",
85148
readOnly: true
86149
});
87150
form.add(newTokenService, this.tr("Service"));
88151

89-
// TODO:
90-
let newTokenKey = new qx.ui.form.TextField();
152+
const newTokenKey = new qx.ui.form.TextField();
91153
newTokenKey.set({
92154
placeholder: this.tr("Introduce token key here")
93155
});
94156
form.add(newTokenKey, this.tr("Key"));
95157

96-
let newTokenSecret = new qx.ui.form.TextField();
158+
const newTokenSecret = new qx.ui.form.TextField();
97159
newTokenSecret.set({
98160
placeholder: this.tr("Introduce token secret here")
99161
});
100162
form.add(newTokenSecret, this.tr("Secret"));
101163

102-
let addTokenBtn = new qx.ui.form.Button(this.tr("Add"));
164+
const addTokenBtn = new qx.ui.form.Button(this.tr("Add"));
103165
addTokenBtn.setWidth(100);
104166
addTokenBtn.addListener("execute", e => {
105167
if (!osparc.data.Permissions.getInstance().canDo("preferences.token.create", true)) {
@@ -121,49 +183,32 @@ qx.Class.define("osparc.desktop.preferences.pages.SecurityPage", {
121183
return form;
122184
},
123185

124-
__createValidTokenForm: function(token) {
186+
__createValidTokenForm: function (token) {
187+
const label = token["keyLabel"] || token["service"];
125188
const service = token["service"];
126189

127190
const height = 20;
128-
const iconHeight = height-6;
191+
const iconHeight = height - 6;
129192
const gr = new qx.ui.layout.Grid(10, 3);
130193
gr.setColumnFlex(1, 1);
131194
gr.setRowHeight(0, height);
132195
gr.setRowHeight(1, height);
133196
gr.setRowHeight(2, height);
134197
const grid = new qx.ui.container.Composite(gr);
135198

136-
const nameLabel = new qx.ui.basic.Label(this.tr("Token name"));
199+
const nameLabel = new qx.ui.basic.Label(service);
137200
grid.add(nameLabel, {
138201
row: 0,
139202
column: 0
140203
});
141204

142-
const nameVal = new qx.ui.basic.Label(service);
205+
const nameVal = new qx.ui.basic.Label(label);
143206
grid.add(nameVal, {
144207
row: 0,
145208
column: 1
146209
});
147210

148-
/*
149-
const showTokenIcon = "@FontAwesome5Solid/edit/"+iconHeight;
150-
const showTokenBtn = new qx.ui.form.Button(null, showTokenIcon);
151-
showTokenBtn.addListener("execute", e => {
152-
const treeItemRenamer = new osparc.component.widget.Renamer(nameVal.getValue());
153-
treeItemRenamer.addListener("labelChanged", ev => {
154-
const newLabel = ev.getData()["newLabel"];
155-
nameVal.setValue(newLabel);
156-
}, this);
157-
treeItemRenamer.center();
158-
treeItemRenamer.open();
159-
}, this);
160-
grid.add(showTokenBtn, {
161-
row: 0,
162-
column: 2
163-
});
164-
*/
165-
166-
const delTokenBtn = new qx.ui.form.Button(null, "@FontAwesome5Solid/trash-alt/"+iconHeight);
211+
const delTokenBtn = new qx.ui.form.Button(null, "@FontAwesome5Solid/trash-alt/" + iconHeight);
167212
delTokenBtn.addListener("execute", e => {
168213
if (!osparc.data.Permissions.getInstance().canDo("preferences.token.delete", true)) {
169214
return;
@@ -185,34 +230,34 @@ qx.Class.define("osparc.desktop.preferences.pages.SecurityPage", {
185230
return grid;
186231
},
187232

188-
__createPasswordSection: function() {
233+
__createPasswordSection: function () {
189234
// layout
190-
let box = this._createSectionBox(this.tr("Password"));
235+
const box = this._createSectionBox(this.tr("Password"));
191236

192-
let currentPassword = new qx.ui.form.PasswordField().set({
237+
const currentPassword = new qx.ui.form.PasswordField().set({
193238
required: true,
194239
placeholder: this.tr("Your current password")
195240
});
196241
box.add(currentPassword);
197242

198-
let newPassword = new qx.ui.form.PasswordField().set({
243+
const newPassword = new qx.ui.form.PasswordField().set({
199244
required: true,
200245
placeholder: this.tr("Your new password")
201246
});
202247
box.add(newPassword);
203248

204-
let confirm = new qx.ui.form.PasswordField().set({
249+
const confirm = new qx.ui.form.PasswordField().set({
205250
required: true,
206251
placeholder: this.tr("Retype your new password")
207252
});
208253
box.add(confirm);
209254

210-
let manager = new qx.ui.form.validation.Manager();
211-
manager.setValidator(function(_itemForms) {
255+
const manager = new qx.ui.form.validation.Manager();
256+
manager.setValidator(function (_itemForms) {
212257
return osparc.auth.core.Utils.checkSamePasswords(newPassword, confirm);
213258
});
214259

215-
let resetBtn = new qx.ui.form.Button("Reset Password").set({
260+
const resetBtn = new qx.ui.form.Button("Reset Password").set({
216261
allowGrowX: false
217262
});
218263
box.add(resetBtn);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* ************************************************************************
2+
osparc - the simcore frontend
3+
https://osparc.io
4+
Copyright:
5+
2020 IT'IS Foundation, https://itis.swiss
6+
License:
7+
MIT: https://opensource.org/licenses/MIT
8+
Authors:
9+
* Odei Maiz (odeimaiz)
10+
************************************************************************ */
11+
12+
/**
13+
*
14+
*/
15+
16+
qx.Class.define("osparc.desktop.preferences.window.APIKeyBase", {
17+
extend: qx.ui.window.Window,
18+
type: "abstract",
19+
20+
construct: function (caption, infoText) {
21+
this.base(arguments, caption);
22+
23+
this.set({
24+
layout: new qx.ui.layout.VBox(5),
25+
autoDestroy: true,
26+
modal: true,
27+
showMaximize: false,
28+
showMinimize: false,
29+
width: 350
30+
});
31+
32+
this.__addInfoText(infoText);
33+
34+
this.center();
35+
},
36+
37+
members: {
38+
__addInfoText: function (infoText) {
39+
const introLabel = new qx.ui.basic.Label(infoText).set({
40+
padding: 5,
41+
rich: true
42+
});
43+
this._add(introLabel);
44+
}
45+
}
46+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* ************************************************************************
2+
osparc - the simcore frontend
3+
https://osparc.io
4+
Copyright:
5+
2020 IT'IS Foundation, https://itis.swiss
6+
License:
7+
MIT: https://opensource.org/licenses/MIT
8+
Authors:
9+
* Odei Maiz (odeimaiz)
10+
************************************************************************ */
11+
12+
/**
13+
*
14+
*/
15+
16+
qx.Class.define("osparc.desktop.preferences.window.CreateAPIKey", {
17+
extend: osparc.desktop.preferences.window.APIKeyBase,
18+
19+
construct: function () {
20+
const caption = this.tr("Create oSPARC API Key");
21+
const infoText = this.tr("Key names must be unique.");
22+
this.base(arguments, caption, infoText);
23+
24+
this.__populateWindow();
25+
},
26+
27+
events: {
28+
"finished": "qx.event.type.Data"
29+
},
30+
31+
members: {
32+
__populateWindow: function () {
33+
const hBox1 = new qx.ui.container.Composite(new qx.ui.layout.HBox(10)).set({
34+
padding: 5
35+
});
36+
const sTitle = new qx.ui.basic.Label(this.tr("API Key")).set({
37+
width: 50,
38+
alignY: "middle"
39+
});
40+
hBox1.add(sTitle);
41+
const labelEditor = new qx.ui.form.TextField();
42+
this.add(labelEditor, {
43+
flex: 1
44+
});
45+
hBox1.add(labelEditor, {
46+
flex: 1
47+
});
48+
this._add(hBox1);
49+
50+
const hBox2 = new qx.ui.container.Composite(new qx.ui.layout.HBox(10)).set({
51+
padding: 5
52+
});
53+
hBox2.add(new qx.ui.core.Spacer(), {
54+
flex: 1
55+
});
56+
const confirmBtn = new qx.ui.form.Button(this.tr("Confirm"));
57+
confirmBtn.addListener("execute", e => {
58+
const keyLabel = labelEditor.getValue();
59+
this.fireDataEvent("finished", keyLabel);
60+
}, this);
61+
hBox2.add(confirmBtn);
62+
63+
this._add(hBox2);
64+
}
65+
}
66+
});

0 commit comments

Comments
 (0)