Alerting: Check permissions for showing create recording rules button (#105256)
This commit is contained in:
+1
-1
@@ -11,9 +11,9 @@ import { shouldUsePrometheusRulesPrimary } from '../../featureToggles';
|
||||
const { usePrometheusRuleNamespacesQuery, useLazyRulerRulesQuery, useRulerRulesQuery } = alertRuleApi;
|
||||
const { useDiscoverDsFeaturesQuery } = featureDiscoveryApi;
|
||||
|
||||
const prometheusRulesPrimary = shouldUsePrometheusRulesPrimary();
|
||||
const emptyRulerConfig: RulerRulesConfigDTO = {};
|
||||
|
||||
const prometheusRulesPrimary = shouldUsePrometheusRulesPrimary();
|
||||
export function useGetLabelsFromDataSourceName(rulesSourceName: string) {
|
||||
const { data: features, isLoading: isFeaturesLoading } = useDiscoverDsFeaturesQuery({ rulesSourceName });
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { css } from '@emotion/css';
|
||||
import { useToggle } from 'react-use';
|
||||
|
||||
import { GrafanaTheme2 } from '@grafana/data';
|
||||
import { config } from '@grafana/runtime';
|
||||
import { Button, LinkButton, LoadingPlaceholder, Pagination, Spinner, Stack, Text, useStyles2 } from '@grafana/ui';
|
||||
import { useQueryParams } from 'app/core/hooks/useQueryParams';
|
||||
import { Trans, t } from 'app/core/internationalization';
|
||||
@@ -9,12 +10,12 @@ import { CombinedRuleNamespace } from 'app/types/unified-alerting';
|
||||
|
||||
import { DEFAULT_PER_PAGE_PAGINATION } from '../../../../../core/constants';
|
||||
import { LogMessages, logInfo } from '../../Analytics';
|
||||
import { useGrafanaManagedRecordingRulesSupport } from '../../featureToggles';
|
||||
import { AlertingAction, useAlertingAbility } from '../../hooks/useAbilities';
|
||||
import { flattenGrafanaManagedRules } from '../../hooks/useCombinedRuleNamespaces';
|
||||
import { usePagination } from '../../hooks/usePagination';
|
||||
import { useUnifiedAlertingSelector } from '../../hooks/useUnifiedAlertingSelector';
|
||||
import { getPaginationStyles } from '../../styles/pagination';
|
||||
import { useRulesAccess } from '../../utils/accessControlHooks';
|
||||
import { GRAFANA_RULES_SOURCE_NAME } from '../../utils/datasource';
|
||||
import { initialAsyncRequestState } from '../../utils/redux';
|
||||
import { createRelativeUrl } from '../../utils/url';
|
||||
@@ -56,8 +57,11 @@ export const GrafanaRules = ({ namespaces, expandAll }: Props) => {
|
||||
|
||||
const [showExportDrawer, toggleShowExportDrawer] = useToggle(false);
|
||||
const hasGrafanaAlerts = namespaces.length > 0;
|
||||
|
||||
const grafanaRecordingRulesEnabled = useGrafanaManagedRecordingRulesSupport();
|
||||
const { canCreateGrafanaRules } = useRulesAccess();
|
||||
const grafanaRecordingRulesEnabled =
|
||||
config.unifiedAlerting.recordingRulesEnabled &&
|
||||
config.featureToggles.grafanaManagedRecordingRules &&
|
||||
canCreateGrafanaRules;
|
||||
|
||||
return (
|
||||
<section className={styles.wrapper}>
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
import { config } from '@grafana/runtime';
|
||||
import { Dropdown, EmptyState, LinkButton, Menu, MenuItem, Stack, TextLink } from '@grafana/ui';
|
||||
import { Trans, t } from 'app/core/internationalization';
|
||||
|
||||
import { useGrafanaManagedRecordingRulesSupport } from '../../featureToggles';
|
||||
import { useRulesAccess } from '../../utils/accessControlHooks';
|
||||
|
||||
const RecordingRulesButtons = () => {
|
||||
const { canCreateGrafanaRules, canCreateCloudRules } = useRulesAccess();
|
||||
const grafanaRecordingRulesEnabled = useGrafanaManagedRecordingRulesSupport();
|
||||
|
||||
const grafanaRecordingRulesEnabled =
|
||||
config.unifiedAlerting.recordingRulesEnabled &&
|
||||
config.featureToggles.grafanaManagedRecordingRules &&
|
||||
canCreateGrafanaRules;
|
||||
|
||||
const canCreateAll = canCreateGrafanaRules && canCreateCloudRules && grafanaRecordingRulesEnabled;
|
||||
|
||||
// User can create Grafana and DS-managed recording rules, show a dropdown
|
||||
|
||||
@@ -16,9 +16,6 @@ export const shouldUseAlertingListViewV2 = () => {
|
||||
return config.featureToggles.alertingListViewV2;
|
||||
};
|
||||
|
||||
export const useGrafanaManagedRecordingRulesSupport = () =>
|
||||
config.unifiedAlerting.recordingRulesEnabled && config.featureToggles.grafanaManagedRecordingRules;
|
||||
|
||||
export const shouldAllowRecoveringDeletedRules = () =>
|
||||
(isAdmin() && config.featureToggles.alertingRuleRecoverDeleted && config.featureToggles.alertRuleRestore) ?? false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user