This commit is contained in:
Marcial Rosales 2023-05-23 16:44:44 +02:00
parent f82a3f253d
commit 02fda919a5
3 changed files with 44 additions and 26 deletions

View File

@ -640,8 +640,8 @@ var exchange_types;
// Used for access control // Used for access control
var user_tags; var user_tags;
var user; var user;
var ac; var ac = new AccessControl();
var display; var display = new DisplayControl();
var ui_data_model = { var ui_data_model = {
vhosts: [], vhosts: [],
@ -651,33 +651,50 @@ var ui_data_model = {
// Access control // Access control
function AccessControl(user, ui_data_model) { function AccessControl() {
this.update = function(user, ui_data_model) {
this.user = user; this.user = user;
this.user_tags = expand_user_tags(user.tags); this.user_tags = expand_user_tags(user.tags);
this.ui_data_model = ui_data_model; this.ui_data_model = ui_data_model;
};
this.isMonitoringUser = function() { this.isMonitoringUser = function() {
if (this.user_tags)
return this.user_tags.includes("monitoring"); return this.user_tags.includes("monitoring");
else return false;
}; };
this.isAdministratorUser = function() { this.isAdministratorUser = function() {
if (this.user_tags)
return this.user_tags.includes("administrator"); return this.user_tags.includes("administrator");
else return false;
}; };
this.isPolicyMakerUser = function() { this.isPolicyMakerUser = function() {
if (this.user_tags)
return this.user_tags.includes("policymaker"); return this.user_tags.includes("policymaker");
else return false;
}; };
this.canAccessVhosts = function() { this.canAccessVhosts = function() {
if (this.ui_data_model)
return this.ui_data_model.vhosts.length > 0; return this.ui_data_model.vhosts.length > 0;
else return false;
}; };
this.canListNodes = function() { this.canListNodes = function() {
if (this.ui_data_model)
return this.isMonitoringUser() && this.ui_data_model.nodes.length > 1; return this.isMonitoringUser() && this.ui_data_model.nodes.length > 1;
else return false;
}; };
}; };
function DisplayControl(overview, ui_data_model) { function DisplayControl() {
this.nodes = ac.canListNodes() && ui_data_model.nodes.length > 1; this.nodes = false
this.vhosts = ac.canAccessVhosts(); this.vhosts = false
this.rabbitmqVersions = false; this.rabbitmqVersions = false
this.update = function(overview, ui_data_model) {
this.nodes = ac.canListNodes() && ui_data_model.nodes.length > 1
this.vhosts = ac.canAccessVhosts()
this.rabbitmqVersions = false
var v = ''; var v = '';
for (var i = 0; i < ui_data_model.nodes.length; i++) { for (var i = 0; i < ui_data_model.nodes.length; i++) {
var v1 = fmt_rabbit_version(ui_data_model.nodes[i].applications); var v1 = fmt_rabbit_version(ui_data_model.nodes[i].applications);
@ -687,6 +704,7 @@ function DisplayControl(overview, ui_data_model) {
} }
} }
this.data = ui_data_model; this.data = ui_data_model;
}
} }

View File

@ -113,13 +113,13 @@ function check_login () {
} }
ui_data_model.vhosts = JSON.parse(sync_get('/vhosts')); ui_data_model.vhosts = JSON.parse(sync_get('/vhosts'));
ac = new AccessControl(user, ui_data_model) ac.update(user, ui_data_model)
if (ac.isMonitoringUser()) { if (ac.isMonitoringUser()) {
ui_data_model.nodes = JSON.parse(sync_get('/nodes')) ui_data_model.nodes = JSON.parse(sync_get('/nodes'))
} }
var overview = JSON.parse(sync_get('/overview')) var overview = JSON.parse(sync_get('/overview'))
display = new DisplayControl(overview, ui_data_model) display.update(overview, ui_data_model)
setup_global_vars(overview) setup_global_vars(overview)

View File

@ -8,7 +8,7 @@
<table class="list"> <table class="list">
<thead> <thead>
<tr> <tr>
<%= group_heading('queues', 'Overview', [vhosts_interesting, nodes_interesting, true]) %> <%= group_heading('queues', 'Overview', [display.vhosts, display.nodes, true]) %>
<% if(disable_stats && enable_queue_totals) { %> <% if(disable_stats && enable_queue_totals) { %>
<%= group_heading('queues', 'Messages', []) %> <%= group_heading('queues', 'Messages', []) %>
<% } else { %> <% } else { %>