Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Policy and OrganizationStatus services #3345

Merged
merged 8 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions client/app/components/dashboards/edit-dashboard-dialog.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isEmpty } from 'lodash';
import policy from '@/services/policy';
import template from './edit-dashboard-dialog.html';

const EditDashboardDialog = {
Expand All @@ -8,11 +9,11 @@ const EditDashboardDialog = {
dismiss: '&',
},
template,
controller($location, $http, Policy, Events) {
controller($location, $http, Events) {
'ngInject';

this.dashboard = this.resolve.dashboard;
this.policy = Policy;
this.policy = policy;

this.isFormValid = () => !isEmpty(this.dashboard.name);

Expand Down
13 changes: 7 additions & 6 deletions client/app/components/empty-state/empty-state.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import organizationStatus from '@/services/organizationStatus';
import './empty-state.less';
import template from './empty-state.html';

Expand All @@ -15,14 +16,14 @@ const EmptyStateComponent = {
showInviteStep: '<',
onboardingMode: '<',
},
controller($uibModal, OrganizationStatus, currentUser) {
controller($uibModal, currentUser) {
this.isAdmin = currentUser.isAdmin;

this.dataSourceStepCompleted = OrganizationStatus.objectCounters.data_sources > 0;
this.queryStepCompleted = OrganizationStatus.objectCounters.queries > 0;
this.dashboardStepCompleted = OrganizationStatus.objectCounters.dashboards > 0;
this.alertStepCompleted = OrganizationStatus.objectCounters.alerts > 0;
this.inviteStepCompleted = OrganizationStatus.objectCounters.users > 1;
this.dataSourceStepCompleted = organizationStatus.objectCounters.data_sources > 0;
this.queryStepCompleted = organizationStatus.objectCounters.queries > 0;
this.dashboardStepCompleted = organizationStatus.objectCounters.dashboards > 0;
this.alertStepCompleted = organizationStatus.objectCounters.alerts > 0;
this.inviteStepCompleted = organizationStatus.objectCounters.users > 1;

this.shouldShowOnboarding = () => {
if (!this.onboardingMode) {
Expand Down
8 changes: 3 additions & 5 deletions client/app/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { each, isFunction, extend } from 'lodash';

import '@/lib/sortable';

import organizationStatus from '@/services/organizationStatus';

import * as filters from '@/filters';
import registerDirectives from '@/directives';
import markdownFilter from '@/filters/markdown';
Expand Down Expand Up @@ -110,11 +112,7 @@ function registerPages() {
route.authenticated = true;
route.resolve = extend(
{
__organizationStatus: (OrganizationStatus) => {
'ngInject';

return OrganizationStatus.refresh();
},
__organizationStatus: () => organizationStatus.refresh(),
},
route.resolve,
);
Expand Down
4 changes: 2 additions & 2 deletions client/app/pages/dashboards/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as _ from 'lodash';
import PromiseRejectionError from '@/lib/promise-rejection-error';
import getTags from '@/services/getTags';
import policy from '@/services/policy';
import { durationHumanize } from '@/filters';
import template from './dashboard.html';
import shareDashboardTemplate from './share-dashboard.html';
Expand Down Expand Up @@ -36,7 +37,6 @@ function DashboardCtrl(
clientConfig,
Events,
toastr,
Policy,
) {
this.saveInProgress = false;

Expand Down Expand Up @@ -83,7 +83,7 @@ function DashboardCtrl(
enabled: true,
}));

const allowedIntervals = Policy.getDashboardRefreshIntervals();
const allowedIntervals = policy.getDashboardRefreshIntervals();
if (_.isArray(allowedIntervals)) {
_.each(this.refreshRates, (rate) => {
rate.enabled = allowedIntervals.indexOf(rate.rate) >= 0;
Expand Down
5 changes: 3 additions & 2 deletions client/app/pages/data-sources/list.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import settingsMenu from '@/services/settingsMenu';
import policy from '@/services/policy';
import template from './list.html';

function DataSourcesCtrl(Policy, DataSource) {
this.policy = Policy;
function DataSourcesCtrl(DataSource) {
this.policy = policy;
this.dataSources = DataSource.query();
}

Expand Down
4 changes: 2 additions & 2 deletions client/app/pages/queries/view.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { pick, some, find, minBy, map, intersection, isArray, isObject } from 'lodash';
import { SCHEMA_NOT_SUPPORTED, SCHEMA_LOAD_ERROR } from '@/services/data-source';
import getTags from '@/services/getTags';
import policy from '@/services/policy';
import Notifications from '@/services/notifications';
import template from './query.html';

Expand All @@ -21,7 +22,6 @@ function QueryViewCtrl(
toastr,
$uibModal,
currentUser,
Policy,
Query,
DataSource,
Visualization,
Expand Down Expand Up @@ -451,7 +451,7 @@ function QueryViewCtrl(
$scope.openVisualizationEditor();
}
const intervals = clientConfig.queryRefreshIntervals;
const allowedIntervals = Policy.getQueryRefreshIntervals();
const allowedIntervals = policy.getQueryRefreshIntervals();
$scope.refreshOptions = isArray(allowedIntervals) ? intersection(intervals, allowedIntervals) : intervals;

$scope.updateQueryMetadata = changes =>
Expand Down
5 changes: 3 additions & 2 deletions client/app/pages/users/list.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { extend } from 'lodash';
import policy from '@/services/policy';
import ListCtrl from '@/lib/list-ctrl';
import settingsMenu from '@/services/settingsMenu';
import template from './list.html';

class UsersListCtrl extends ListCtrl {
constructor($scope, $location, currentUser, clientConfig, Policy, User) {
constructor($scope, $location, currentUser, clientConfig, User) {
super($scope, $location, currentUser, clientConfig);
this.policy = Policy;
this.policy = policy;
this.enableUser = user => User.enableUser(user).then(this.update);
this.disableUser = user => User.disableUser(user).then(this.update);
this.deleteUser = user => User.deleteUser(user).then(this.update);
Expand Down
2 changes: 2 additions & 0 deletions client/app/services/ng.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
export let $http = null; // eslint-disable-line import/no-mutable-exports
export let $sanitize = null; // eslint-disable-line import/no-mutable-exports
export let $q = null; // eslint-disable-line import/no-mutable-exports
export let $uibModal = null; // eslint-disable-line import/no-mutable-exports
export let toastr = null; // eslint-disable-line import/no-mutable-exports

export default function init(ngModule) {
ngModule.run(($injector) => {
$http = $injector.get('$http');
$sanitize = $injector.get('$sanitize');
$q = $injector.get('$q');
$uibModal = $injector.get('$uibModal');
toastr = $injector.get('toastr');
});
Expand Down
22 changes: 0 additions & 22 deletions client/app/services/organization-status.js

This file was deleted.

17 changes: 17 additions & 0 deletions client/app/services/organizationStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { $http } from '@/services/ng';

class OrganizationStatus {
constructor() {
this.objectCounters = {};
}

refresh() {
return $http.get('api/organization/status').then(({ data }) => {
this.objectCounters = data.object_counters;
return this;
});
}
}

export default new OrganizationStatus();

84 changes: 0 additions & 84 deletions client/app/services/policy.js

This file was deleted.

56 changes: 56 additions & 0 deletions client/app/services/policy/AbstractPolicy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
export default class AbstractPolicy {
kravets-levko marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line class-methods-use-this
_notImplemented() {
throw new Error('Not implemented');
}

// eslint-disable-next-line class-methods-use-this
get user() {
return null;
}

// eslint-disable-next-line class-methods-use-this
get organizationStatus() {
return null;
}

refresh() {
this._notImplemented();
}

canCreateDataSource() {
this._notImplemented();
}

isCreateDataSourceEnabled() {
this._notImplemented();
}

canCreateDashboard() {
this._notImplemented();
}

isCreateDashboardEnabled() {
this._notImplemented();
}

canCreateAlert() {
this._notImplemented();
}

canCreateUser() {
this._notImplemented();
}

isCreateUserEnabled() {
this._notImplemented();
}

getDashboardRefreshIntervals() {
this._notImplemented();
}

getQueryRefreshIntervals() {
this._notImplemented();
}
}
Loading