From 6f22584d2690b437c3494c99401255ac87de2ed8 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Fri, 10 Mar 2023 14:29:43 +0100 Subject: [PATCH] [v9.4.x] Alerting: fix users call 403 by calling /user instead of /users/{id} (#64607) Co-authored-by: Virginia Cepeda fix users call 403 by calling /user instead of /users/{id} (#64544) --- public/app/features/alerting/unified/Analytics.test.ts | 8 ++++---- public/app/features/alerting/unified/Analytics.ts | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/public/app/features/alerting/unified/Analytics.test.ts b/public/app/features/alerting/unified/Analytics.test.ts index f884c8d40eb..bea69a3ade4 100644 --- a/public/app/features/alerting/unified/Analytics.test.ts +++ b/public/app/features/alerting/unified/Analytics.test.ts @@ -18,10 +18,10 @@ describe('isNewUser', function () { getBackendSrv().get = jest.fn().mockResolvedValue(newUser); - const isNew = await isNewUser(1); + const isNew = await isNewUser(); expect(isNew).toBe(true); expect(getBackendSrv().get).toHaveBeenCalledTimes(1); - expect(getBackendSrv().get).toHaveBeenCalledWith('/api/users/1'); + expect(getBackendSrv().get).toHaveBeenCalledWith('/api/user'); }); it('should return false if the user has been created prior to the last two weeks', async () => { @@ -32,9 +32,9 @@ describe('isNewUser', function () { getBackendSrv().get = jest.fn().mockResolvedValue(oldUser); - const isNew = await isNewUser(2); + const isNew = await isNewUser(); expect(isNew).toBe(false); expect(getBackendSrv().get).toHaveBeenCalledTimes(1); - expect(getBackendSrv().get).toHaveBeenCalledWith('/api/users/2'); + 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 51c150d968b..8cd88e6d0ec 100644 --- a/public/app/features/alerting/unified/Analytics.ts +++ b/public/app/features/alerting/unified/Analytics.ts @@ -44,9 +44,9 @@ export function withPerformanceLogging Promise }; } -export async function isNewUser(userId: number) { +export async function isNewUser() { try { - const { createdAt } = await getBackendSrv().get(`/api/users/${userId}`); + const { createdAt } = await getBackendSrv().get(`/api/user`); const limitDateForNewUser = dateTime().subtract(USER_CREATION_MIN_DAYS, 'days'); const userCreationDate = dateTime(createdAt); @@ -60,7 +60,7 @@ export async function isNewUser(userId: number) { } export const trackNewAlerRuleFormSaved = async (props: AlertRuleTrackingProps) => { - const isNew = await isNewUser(props.user_id); + const isNew = await isNewUser(); if (isNew) { return; } @@ -68,7 +68,7 @@ export const trackNewAlerRuleFormSaved = async (props: AlertRuleTrackingProps) = }; export const trackNewAlerRuleFormCancelled = async (props: AlertRuleTrackingProps) => { - const isNew = await isNewUser(props.user_id); + const isNew = await isNewUser(); if (isNew) { return; } @@ -76,7 +76,7 @@ export const trackNewAlerRuleFormCancelled = async (props: AlertRuleTrackingProp }; export const trackNewAlerRuleFormError = async (props: AlertRuleTrackingProps & { error: string }) => { - const isNew = await isNewUser(props.user_id); + const isNew = await isNewUser(); if (isNew) { return; }