24
24
*/
25
25
26
26
qx . Class . define ( "osparc.desktop.preferences.pages.SecurityPage" , {
27
- extend :osparc . desktop . preferences . pages . BasePage ,
27
+ extend : osparc . desktop . preferences . pages . BasePage ,
28
28
29
- construct : function ( ) {
29
+ construct : function ( ) {
30
30
const iconSrc = "@FontAwesome5Solid/shield-alt/24" ;
31
31
const title = this . tr ( "Security" ) ;
32
32
this . base ( arguments , title , iconSrc ) ;
33
33
34
34
this . add ( this . __createPasswordSection ( ) ) ;
35
- this . add ( this . __createTokensSection ( ) ) ;
35
+ this . add ( this . __createInternalTokensSection ( ) ) ;
36
+ this . add ( this . __createExternalTokensSection ( ) ) ;
37
+
38
+ this . __rebuildTokensList ( ) ;
36
39
} ,
37
40
38
41
members : {
39
- __tokensList : null ,
42
+ __internalTokensList : null ,
43
+ __externalTokensList : null ,
40
44
41
- __createTokensSection : function ( ) {
45
+ __createInternalTokensSection : function ( ) {
42
46
// 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" ) ) ;
44
103
45
104
const label = this . _createHelpLabel ( this . tr (
46
105
"List of API tokens to access external services. Currently, \
47
106
only DAT-Core API keys are supported."
48
107
) ) ;
49
108
box . add ( label ) ;
50
109
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" ) ;
52
111
box . add ( linkBtn ) ;
53
112
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 ) ) ;
55
114
box . add ( tokensList ) ;
56
- this . __rebuildTokensList ( ) ;
57
115
58
116
return box ;
59
117
} ,
60
118
61
- __rebuildTokensList : function ( ) {
62
- this . __tokensList . removeAll ( ) ;
119
+ __rebuildTokensList : function ( ) {
120
+ this . __internalTokensList . removeAll ( ) ;
121
+ this . __externalTokensList . removeAll ( ) ;
63
122
osparc . data . Resources . get ( "tokens" )
64
123
. then ( tokensList => {
65
124
if ( tokensList . length ) {
66
- for ( let i = 0 ; i < tokensList . length ; i ++ ) {
125
+ for ( let i = 0 ; i < tokensList . length ; i ++ ) {
67
126
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
+ }
69
132
}
70
133
} else {
71
134
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 ) ) ;
73
136
}
74
137
} )
75
138
. catch ( err => console . error ( err ) ) ;
76
139
} ,
77
140
78
- __createEmptyTokenForm : function ( ) {
79
- let form = new qx . ui . form . Form ( ) ;
141
+ __createEmptyTokenForm : function ( ) {
142
+ const form = new qx . ui . form . Form ( ) ;
80
143
81
144
// 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 ( ) ;
83
146
newTokenService . set ( {
84
147
value : "blackfynn-datcore" ,
85
148
readOnly : true
86
149
} ) ;
87
150
form . add ( newTokenService , this . tr ( "Service" ) ) ;
88
151
89
- // TODO:
90
- let newTokenKey = new qx . ui . form . TextField ( ) ;
152
+ const newTokenKey = new qx . ui . form . TextField ( ) ;
91
153
newTokenKey . set ( {
92
154
placeholder : this . tr ( "Introduce token key here" )
93
155
} ) ;
94
156
form . add ( newTokenKey , this . tr ( "Key" ) ) ;
95
157
96
- let newTokenSecret = new qx . ui . form . TextField ( ) ;
158
+ const newTokenSecret = new qx . ui . form . TextField ( ) ;
97
159
newTokenSecret . set ( {
98
160
placeholder : this . tr ( "Introduce token secret here" )
99
161
} ) ;
100
162
form . add ( newTokenSecret , this . tr ( "Secret" ) ) ;
101
163
102
- let addTokenBtn = new qx . ui . form . Button ( this . tr ( "Add" ) ) ;
164
+ const addTokenBtn = new qx . ui . form . Button ( this . tr ( "Add" ) ) ;
103
165
addTokenBtn . setWidth ( 100 ) ;
104
166
addTokenBtn . addListener ( "execute" , e => {
105
167
if ( ! osparc . data . Permissions . getInstance ( ) . canDo ( "preferences.token.create" , true ) ) {
@@ -121,49 +183,32 @@ qx.Class.define("osparc.desktop.preferences.pages.SecurityPage", {
121
183
return form ;
122
184
} ,
123
185
124
- __createValidTokenForm : function ( token ) {
186
+ __createValidTokenForm : function ( token ) {
187
+ const label = token [ "keyLabel" ] || token [ "service" ] ;
125
188
const service = token [ "service" ] ;
126
189
127
190
const height = 20 ;
128
- const iconHeight = height - 6 ;
191
+ const iconHeight = height - 6 ;
129
192
const gr = new qx . ui . layout . Grid ( 10 , 3 ) ;
130
193
gr . setColumnFlex ( 1 , 1 ) ;
131
194
gr . setRowHeight ( 0 , height ) ;
132
195
gr . setRowHeight ( 1 , height ) ;
133
196
gr . setRowHeight ( 2 , height ) ;
134
197
const grid = new qx . ui . container . Composite ( gr ) ;
135
198
136
- const nameLabel = new qx . ui . basic . Label ( this . tr ( "Token name" ) ) ;
199
+ const nameLabel = new qx . ui . basic . Label ( service ) ;
137
200
grid . add ( nameLabel , {
138
201
row : 0 ,
139
202
column : 0
140
203
} ) ;
141
204
142
- const nameVal = new qx . ui . basic . Label ( service ) ;
205
+ const nameVal = new qx . ui . basic . Label ( label ) ;
143
206
grid . add ( nameVal , {
144
207
row : 0 ,
145
208
column : 1
146
209
} ) ;
147
210
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 ) ;
167
212
delTokenBtn . addListener ( "execute" , e => {
168
213
if ( ! osparc . data . Permissions . getInstance ( ) . canDo ( "preferences.token.delete" , true ) ) {
169
214
return ;
@@ -185,34 +230,34 @@ qx.Class.define("osparc.desktop.preferences.pages.SecurityPage", {
185
230
return grid ;
186
231
} ,
187
232
188
- __createPasswordSection : function ( ) {
233
+ __createPasswordSection : function ( ) {
189
234
// layout
190
- let box = this . _createSectionBox ( this . tr ( "Password" ) ) ;
235
+ const box = this . _createSectionBox ( this . tr ( "Password" ) ) ;
191
236
192
- let currentPassword = new qx . ui . form . PasswordField ( ) . set ( {
237
+ const currentPassword = new qx . ui . form . PasswordField ( ) . set ( {
193
238
required : true ,
194
239
placeholder : this . tr ( "Your current password" )
195
240
} ) ;
196
241
box . add ( currentPassword ) ;
197
242
198
- let newPassword = new qx . ui . form . PasswordField ( ) . set ( {
243
+ const newPassword = new qx . ui . form . PasswordField ( ) . set ( {
199
244
required : true ,
200
245
placeholder : this . tr ( "Your new password" )
201
246
} ) ;
202
247
box . add ( newPassword ) ;
203
248
204
- let confirm = new qx . ui . form . PasswordField ( ) . set ( {
249
+ const confirm = new qx . ui . form . PasswordField ( ) . set ( {
205
250
required : true ,
206
251
placeholder : this . tr ( "Retype your new password" )
207
252
} ) ;
208
253
box . add ( confirm ) ;
209
254
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 ) {
212
257
return osparc . auth . core . Utils . checkSamePasswords ( newPassword , confirm ) ;
213
258
} ) ;
214
259
215
- let resetBtn = new qx . ui . form . Button ( "Reset Password" ) . set ( {
260
+ const resetBtn = new qx . ui . form . Button ( "Reset Password" ) . set ( {
216
261
allowGrowX : false
217
262
} ) ;
218
263
box . add ( resetBtn ) ;
0 commit comments