mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
This feature would provide a way for administrators to limit the minimum dashboard refresh interval globally. Filters out the refresh intervals available in the time picker that are lower than the set minimum refresh interval in the configuration .ini file Adds the minimum refresh interval as available in the time picker. If the user tries to enter a refresh interval that is lower than the minimum in the URL, defaults to the minimum interval. When trying to update the JSON via the API, rejects the update if the dashboard's refresh interval is lower than the minimum. When trying to update a dashboard via provisioning having a lower refresh interval than the minimum, defaults to the minimum interval and logs a warning. Fixes #3356 Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
85 lines
2.0 KiB
TypeScript
85 lines
2.0 KiB
TypeScript
import config from '../../core/config';
|
|
import _ from 'lodash';
|
|
import coreModule from 'app/core/core_module';
|
|
import kbn from '../utils/kbn';
|
|
|
|
export class User {
|
|
id: number;
|
|
isGrafanaAdmin: any;
|
|
isSignedIn: any;
|
|
orgRole: any;
|
|
orgId: number;
|
|
orgName: string;
|
|
login: string;
|
|
orgCount: number;
|
|
timezone: string;
|
|
helpFlags1: number;
|
|
lightTheme: boolean;
|
|
hasEditPermissionInFolders: boolean;
|
|
|
|
constructor() {
|
|
if (config.bootData.user) {
|
|
_.extend(this, config.bootData.user);
|
|
}
|
|
}
|
|
}
|
|
|
|
export class ContextSrv {
|
|
pinned: any;
|
|
version: any;
|
|
user: User;
|
|
isSignedIn: any;
|
|
isGrafanaAdmin: any;
|
|
isEditor: any;
|
|
sidemenuSmallBreakpoint = false;
|
|
hasEditPermissionInFolders: boolean;
|
|
minRefreshInterval: string;
|
|
|
|
constructor() {
|
|
if (!config.bootData) {
|
|
config.bootData = { user: {}, settings: {} };
|
|
}
|
|
|
|
this.user = new User();
|
|
this.isSignedIn = this.user.isSignedIn;
|
|
this.isGrafanaAdmin = this.user.isGrafanaAdmin;
|
|
this.isEditor = this.hasRole('Editor') || this.hasRole('Admin');
|
|
this.hasEditPermissionInFolders = this.user.hasEditPermissionInFolders;
|
|
this.minRefreshInterval = config.minRefreshInterval;
|
|
}
|
|
|
|
hasRole(role: string) {
|
|
return this.user.orgRole === role;
|
|
}
|
|
|
|
isGrafanaVisible() {
|
|
return !!(document.visibilityState === undefined || document.visibilityState === 'visible');
|
|
}
|
|
|
|
// checks whether the passed interval is longer than the configured minimum refresh rate
|
|
isAllowedInterval(interval: string) {
|
|
if (!config.minRefreshInterval) {
|
|
return true;
|
|
}
|
|
return kbn.interval_to_ms(interval) >= kbn.interval_to_ms(config.minRefreshInterval);
|
|
}
|
|
|
|
getValidInterval(interval: string) {
|
|
if (!this.isAllowedInterval(interval)) {
|
|
return config.minRefreshInterval;
|
|
}
|
|
return interval;
|
|
}
|
|
|
|
hasAccessToExplore() {
|
|
return (this.isEditor || config.viewersCanEdit) && config.exploreEnabled;
|
|
}
|
|
}
|
|
|
|
const contextSrv = new ContextSrv();
|
|
export { contextSrv };
|
|
|
|
coreModule.factory('contextSrv', () => {
|
|
return contextSrv;
|
|
});
|