@@ -40,19 +40,18 @@ dispatcher_add(function(sammy) {
40
40
'node' , '' ) ;
41
41
} ) ;
42
42
43
- sammy . get ( '#/connections' , function ( ) {
43
+ if ( ac . canAccessVhosts ( ) ) {
44
+ sammy . get ( '#/connections' , function ( ) {
44
45
renderConnections ( ) ;
45
46
} ) ;
46
-
47
-
48
- sammy . get ( '#/connections/:name' , function ( ) {
47
+ sammy . get ( '#/connections/:name' , function ( ) {
49
48
var name = esc ( this . params [ 'name' ] ) ;
50
49
render ( { 'connection' : { path : '/connections/' + name ,
51
50
options : { ranges : [ 'data-rates-conn' ] } } ,
52
51
'channels' : '/connections/' + name + '/channels' } ,
53
52
'connection' , '#/connections' ) ;
54
53
} ) ;
55
- sammy . del ( '#/connections' , function ( ) {
54
+ sammy . del ( '#/connections' , function ( ) {
56
55
var options = { headers : {
57
56
'X-Reason' : this . params [ 'reason' ]
58
57
} } ;
@@ -62,51 +61,45 @@ dispatcher_add(function(sammy) {
62
61
63
62
return false ;
64
63
} ) ;
65
-
66
- sammy . get ( '#/channels' , function ( ) {
64
+ sammy . get ( '#/channels' , function ( ) {
67
65
renderChannels ( ) ;
68
66
} ) ;
69
-
70
- sammy . get ( '#/channels/:name' , function ( ) {
67
+ sammy . get ( '#/channels/:name' , function ( ) {
71
68
render ( { 'channel' : { path : '/channels/' + esc ( this . params [ 'name' ] ) ,
72
69
options :{ ranges :[ 'data-rates-ch' , 'msg-rates-ch' ] } } } ,
73
70
'channel' , '#/channels' ) ;
74
71
} ) ;
75
-
76
-
77
- sammy . get ( '#/exchanges' , function ( ) {
72
+ sammy . get ( '#/exchanges' , function ( ) {
78
73
renderExchanges ( ) ;
79
74
} ) ;
80
-
81
-
82
- sammy . get ( '#/exchanges/:vhost/:name' , function ( ) {
75
+ sammy . get ( '#/exchanges/:vhost/:name' , function ( ) {
83
76
var path = '/exchanges/' + esc ( this . params [ 'vhost' ] ) + '/' + esc ( this . params [ 'name' ] ) ;
84
77
render ( { 'exchange' : { path : path ,
85
78
options : { ranges :[ 'msg-rates-x' ] } } ,
86
79
'bindings_source' : path + '/bindings/source' ,
87
80
'bindings_destination' : path + '/bindings/destination' } ,
88
81
'exchange' , '#/exchanges' ) ;
89
82
} ) ;
90
- sammy . put ( '#/exchanges' , function ( ) {
83
+ sammy . put ( '#/exchanges' , function ( ) {
91
84
if ( sync_put ( this , '/exchanges/:vhost/:name' ) )
92
85
update ( ) ;
93
86
return false ;
94
87
} ) ;
95
- sammy . del ( '#/exchanges' , function ( ) {
88
+ sammy . del ( '#/exchanges' , function ( ) {
96
89
if ( sync_delete ( this , '/exchanges/:vhost/:name' ) )
97
90
go_to ( '#/exchanges' ) ;
98
91
return false ;
99
92
} ) ;
100
- sammy . post ( '#/exchanges/publish' , function ( ) {
93
+ sammy . post ( '#/exchanges/publish' , function ( ) {
101
94
publish_msg ( this . params ) ;
102
95
return false ;
103
96
} ) ;
104
97
105
- sammy . get ( '#/queues' , function ( ) {
98
+ sammy . get ( '#/queues' , function ( ) {
106
99
renderQueues ( ) ;
107
100
} ) ;
108
101
109
- sammy . get ( '#/queues/:vhost/:name' , function ( ) {
102
+ sammy . get ( '#/queues/:vhost/:name' , function ( ) {
110
103
var vhost = this . params [ 'vhost' ] ;
111
104
var queue = this . params [ 'name' ] ;
112
105
var path = '/queues/' + esc ( vhost ) + '/' + esc ( queue ) ;
@@ -124,12 +117,12 @@ dispatcher_add(function(sammy) {
124
117
}
125
118
render ( requests , 'queue' , '#/queues' ) ;
126
119
} ) ;
127
- sammy . put ( '#/queues' , function ( ) {
120
+ sammy . put ( '#/queues' , function ( ) {
128
121
if ( sync_put ( this , '/queues/:vhost/:name' ) )
129
122
update ( ) ;
130
123
return false ;
131
124
} ) ;
132
- sammy . del ( '#/queues' , function ( ) {
125
+ sammy . del ( '#/queues' , function ( ) {
133
126
if ( this . params [ 'mode' ] == 'delete' ) {
134
127
if ( sync_delete ( this , '/queues/:vhost/:name' ) )
135
128
go_to ( '#/queues' ) ;
@@ -142,32 +135,31 @@ dispatcher_add(function(sammy) {
142
135
}
143
136
return false ;
144
137
} ) ;
145
- sammy . post ( '#/queues/get' , function ( ) {
138
+ sammy . post ( '#/queues/get' , function ( ) {
146
139
get_msgs ( this . params ) ;
147
140
return false ;
148
141
} ) ;
149
- sammy . post ( '#/queues/actions' , function ( ) {
142
+ sammy . post ( '#/queues/actions' , function ( ) {
150
143
if ( sync_post ( this , '/queues/:vhost/:name/actions' ) )
151
144
// We can't refresh fast enough, it's racy. So grey
152
145
// the button and wait for a normal refresh.
153
146
$ ( '#action-button' ) . addClass ( 'wait' ) . prop ( 'disabled' , true ) ;
154
147
return false ;
155
148
} ) ;
156
- sammy . post ( '#/bindings' , function ( ) {
149
+ sammy . post ( '#/bindings' , function ( ) {
157
150
if ( sync_post ( this , '/bindings/:vhost/e/:source/:destination_type/:destination' ) )
158
151
update ( ) ;
159
152
return false ;
160
153
} ) ;
161
- sammy . del ( '#/bindings' , function ( ) {
154
+ sammy . del ( '#/bindings' , function ( ) {
162
155
if ( sync_delete ( this , '/bindings/:vhost/e/:source/:destination_type/:destination/:properties_key' ) )
163
156
update ( ) ;
164
157
return false ;
165
158
} ) ;
166
-
167
- path ( '#/vhosts' , { 'vhosts' : { path : '/vhosts' ,
159
+ path ( '#/vhosts' , { 'vhosts' : { path : '/vhosts' ,
168
160
options : { sort :true } } ,
169
161
'permissions' : '/permissions' } , 'vhosts' ) ;
170
- sammy . get ( '#/vhosts/:id' , function ( ) {
162
+ sammy . get ( '#/vhosts/:id' , function ( ) {
171
163
render ( { 'vhost' : { path : '/vhosts/' + esc ( this . params [ 'id' ] ) ,
172
164
options : { ranges : [ 'lengths-vhost' ,
173
165
'msg-rates-vhost' ,
@@ -178,26 +170,25 @@ dispatcher_add(function(sammy) {
178
170
'exchanges' : '/exchanges/' + esc ( this . params [ 'id' ] ) } ,
179
171
'vhost' , '#/vhosts' ) ;
180
172
} ) ;
181
-
182
- sammy . put ( '#/vhosts' , function ( ) {
173
+ sammy . put ( '#/vhosts' , function ( ) {
183
174
if ( sync_put ( this , '/vhosts/:name' ) ) {
184
175
update_vhosts ( ) ;
185
176
update ( ) ;
186
177
}
187
178
return false ;
188
179
} ) ;
189
- sammy . del ( '#/vhosts' , function ( ) {
180
+ sammy . del ( '#/vhosts' , function ( ) {
190
181
if ( sync_delete ( this , '/vhosts/:name' ) ) {
191
182
update_vhosts ( ) ;
192
183
go_to ( '#/vhosts' ) ;
193
184
}
194
185
return false ;
195
186
} ) ;
196
187
197
- sammy . get ( '#/users' , function ( ) {
188
+ sammy . get ( '#/users' , function ( ) {
198
189
renderUsers ( ) ;
199
- } ) ;
200
- sammy . get ( '#/users/:id' , function ( ) {
190
+ } ) ;
191
+ sammy . get ( '#/users/:id' , function ( ) {
201
192
var vhosts = JSON . parse ( sync_get ( '/vhosts' ) ) ;
202
193
const current_vhost = get_pref ( 'vhost' ) ;
203
194
var index_vhost = 0 ;
@@ -213,8 +204,8 @@ dispatcher_add(function(sammy) {
213
204
'vhosts' : '/vhosts/' ,
214
205
'exchanges' : '/exchanges/' + esc ( vhosts [ index_vhost ] . name ) } ,
215
206
'user' , '#/users' ) ;
216
- } ) ;
217
- sammy . put ( '#/users-add' , function ( ) {
207
+ } ) ;
208
+ sammy . put ( '#/users-add' , function ( ) {
218
209
res = sync_put ( this , '/users/:username' ) ;
219
210
if ( res ) {
220
211
if ( res . http_status === 204 ) {
@@ -225,75 +216,120 @@ dispatcher_add(function(sammy) {
225
216
}
226
217
return false ;
227
218
} ) ;
228
- sammy . put ( '#/users-modify' , function ( ) {
219
+ sammy . put ( '#/users-modify' , function ( ) {
229
220
if ( sync_put ( this , '/users/:username' ) )
230
221
go_to ( '#/users' ) ;
231
222
return false ;
232
223
} ) ;
233
- sammy . del ( '#/users' , function ( ) {
224
+ sammy . del ( '#/users' , function ( ) {
234
225
if ( sync_delete ( this , '/users/:username' ) )
235
226
go_to ( '#/users' ) ;
236
227
return false ;
237
228
} ) ;
238
-
239
- path ( '#/feature-flags' , { 'feature_flags' : { path : '/feature-flags' ,
240
- options : { sort :true } } ,
241
- 'permissions' : '/permissions' } , 'feature-flags' ) ;
242
- sammy . put ( '#/feature-flags-enable' , function ( ) {
243
- if ( sync_put ( this , '/feature-flags/:name/enable' ) )
244
- update ( ) ;
245
- return false ;
246
- } ) ;
247
-
248
- sammy . put ( '#/permissions' , function ( ) {
229
+ sammy . put ( '#/permissions' , function ( ) {
249
230
if ( sync_put ( this , '/permissions/:vhost/:username' ) )
250
231
update ( ) ;
251
232
return false ;
252
233
} ) ;
253
- sammy . del ( '#/permissions' , function ( ) {
234
+ sammy . del ( '#/permissions' , function ( ) {
254
235
if ( sync_delete ( this , '/permissions/:vhost/:username' ) )
255
236
update ( ) ;
256
237
return false ;
257
238
} ) ;
258
- sammy . put ( '#/topic-permissions' , function ( ) {
239
+ sammy . put ( '#/topic-permissions' , function ( ) {
259
240
if ( sync_put ( this , '/topic-permissions/:vhost/:username' ) )
260
241
update ( ) ;
261
242
return false ;
262
243
} ) ;
263
- sammy . del ( '#/topic-permissions' , function ( ) {
244
+ sammy . del ( '#/topic-permissions' , function ( ) {
264
245
if ( sync_delete ( this , '/topic-permissions/:vhost/:username/:exchange' ) )
265
246
update ( ) ;
266
247
return false ;
267
248
} ) ;
268
- path ( '#/policies' , { 'policies' : '/policies' ,
249
+ path ( '#/policies' , { 'policies' : '/policies' ,
269
250
'operator_policies' : '/operator-policies' ,
270
251
'vhosts' : '/vhosts' } , 'policies' ) ;
271
- sammy . get ( '#/policies/:vhost/:id' , function ( ) {
252
+ sammy . get ( '#/policies/:vhost/:id' , function ( ) {
272
253
render ( { 'policy' : '/policies/' + esc ( this . params [ 'vhost' ] )
273
254
+ '/' + esc ( this . params [ 'id' ] ) } ,
274
255
'policy' , '#/policies' ) ;
275
256
} ) ;
276
- sammy . put ( '#/policies' , function ( ) {
257
+ sammy . put ( '#/policies' , function ( ) {
277
258
put_cast_params ( this , '/policies/:vhost/:name' ,
278
259
[ 'name' , 'pattern' , 'policy' ] , [ 'priority' ] , [ ] ) ;
279
260
return false ;
280
261
} ) ;
281
- sammy . del ( '#/policies' , function ( ) {
262
+ sammy . del ( '#/policies' , function ( ) {
282
263
if ( sync_delete ( this , '/policies/:vhost/:name' ) )
283
264
go_to ( '#/policies' ) ;
284
265
return false ;
285
266
} ) ;
286
- sammy . put ( '#/operator_policies' , function ( ) {
267
+ sammy . put ( '#/operator_policies' , function ( ) {
287
268
this . params = rename_multifield ( this . params , "definitionop" , "definition" ) ;
288
269
put_cast_params ( this , '/operator-policies/:vhost/:name' ,
289
270
[ 'name' , 'pattern' , 'policy' ] , [ 'priority' ] , [ ] ) ;
290
271
return false ;
291
272
} ) ;
292
- sammy . del ( '#/operator_policies' , function ( ) {
273
+ sammy . del ( '#/operator_policies' , function ( ) {
293
274
if ( sync_delete ( this , '/operator-policies/:vhost/:name' ) )
294
275
update ( ) ;
295
276
} ) ;
277
+ let datamodel = {
278
+ 'limits' : '/vhost-limits' ,
279
+ 'user_limits' : '/user-limits' ,
280
+ 'vhosts' : '/vhosts'
281
+ }
282
+ if ( ac . isAdministratorUser ( ) ) {
283
+ datamodel [ 'users' ] = '/users'
284
+ }
285
+ path ( '#/limits' , datamodel , 'limits' ) ;
296
286
287
+ sammy . put ( '#/limits' , function ( ) {
288
+ var valAsInt = parseInt ( this . params . value ) ;
289
+ if ( isNaN ( valAsInt ) ) {
290
+ var e = 'Validation failed\n\n' +
291
+ this . params . name + ' should be a number, actually was "' +
292
+ this . params . value + '"' ;
293
+ show_popup ( 'warn' , fmt_escape_html ( e ) ) ;
294
+ } else {
295
+ this . params . value = valAsInt ;
296
+ if ( sync_put ( this , '/vhost-limits/:vhost/:name' ) ) {
297
+ update ( ) ;
298
+ }
299
+ }
300
+ } )
301
+ sammy . put ( '#/user-limits' , function ( ) {
302
+ var valAsInt = parseInt ( this . params . value ) ;
303
+ if ( isNaN ( valAsInt ) ) {
304
+ var e = 'Validation failed\n\n' +
305
+ this . params . name + ' should be a number, actually was "' +
306
+ this . params . value + '"' ;
307
+ show_popup ( 'warn' , fmt_escape_html ( e ) ) ;
308
+ } else {
309
+ this . params . value = valAsInt ;
310
+ if ( sync_put ( this , '/user-limits/:user/:name' ) ) {
311
+ update ( ) ;
312
+ }
313
+ }
314
+ } )
315
+ sammy . post ( '#/restart_vhost' , function ( ) {
316
+ if ( sync_post ( this , '/vhosts/:vhost/start/:node' ) ) update ( ) ;
317
+ } )
318
+ sammy . del ( '#/limits' , function ( ) {
319
+ if ( sync_delete ( this , '/vhost-limits/:vhost/:name' ) ) update ( ) ;
320
+ } )
321
+ sammy . del ( '#/user-limits' , function ( ) {
322
+ if ( sync_delete ( this , '/user-limits/:user/:name' ) ) update ( ) ;
323
+ } )
324
+ }
325
+ path ( '#/feature-flags' , { 'feature_flags' : { path : '/feature-flags' ,
326
+ options : { sort :true } } ,
327
+ 'permissions' : '/permissions' } , 'feature-flags' ) ;
328
+ sammy . put ( '#/feature-flags-enable' , function ( ) {
329
+ if ( sync_put ( this , '/feature-flags/:name/enable' ) )
330
+ update ( ) ;
331
+ return false ;
332
+ } ) ;
297
333
sammy . put ( '#/logout' , function ( ) {
298
334
// clear a local storage value used by earlier versions
299
335
clear_auth ( )
@@ -312,48 +348,7 @@ dispatcher_add(function(sammy) {
312
348
sammy . put ( '#/column-options' , function ( ) {
313
349
update_column_options ( this ) ;
314
350
} ) ;
315
- path ( '#/limits' , { 'limits' : '/vhost-limits' ,
316
- 'user_limits' : '/user-limits' ,
317
- 'users' : '/users' ,
318
- 'vhosts' : '/vhosts' } , 'limits' ) ;
319
351
320
- sammy . put ( '#/limits' , function ( ) {
321
- var valAsInt = parseInt ( this . params . value ) ;
322
- if ( isNaN ( valAsInt ) ) {
323
- var e = 'Validation failed\n\n' +
324
- this . params . name + ' should be a number, actually was "' +
325
- this . params . value + '"' ;
326
- show_popup ( 'warn' , fmt_escape_html ( e ) ) ;
327
- } else {
328
- this . params . value = valAsInt ;
329
- if ( sync_put ( this , '/vhost-limits/:vhost/:name' ) ) {
330
- update ( ) ;
331
- }
332
- }
333
- } ) ;
334
- sammy . put ( '#/user-limits' , function ( ) {
335
- var valAsInt = parseInt ( this . params . value ) ;
336
- if ( isNaN ( valAsInt ) ) {
337
- var e = 'Validation failed\n\n' +
338
- this . params . name + ' should be a number, actually was "' +
339
- this . params . value + '"' ;
340
- show_popup ( 'warn' , fmt_escape_html ( e ) ) ;
341
- } else {
342
- this . params . value = valAsInt ;
343
- if ( sync_put ( this , '/user-limits/:user/:name' ) ) {
344
- update ( ) ;
345
- }
346
- }
347
- } ) ;
348
- sammy . post ( '#/restart_vhost' , function ( ) {
349
- if ( sync_post ( this , '/vhosts/:vhost/start/:node' ) ) update ( ) ;
350
- } )
351
- sammy . del ( '#/limits' , function ( ) {
352
- if ( sync_delete ( this , '/vhost-limits/:vhost/:name' ) ) update ( ) ;
353
- } ) ;
354
- sammy . del ( '#/user-limits' , function ( ) {
355
- if ( sync_delete ( this , '/user-limits/:user/:name' ) ) update ( ) ;
356
- } ) ;
357
352
sammy . del ( "#/reset" , function ( ) {
358
353
if ( sync_delete ( this , '/reset' ) ) {
359
354
update ( ) ;
0 commit comments