option to disable acknowledges for read-only users, closes #481

This commit is contained in:
Alexander Zobnin
2018-03-23 19:14:20 +03:00
parent 0c8308a951
commit fdbbba2fb0
8 changed files with 34 additions and 4 deletions

View File

@@ -220,7 +220,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
this.basicAuth = instanceSettings.basicAuth;
this.withCredentials = instanceSettings.withCredentials;
var jsonData = instanceSettings.jsonData;
var jsonData = instanceSettings.jsonData || {};
// Zabbix API credentials
this.username = jsonData.username;
@@ -240,6 +240,9 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
this.addThresholds = jsonData.addThresholds;
this.alertingMinSeverity = jsonData.alertingMinSeverity || c.SEV_WARNING;
// Other options
this.disableReadOnlyUsersAck = jsonData.disableReadOnlyUsersAck;
// Direct DB Connection options
var dbConnectionOptions = jsonData.dbConnection || {};
this.enableDirectDBConnection = dbConnectionOptions.enable;

File diff suppressed because one or more lines are too long

View File

@@ -126,3 +126,11 @@
</div>
</div>
</div>
<div class="gf-form-group">
<h3 class="page-heading">Other</h3>
<gf-form-switch class="gf-form" label-class="width-20"
label="Disable acknowledges for read-only users"
checked="ctrl.current.jsonData.disableReadOnlyUsersAck">
</gf-form-switch>
</div>

View File

@@ -603,6 +603,10 @@ System.register(['lodash', 'jquery', 'moment', '../datasource-zabbix/utils', 'ap
var grafana_user = this.contextSrv.user.name;
var ack_message = grafana_user + ' (Grafana): ' + message;
return this.datasourceSrv.get(trigger.datasource).then(function (datasource) {
var userIsEditor = _this8.contextSrv.isEditor || _this8.contextSrv.isGrafanaAdmin;
if (datasource.disableReadOnlyUsersAck && !userIsEditor) {
return Promise.reject({ message: 'You have no permissions to acknowledge events.' });
}
if (eventid) {
return datasource.zabbix.zabbixAPI.acknowledgeEvent(eventid, ack_message);
} else {

File diff suppressed because one or more lines are too long

View File

@@ -28,7 +28,7 @@ class ZabbixAPIDatasource {
this.basicAuth = instanceSettings.basicAuth;
this.withCredentials = instanceSettings.withCredentials;
const jsonData = instanceSettings.jsonData;
const jsonData = instanceSettings.jsonData || {};
// Zabbix API credentials
this.username = jsonData.username;
@@ -48,6 +48,9 @@ class ZabbixAPIDatasource {
this.addThresholds = jsonData.addThresholds;
this.alertingMinSeverity = jsonData.alertingMinSeverity || c.SEV_WARNING;
// Other options
this.disableReadOnlyUsersAck = jsonData.disableReadOnlyUsersAck;
// Direct DB Connection options
let dbConnectionOptions = jsonData.dbConnection || {};
this.enableDirectDBConnection = dbConnectionOptions.enable;

View File

@@ -126,3 +126,11 @@
</div>
</div>
</div>
<div class="gf-form-group">
<h3 class="page-heading">Other</h3>
<gf-form-switch class="gf-form" label-class="width-20"
label="Disable acknowledges for read-only users"
checked="ctrl.current.jsonData.disableReadOnlyUsersAck">
</gf-form-switch>
</div>

View File

@@ -453,6 +453,10 @@ export class TriggerPanelCtrl extends PanelCtrl {
let ack_message = grafana_user + ' (Grafana): ' + message;
return this.datasourceSrv.get(trigger.datasource)
.then(datasource => {
const userIsEditor = this.contextSrv.isEditor || this.contextSrv.isGrafanaAdmin;
if (datasource.disableReadOnlyUsersAck && !userIsEditor) {
return Promise.reject({message: 'You have no permissions to acknowledge events.'});
}
if (eventid) {
return datasource.zabbix.zabbixAPI.acknowledgeEvent(eventid, ack_message);
} else {