mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: remove legacy dashboard and folder permission pages (#77143)
remove legacy dashboard and folder permission pages
This commit is contained in:
@@ -5,100 +5,14 @@ import { createSuccessNotification } from 'app/core/copy/appNotification';
|
||||
import { dashboardWatcher } from 'app/features/live/dashboard/dashboardWatcher';
|
||||
import { removeAllPanels } from 'app/features/panel/state/reducers';
|
||||
import { updateTimeZoneForSession, updateWeekStartForSession } from 'app/features/profile/state/reducers';
|
||||
import { DashboardAcl, DashboardAclUpdateDTO, NewDashboardAclItem, PermissionLevel, ThunkResult } from 'app/types';
|
||||
import { ThunkResult } from 'app/types';
|
||||
|
||||
import { loadPluginDashboards } from '../../plugins/admin/state/actions';
|
||||
import { cancelVariables } from '../../variables/state/actions';
|
||||
import { getDashboardSrv } from '../services/DashboardSrv';
|
||||
import { getTimeSrv } from '../services/TimeSrv';
|
||||
|
||||
import { cleanUpDashboard, loadDashboardPermissions } from './reducers';
|
||||
|
||||
export function getDashboardPermissions(id: number): ThunkResult<void> {
|
||||
return async (dispatch) => {
|
||||
const permissions = await getBackendSrv().get(`/api/dashboards/id/${id}/permissions`);
|
||||
dispatch(loadDashboardPermissions(permissions));
|
||||
};
|
||||
}
|
||||
|
||||
function toUpdateItem(item: DashboardAcl): DashboardAclUpdateDTO {
|
||||
return {
|
||||
userId: item.userId,
|
||||
teamId: item.teamId,
|
||||
role: item.role,
|
||||
permission: item.permission,
|
||||
};
|
||||
}
|
||||
|
||||
export function updateDashboardPermission(
|
||||
dashboardId: number,
|
||||
itemToUpdate: DashboardAcl,
|
||||
level: PermissionLevel
|
||||
): ThunkResult<void> {
|
||||
return async (dispatch, getStore) => {
|
||||
const { dashboard } = getStore();
|
||||
const itemsToUpdate = [];
|
||||
|
||||
for (const item of dashboard.permissions) {
|
||||
if (item.inherited) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const updated = toUpdateItem(item);
|
||||
|
||||
// if this is the item we want to update, update its permission
|
||||
if (itemToUpdate === item) {
|
||||
updated.permission = level;
|
||||
}
|
||||
|
||||
itemsToUpdate.push(updated);
|
||||
}
|
||||
|
||||
await getBackendSrv().post(`/api/dashboards/id/${dashboardId}/permissions`, { items: itemsToUpdate });
|
||||
await dispatch(getDashboardPermissions(dashboardId));
|
||||
};
|
||||
}
|
||||
|
||||
export function removeDashboardPermission(dashboardId: number, itemToDelete: DashboardAcl): ThunkResult<void> {
|
||||
return async (dispatch, getStore) => {
|
||||
const dashboard = getStore().dashboard;
|
||||
const itemsToUpdate = [];
|
||||
|
||||
for (const item of dashboard.permissions) {
|
||||
if (item.inherited || item === itemToDelete) {
|
||||
continue;
|
||||
}
|
||||
itemsToUpdate.push(toUpdateItem(item));
|
||||
}
|
||||
|
||||
await getBackendSrv().post(`/api/dashboards/id/${dashboardId}/permissions`, { items: itemsToUpdate });
|
||||
await dispatch(getDashboardPermissions(dashboardId));
|
||||
};
|
||||
}
|
||||
|
||||
export function addDashboardPermission(dashboardId: number, newItem: NewDashboardAclItem): ThunkResult<void> {
|
||||
return async (dispatch, getStore) => {
|
||||
const { dashboard } = getStore();
|
||||
const itemsToUpdate = [];
|
||||
|
||||
for (const item of dashboard.permissions) {
|
||||
if (item.inherited) {
|
||||
continue;
|
||||
}
|
||||
itemsToUpdate.push(toUpdateItem(item));
|
||||
}
|
||||
|
||||
itemsToUpdate.push({
|
||||
userId: newItem.userId,
|
||||
teamId: newItem.teamId,
|
||||
role: newItem.role,
|
||||
permission: newItem.permission,
|
||||
});
|
||||
|
||||
await getBackendSrv().post(`/api/dashboards/id/${dashboardId}/permissions`, { items: itemsToUpdate });
|
||||
await dispatch(getDashboardPermissions(dashboardId));
|
||||
};
|
||||
}
|
||||
import { cleanUpDashboard } from './reducers';
|
||||
|
||||
export function importDashboard(data: any, dashboardTitle: string): ThunkResult<void> {
|
||||
return async (dispatch) => {
|
||||
|
||||
@@ -1,32 +1,15 @@
|
||||
import { DashboardInitPhase, DashboardState, OrgRole, PermissionLevel } from 'app/types';
|
||||
import { DashboardInitPhase, DashboardState } from 'app/types';
|
||||
|
||||
import { createDashboardModelFixture, createPanelSaveModel } from './__fixtures__/dashboardFixtures';
|
||||
import {
|
||||
dashboardInitCompleted,
|
||||
dashboardInitFailed,
|
||||
dashboardInitFetching,
|
||||
loadDashboardPermissions,
|
||||
dashboardReducer,
|
||||
initialState,
|
||||
} from './reducers';
|
||||
|
||||
describe('dashboard reducer', () => {
|
||||
describe('loadDashboardPermissions', () => {
|
||||
let state: DashboardState;
|
||||
|
||||
beforeEach(() => {
|
||||
const action = loadDashboardPermissions([
|
||||
{ id: 2, dashboardId: 1, role: OrgRole.Viewer, permission: PermissionLevel.View },
|
||||
{ id: 3, dashboardId: 1, role: OrgRole.Editor, permission: PermissionLevel.Edit },
|
||||
]);
|
||||
state = dashboardReducer(initialState, action);
|
||||
});
|
||||
|
||||
it('should add permissions to state', async () => {
|
||||
expect(state.permissions?.length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('dashboardInitCompleted', () => {
|
||||
let state: DashboardState;
|
||||
|
||||
|
||||
@@ -3,8 +3,7 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||
import { PanelPlugin } from '@grafana/data';
|
||||
import { AngularComponent } from '@grafana/runtime';
|
||||
import { defaultDashboard } from '@grafana/schema';
|
||||
import { processAclItems } from 'app/core/utils/acl';
|
||||
import { DashboardAclDTO, DashboardInitError, DashboardInitPhase, DashboardState } from 'app/types';
|
||||
import { DashboardInitError, DashboardInitPhase, DashboardState } from 'app/types';
|
||||
|
||||
import { DashboardModel } from './DashboardModel';
|
||||
import { PanelModel } from './PanelModel';
|
||||
@@ -12,7 +11,6 @@ import { PanelModel } from './PanelModel';
|
||||
export const initialState: DashboardState = {
|
||||
initPhase: DashboardInitPhase.NotStarted,
|
||||
getModel: () => null,
|
||||
permissions: [],
|
||||
initError: null,
|
||||
initialDatasource: undefined,
|
||||
};
|
||||
@@ -21,9 +19,6 @@ const dashboardSlice = createSlice({
|
||||
name: 'dashboard',
|
||||
initialState,
|
||||
reducers: {
|
||||
loadDashboardPermissions: (state, action: PayloadAction<DashboardAclDTO[]>) => {
|
||||
state.permissions = processAclItems(action.payload);
|
||||
},
|
||||
dashboardInitFetching: (state) => {
|
||||
state.initPhase = DashboardInitPhase.Fetching;
|
||||
},
|
||||
@@ -74,7 +69,6 @@ export interface SetPanelInstanceStatePayload {
|
||||
}
|
||||
|
||||
export const {
|
||||
loadDashboardPermissions,
|
||||
dashboardInitFetching,
|
||||
dashboardInitFailed,
|
||||
dashboardInitCompleted,
|
||||
|
||||
Reference in New Issue
Block a user