Alerting: Hide "unauthorized" warning for anonymous users (#101811)
* remove nav analytics * revert * Remove new user check for alerting navigation tracking * Delete Analytics.test.ts
This commit is contained in:
@@ -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');
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user