Alerting: enforce roles on frontend (#33997)

This commit is contained in:
Domas
2021-05-17 11:15:17 +03:00
committed by GitHub
parent a26507e9c4
commit 8a0dbd0127
21 changed files with 281 additions and 125 deletions

View File

@@ -16,7 +16,7 @@ import { saveRuleFormAction } from '../../state/actions';
import { RuleWithLocation } from 'app/types/unified-alerting';
import { useDispatch } from 'react-redux';
import { useCleanup } from 'app/core/hooks/useCleanup';
import { rulerRuleToFormValues, defaultFormValues, getDefaultQueries } from '../../utils/rule-form';
import { rulerRuleToFormValues, getDefaultFormValues, getDefaultQueries } from '../../utils/rule-form';
import { Link } from 'react-router-dom';
import { useQueryParams } from 'app/core/hooks/useQueryParams';
@@ -36,7 +36,7 @@ export const AlertRuleForm: FC<Props> = ({ existing }) => {
return rulerRuleToFormValues(existing);
}
return {
...defaultFormValues,
...getDefaultFormValues(),
queries: getDefaultQueries(),
...(queryParams['defaults'] ? JSON.parse(queryParams['defaults'] as string) : {}),
};

View File

@@ -10,6 +10,7 @@ import { DataSourcePicker } from '@grafana/runtime';
import { useRulesSourcesWithRuler } from '../../hooks/useRuleSourcesWithRuler';
import { RuleFolderPicker } from './RuleFolderPicker';
import { GroupAndNamespaceFields } from './GroupAndNamespaceFields';
import { contextSrv } from 'app/core/services/context_srv';
const alertTypeOptions: SelectableValue[] = [
{
@@ -17,12 +18,15 @@ const alertTypeOptions: SelectableValue[] = [
value: RuleFormType.threshold,
description: 'Metric alert based on a defined threshold',
},
{
];
if (contextSrv.isEditor) {
alertTypeOptions.push({
label: 'System or application',
value: RuleFormType.system,
description: 'Alert based on a system or application behavior. Based on Prometheus.',
},
];
});
}
interface Props {
editingExistingRule: boolean;