Skip to content

Commit 02fda91

Browse files
Fix #8276
1 parent f82a3f2 commit 02fda91

File tree

3 files changed

+44
-26
lines changed

3 files changed

+44
-26
lines changed

deps/rabbitmq_management/priv/www/js/global.js

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ var exchange_types;
640640
// Used for access control
641641
var user_tags;
642642
var user;
643-
var ac;
644-
var display;
643+
var ac = new AccessControl();
644+
var display = new DisplayControl();
645645

646646
var ui_data_model = {
647647
vhosts: [],
@@ -651,42 +651,60 @@ var ui_data_model = {
651651

652652
// Access control
653653

654-
function AccessControl(user, ui_data_model) {
655-
this.user = user;
656-
this.user_tags = expand_user_tags(user.tags);
657-
this.ui_data_model = ui_data_model;
654+
function AccessControl() {
658655

656+
this.update = function(user, ui_data_model) {
657+
this.user = user;
658+
this.user_tags = expand_user_tags(user.tags);
659+
this.ui_data_model = ui_data_model;
660+
};
659661
this.isMonitoringUser = function() {
660-
return this.user_tags.includes("monitoring");
662+
if (this.user_tags)
663+
return this.user_tags.includes("monitoring");
664+
else return false;
661665
};
662666
this.isAdministratorUser = function() {
663-
return this.user_tags.includes("administrator");
667+
if (this.user_tags)
668+
return this.user_tags.includes("administrator");
669+
else return false;
664670
};
665671
this.isPolicyMakerUser = function() {
666-
return this.user_tags.includes("policymaker");
672+
if (this.user_tags)
673+
return this.user_tags.includes("policymaker");
674+
else return false;
667675
};
668676
this.canAccessVhosts = function() {
669-
return this.ui_data_model.vhosts.length > 0;
677+
if (this.ui_data_model)
678+
return this.ui_data_model.vhosts.length > 0;
679+
else return false;
670680
};
671681
this.canListNodes = function() {
672-
return this.isMonitoringUser() && this.ui_data_model.nodes.length > 1;
682+
if (this.ui_data_model)
683+
return this.isMonitoringUser() && this.ui_data_model.nodes.length > 1;
684+
else return false;
673685
};
674686

675687
};
676688

677-
function DisplayControl(overview, ui_data_model) {
678-
this.nodes = ac.canListNodes() && ui_data_model.nodes.length > 1;
679-
this.vhosts = ac.canAccessVhosts();
680-
this.rabbitmqVersions = false;
681-
var v = '';
682-
for (var i = 0; i < ui_data_model.nodes.length; i++) {
683-
var v1 = fmt_rabbit_version(ui_data_model.nodes[i].applications);
684-
if (v1 != 'unknown') {
685-
if (v != '' && v != v1) this.rabbitmqVersions = true;
686-
v = v1;
687-
}
689+
function DisplayControl() {
690+
this.nodes = false
691+
this.vhosts = false
692+
this.rabbitmqVersions = false
693+
694+
this.update = function(overview, ui_data_model) {
695+
this.nodes = ac.canListNodes() && ui_data_model.nodes.length > 1
696+
this.vhosts = ac.canAccessVhosts()
697+
this.rabbitmqVersions = false
698+
var v = '';
699+
for (var i = 0; i < ui_data_model.nodes.length; i++) {
700+
var v1 = fmt_rabbit_version(ui_data_model.nodes[i].applications);
701+
if (v1 != 'unknown') {
702+
if (v != '' && v != v1) this.rabbitmqVersions = true;
703+
v = v1;
704+
}
705+
}
706+
this.data = ui_data_model;
688707
}
689-
this.data = ui_data_model;
690708

691709
}
692710

deps/rabbitmq_management/priv/www/js/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ function check_login () {
113113
}
114114

115115
ui_data_model.vhosts = JSON.parse(sync_get('/vhosts'));
116-
ac = new AccessControl(user, ui_data_model)
116+
ac.update(user, ui_data_model)
117117
if (ac.isMonitoringUser()) {
118118
ui_data_model.nodes = JSON.parse(sync_get('/nodes'))
119119
}
120120
var overview = JSON.parse(sync_get('/overview'))
121121

122-
display = new DisplayControl(overview, ui_data_model)
122+
display.update(overview, ui_data_model)
123123

124124
setup_global_vars(overview)
125125

deps/rabbitmq_management/priv/www/js/tmpl/queues.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<table class="list">
99
<thead>
1010
<tr>
11-
<%= group_heading('queues', 'Overview', [vhosts_interesting, nodes_interesting, true]) %>
11+
<%= group_heading('queues', 'Overview', [display.vhosts, display.nodes, true]) %>
1212
<% if(disable_stats && enable_queue_totals) { %>
1313
<%= group_heading('queues', 'Messages', []) %>
1414
<% } else { %>

0 commit comments

Comments
 (0)