Problems panel: hide acknowledge button for read-only users, fix #722

This commit is contained in:
Alexander Zobnin
2019-04-22 13:10:23 +03:00
parent bc889ffe30
commit f908376802
5 changed files with 41 additions and 16 deletions

View File

@@ -36,11 +36,13 @@ export default class AlertAcknowledges extends PureComponent<AlertAcknowledgesPr
{ackRows} {ackRows}
</tbody> </tbody>
</table> </table>
{problem.showAckButton &&
<div className="ack-add-button"> <div className="ack-add-button">
<button id="add-acknowledge-btn" className="btn btn-mini btn-inverse gf-form-button" onClick={this.handleClick}> <button id="add-acknowledge-btn" className="btn btn-mini btn-inverse gf-form-button" onClick={this.handleClick}>
<i className="fa fa-plus"></i> <i className="fa fa-plus"></i>
</button> </button>
</div> </div>
}
</div> </div>
); );
} }

View File

@@ -44,8 +44,11 @@ export default class AlertCard extends PureComponent<AlertCardProps, AlertCardSt
} }
showAckDialog = () => { showAckDialog = () => {
const problem = this.props.problem;
if (problem.showAckButton) {
this.setState({ showAckDialog: true }); this.setState({ showAckDialog: true });
} }
}
closeAckDialog = () => { closeAckDialog = () => {
this.setState({ showAckDialog: false }); this.setState({ showAckDialog: false });
@@ -258,14 +261,20 @@ class AlertAcknowledgesButton extends PureComponent<AlertAcknowledgesButtonProps
render() { render() {
const { problem } = this.props; const { problem } = this.props;
return ( let content = null;
problem.acknowledges && problem.acknowledges.length ? if (problem.acknowledges && problem.acknowledges.length) {
content = (
<Tooltip placement="bottom" popperClassName="ack-tooltip" content={this.renderTooltipContent}> <Tooltip placement="bottom" popperClassName="ack-tooltip" content={this.renderTooltipContent}>
<span><i className="fa fa-comments"></i></span> <span><i className="fa fa-comments"></i></span>
</Tooltip> : </Tooltip>
);
} else if (problem.showAckButton) {
content = (
<Tooltip placement="bottom" content="Acknowledge problem"> <Tooltip placement="bottom" content="Acknowledge problem">
<span role="button" onClick={this.handleClick}><i className="fa fa-comments-o"></i></span> <span role="button" onClick={this.handleClick}><i className="fa fa-comments-o"></i></span>
</Tooltip> </Tooltip>
); );
} }
return content;
}
} }

View File

@@ -110,12 +110,14 @@ export default class ProblemDetails extends PureComponent<ProblemDetailsProps, P
{problem.items && <ProblemItems items={problem.items} />} {problem.items && <ProblemItems items={problem.items} />}
</div> </div>
<ProblemStatusBar problem={problem} alerts={alerts} className={compactStatusBar && 'compact'} /> <ProblemStatusBar problem={problem} alerts={alerts} className={compactStatusBar && 'compact'} />
{problem.showAckButton &&
<div className="problem-actions"> <div className="problem-actions">
<ProblemActionButton className="navbar-button navbar-button--settings" <ProblemActionButton className="navbar-button navbar-button--settings"
icon="reply-all" icon="reply-all"
tooltip="Acknowledge problem" tooltip="Acknowledge problem"
onClick={this.showAckDialog} /> onClick={this.showAckDialog} />
</div> </div>
}
</div> </div>
{problem.comments && {problem.comments &&
<div className="problem-description"> <div className="problem-description">

View File

@@ -234,9 +234,11 @@ export class TriggerPanelCtrl extends PanelCtrl {
getTriggers() { getTriggers() {
const timeFrom = Math.ceil(dateMath.parse(this.range.from) / 1000); const timeFrom = Math.ceil(dateMath.parse(this.range.from) / 1000);
const timeTo = Math.ceil(dateMath.parse(this.range.to) / 1000); const timeTo = Math.ceil(dateMath.parse(this.range.to) / 1000);
const userIsEditor = this.contextSrv.isEditor || this.contextSrv.isGrafanaAdmin;
let promises = _.map(this.panel.datasources, (ds) => { let promises = _.map(this.panel.datasources, (ds) => {
let proxies; let proxies;
let showAckButton = true;
return this.datasourceSrv.get(ds) return this.datasourceSrv.get(ds)
.then(datasource => { .then(datasource => {
const zabbix = datasource.zabbix; const zabbix = datasource.zabbix;
@@ -244,6 +246,7 @@ export class TriggerPanelCtrl extends PanelCtrl {
const triggerFilter = this.panel.targets[ds]; const triggerFilter = this.panel.targets[ds];
const showProxy = this.panel.hostProxy; const showProxy = this.panel.hostProxy;
const getProxiesPromise = showProxy ? zabbix.getProxies() : () => []; const getProxiesPromise = showProxy ? zabbix.getProxies() : () => [];
showAckButton = !datasource.disableReadOnlyUsersAck || userIsEditor;
// Replace template variables // Replace template variables
const groupFilter = datasource.replaceTemplateVars(triggerFilter.group.filter); const groupFilter = datasource.replaceTemplateVars(triggerFilter.group.filter);
@@ -280,6 +283,7 @@ export class TriggerPanelCtrl extends PanelCtrl {
return triggers; return triggers;
}) })
.then(triggers => this.setMaintenanceStatus(triggers)) .then(triggers => this.setMaintenanceStatus(triggers))
.then(triggers => this.setAckButtonStatus(triggers, showAckButton))
.then(triggers => this.filterTriggersPre(triggers, ds)) .then(triggers => this.filterTriggersPre(triggers, ds))
.then(triggers => this.addTriggerDataSource(triggers, ds)) .then(triggers => this.addTriggerDataSource(triggers, ds))
.then(triggers => this.addTriggerHostProxy(triggers, proxies)); .then(triggers => this.addTriggerHostProxy(triggers, proxies));
@@ -395,6 +399,13 @@ export class TriggerPanelCtrl extends PanelCtrl {
return triggers; return triggers;
} }
setAckButtonStatus(triggers, showAckButton) {
_.each(triggers, (trigger) => {
trigger.showAckButton = showAckButton;
});
return triggers;
}
addTriggerDataSource(triggers, ds) { addTriggerDataSource(triggers, ds) {
_.each(triggers, (trigger) => { _.each(triggers, (trigger) => {
trigger.datasource = ds; trigger.datasource = ds;

View File

@@ -75,6 +75,7 @@ export type TriggerColor = string;
export interface ZBXTrigger { export interface ZBXTrigger {
acknowledges?: ZBXAcknowledge[]; acknowledges?: ZBXAcknowledge[];
showAckButton?: boolean;
alerts?: ZBXAlert[]; alerts?: ZBXAlert[];
age?: string; age?: string;
color?: TriggerColor; color?: TriggerColor;