From adbc5b2b8813c1ae2b888fe2b726acf72991e935 Mon Sep 17 00:00:00 2001 From: Gilles De Mey Date: Tue, 11 Mar 2025 12:51:48 +0100 Subject: [PATCH] Alerting: Hide "unauthorized" warning for anonymous users (#101811) * remove nav analytics * revert * Remove new user check for alerting navigation tracking * Delete Analytics.test.ts --- .../alerting/unified/Analytics.test.ts | 41 ------------------- .../features/alerting/unified/Analytics.ts | 24 +---------- 2 files changed, 1 insertion(+), 64 deletions(-) delete mode 100644 public/app/features/alerting/unified/Analytics.test.ts diff --git a/public/app/features/alerting/unified/Analytics.test.ts b/public/app/features/alerting/unified/Analytics.test.ts deleted file mode 100644 index 47575f755df..00000000000 --- a/public/app/features/alerting/unified/Analytics.test.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { dateTime } from '@grafana/data'; -import { getBackendSrv } from '@grafana/runtime'; - -import { USER_CREATION_MIN_DAYS, isNewUser } from './Analytics'; - -jest.mock('@grafana/runtime', () => ({ - ...jest.requireActual('@grafana/runtime'), - getBackendSrv: jest.fn().mockReturnValue({ - get: jest.fn(), - }), -})); - -describe('isNewUser', function () { - it('should return true if the user has been created within the last week', async () => { - const newUser = { - id: 1, - createdAt: dateTime().subtract(6, 'days'), - }; - - getBackendSrv().get = jest.fn().mockResolvedValue(newUser); - - const isNew = await isNewUser(); - expect(isNew).toBe(true); - expect(getBackendSrv().get).toHaveBeenCalledTimes(1); - expect(getBackendSrv().get).toHaveBeenCalledWith('/api/user'); - }); - - it('should return false if the user has been created prior to the last two weeks', async () => { - const oldUser = { - id: 2, - createdAt: dateTime().subtract(USER_CREATION_MIN_DAYS, 'days'), - }; - - getBackendSrv().get = jest.fn().mockResolvedValue(oldUser); - - const isNew = await isNewUser(); - expect(isNew).toBe(false); - expect(getBackendSrv().get).toHaveBeenCalledTimes(1); - expect(getBackendSrv().get).toHaveBeenCalledWith('/api/user'); - }); -}); diff --git a/public/app/features/alerting/unified/Analytics.ts b/public/app/features/alerting/unified/Analytics.ts index e546d215574..559e7808d96 100644 --- a/public/app/features/alerting/unified/Analytics.ts +++ b/public/app/features/alerting/unified/Analytics.ts @@ -1,7 +1,6 @@ import { isEmpty } from 'lodash'; -import { dateTime } from '@grafana/data'; -import { createMonitoringLogger, getBackendSrv } from '@grafana/runtime'; +import { createMonitoringLogger } from '@grafana/runtime'; import { config, reportInteraction } from '@grafana/runtime/src'; import { contextSrv } from 'app/core/core'; @@ -13,8 +12,6 @@ import { FilterType } from './components/rules/central-state-history/EventListSc import { RulesFilter, getSearchFilterFromQuery } from './search/rulesSearchParser'; import { RuleFormType } from './types/rule-form'; -export const USER_CREATION_MIN_DAYS = 7; - export const LogMessages = { filterByLabel: 'filtering alert instances by label', loadedList: 'loaded Alert Rules list', @@ -152,21 +149,6 @@ function getRulerRulesMetadata(rulerRules: RulerRulesConfigDTO) { }; } -export async function isNewUser() { - try { - const { createdAt } = await getBackendSrv().get(`/api/user`); - - const limitDateForNewUser = dateTime().subtract(USER_CREATION_MIN_DAYS, 'days'); - const userCreationDate = dateTime(createdAt); - - const isNew = limitDateForNewUser.isBefore(userCreationDate); - - return isNew; - } catch { - return true; //if no date is returned, we assume the user is new to prevent tracking actions - } -} - export const trackRuleListNavigation = async ( props: AlertRuleTrackingProps = { grafana_version: config.buildInfo.version, @@ -174,10 +156,6 @@ export const trackRuleListNavigation = async ( user_id: contextSrv.user.id, } ) => { - const isNew = await isNewUser(); - if (isNew) { - return; - } reportInteraction('grafana_alerting_navigation', props); };