Alerting: Fix contact points tab visibility when user can only create (#106735)
Contact points tab was not being displayed for users with only `alert.notifications.receivers:create` and not `alert.notifications.receivers:read`
This commit is contained in:
@@ -154,6 +154,20 @@ describe('contact points', () => {
|
||||
|
||||
expect(await screen.findByText(/create contact point/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('defaults to contact points tab if user has only read permission', async () => {
|
||||
grantUserPermissions([AccessControlAction.AlertingReceiversRead]);
|
||||
renderWithProvider(<ContactPointsPageContents />);
|
||||
|
||||
expect(await screen.findByText(/create contact point/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('defaults to contact points tab if user has only create permission', async () => {
|
||||
grantUserPermissions([AccessControlAction.AlertingReceiversCreate]);
|
||||
renderWithProvider(<ContactPointsPageContents />);
|
||||
|
||||
expect(await screen.findByText(/create contact point/i)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('templates tab', () => {
|
||||
|
||||
@@ -196,9 +196,12 @@ const useTabQueryParam = (defaultTab: ActiveTab) => {
|
||||
|
||||
export const ContactPointsPageContents = () => {
|
||||
const { selectedAlertmanager } = useAlertmanager();
|
||||
const [, showContactPointsTab] = useAlertmanagerAbility(AlertmanagerAction.ViewContactPoint);
|
||||
const [, canViewContactPoints] = useAlertmanagerAbility(AlertmanagerAction.ViewContactPoint);
|
||||
const [, canCreateContactPoints] = useAlertmanagerAbility(AlertmanagerAction.CreateContactPoint);
|
||||
const [, showTemplatesTab] = useAlertmanagerAbility(AlertmanagerAction.ViewNotificationTemplate);
|
||||
|
||||
const showContactPointsTab = canViewContactPoints || canCreateContactPoints;
|
||||
|
||||
// Depending on permissions, user may not have access to all tabs,
|
||||
// but we can default to picking the first one that they definitely _do_ have access to
|
||||
const defaultTab = [
|
||||
|
||||
Reference in New Issue
Block a user