mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: fix users call 403 by calling /user instead of /users/{id} (#64544)
Fetch user data with calling /user endpoint This avoids a permission error we were getting by calling /users/{id}
This commit is contained in:
parent
79152969f3
commit
93b32eec4b
@ -18,10 +18,10 @@ describe('isNewUser', function () {
|
|||||||
|
|
||||||
getBackendSrv().get = jest.fn().mockResolvedValue(newUser);
|
getBackendSrv().get = jest.fn().mockResolvedValue(newUser);
|
||||||
|
|
||||||
const isNew = await isNewUser(1);
|
const isNew = await isNewUser();
|
||||||
expect(isNew).toBe(true);
|
expect(isNew).toBe(true);
|
||||||
expect(getBackendSrv().get).toHaveBeenCalledTimes(1);
|
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 () => {
|
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);
|
getBackendSrv().get = jest.fn().mockResolvedValue(oldUser);
|
||||||
|
|
||||||
const isNew = await isNewUser(2);
|
const isNew = await isNewUser();
|
||||||
expect(isNew).toBe(false);
|
expect(isNew).toBe(false);
|
||||||
expect(getBackendSrv().get).toHaveBeenCalledTimes(1);
|
expect(getBackendSrv().get).toHaveBeenCalledTimes(1);
|
||||||
expect(getBackendSrv().get).toHaveBeenCalledWith('/api/users/2');
|
expect(getBackendSrv().get).toHaveBeenCalledWith('/api/user');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -45,9 +45,9 @@ export function withPerformanceLogging<TFunc extends (...args: any[]) => Promise
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function isNewUser(userId: number) {
|
export async function isNewUser() {
|
||||||
try {
|
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 limitDateForNewUser = dateTime().subtract(USER_CREATION_MIN_DAYS, 'days');
|
||||||
const userCreationDate = dateTime(createdAt);
|
const userCreationDate = dateTime(createdAt);
|
||||||
@ -61,7 +61,7 @@ export async function isNewUser(userId: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const trackNewAlerRuleFormSaved = async (props: AlertRuleTrackingProps) => {
|
export const trackNewAlerRuleFormSaved = async (props: AlertRuleTrackingProps) => {
|
||||||
const isNew = await isNewUser(props.user_id);
|
const isNew = await isNewUser();
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ export const trackNewAlerRuleFormSaved = async (props: AlertRuleTrackingProps) =
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const trackNewAlerRuleFormCancelled = async (props: AlertRuleTrackingProps) => {
|
export const trackNewAlerRuleFormCancelled = async (props: AlertRuleTrackingProps) => {
|
||||||
const isNew = await isNewUser(props.user_id);
|
const isNew = await isNewUser();
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ export const trackNewAlerRuleFormCancelled = async (props: AlertRuleTrackingProp
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const trackNewAlerRuleFormError = async (props: AlertRuleTrackingProps & { error: string }) => {
|
export const trackNewAlerRuleFormError = async (props: AlertRuleTrackingProps & { error: string }) => {
|
||||||
const isNew = await isNewUser(props.user_id);
|
const isNew = await isNewUser();
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user