diff --git a/.betterer.results b/.betterer.results index 655d91af0bf..41d23da9f1c 100644 --- a/.betterer.results +++ b/.betterer.results @@ -1349,9 +1349,6 @@ exports[`better eslint`] = { "public/app/core/components/PasswordField/PasswordField.tsx:5381": [ [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"] ], - "public/app/core/components/PermissionList/AddPermission.tsx:5381": [ - [0, 0, 0, "Styles should be written using objects.", "0"] - ], "public/app/core/components/QueryOperationRow/OperationRowHelp.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"] ], @@ -4197,9 +4194,6 @@ exports[`better eslint`] = { "public/app/features/expressions/guards.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], - "public/app/features/folders/state/actions.test.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/features/geo/editor/GazetteerPathEditor.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"] ], diff --git a/public/app/core/components/PermissionList/AddPermission.tsx b/public/app/core/components/PermissionList/AddPermission.tsx deleted file mode 100644 index 3620fe61443..00000000000 --- a/public/app/core/components/PermissionList/AddPermission.tsx +++ /dev/null @@ -1,148 +0,0 @@ -import { css } from '@emotion/css'; -import React, { Component } from 'react'; - -import { GrafanaTheme2, SelectableValue } from '@grafana/data'; -import { Button, Form, HorizontalGroup, Select, stylesFactory } from '@grafana/ui'; -import { TeamPicker } from 'app/core/components/Select/TeamPicker'; -import { UserPicker } from 'app/core/components/Select/UserPicker'; -import config from 'app/core/config'; -import { OrgUser, Team } from 'app/types'; -import { - dashboardPermissionLevels, - dashboardAclTargets, - AclTarget, - PermissionLevel, - NewDashboardAclItem, - OrgRole, -} from 'app/types/acl'; - -import { CloseButton } from '../CloseButton/CloseButton'; - -export interface Props { - onAddPermission: (item: NewDashboardAclItem) => void; - onCancel: () => void; -} - -class AddPermissions extends Component { - static defaultProps = { - showPermissionLevels: true, - }; - - constructor(props: Props) { - super(props); - this.state = this.getCleanState(); - } - - getCleanState() { - return { - userId: 0, - teamId: 0, - role: undefined, - type: AclTarget.Team, - permission: PermissionLevel.View, - }; - } - - onTypeChanged = (item: SelectableValue) => { - const type = item.value; - - switch (type) { - case AclTarget.User: - case AclTarget.Team: - this.setState({ type: type, userId: 0, teamId: 0, role: undefined }); - break; - case AclTarget.Editor: - this.setState({ type: type, userId: 0, teamId: 0, role: OrgRole.Editor }); - break; - case AclTarget.Viewer: - this.setState({ type: type, userId: 0, teamId: 0, role: OrgRole.Viewer }); - break; - } - }; - - onUserSelected = (user: SelectableValue) => { - this.setState({ userId: user && !Array.isArray(user) ? user.id : 0 }); - }; - - onTeamSelected = (team: SelectableValue) => { - this.setState({ teamId: team.value?.id && !Array.isArray(team.value) ? team.value.id : 0 }); - }; - - onPermissionChanged = (permission: SelectableValue) => { - this.setState({ permission: permission.value! }); - }; - - onSubmit = async () => { - await this.props.onAddPermission(this.state); - this.setState(this.getCleanState()); - }; - - isValid() { - switch (this.state.type) { - case AclTarget.Team: - return this.state.teamId > 0; - case AclTarget.User: - return this.state.userId > 0; - } - return true; - } - - render() { - const { onCancel } = this.props; - const newItem = this.state; - const pickerClassName = 'min-width-20'; - const isValid = this.isValid(); - const styles = getStyles(config.theme2); - - return ( -
- -
Add Permission For
-
- {() => ( - - - - - )} -
-
- ); - } -} - -const getStyles = stylesFactory((theme: GrafanaTheme2) => ({ - label: css` - color: ${theme.colors.primary.text}; - font-weight: bold; - `, -})); - -export default AddPermissions; diff --git a/public/app/core/components/PermissionList/DisabledPermissionListItem.tsx b/public/app/core/components/PermissionList/DisabledPermissionListItem.tsx deleted file mode 100644 index ae0fd53fe35..00000000000 --- a/public/app/core/components/PermissionList/DisabledPermissionListItem.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import React, { Component } from 'react'; - -import { Select, Icon, Button } from '@grafana/ui'; -import { DashboardAcl, dashboardPermissionLevels } from 'app/types/acl'; - -export interface Props { - item: DashboardAcl; -} - -export default class DisabledPermissionListItem extends Component { - render() { - const { item } = this.props; - const currentPermissionLevel = dashboardPermissionLevels.find((dp) => dp.value === item.permission); - - return ( - - - - - - {item.name} - (Role) - - - Can - -
- - - - {!item.inherited ? ( - -
- - - - - - ); - } -} - -export const DashboardPermissions = connector(DashboardPermissionsUnconnected); diff --git a/public/app/features/dashboard/components/ShareModal/SharePublicDashboard/utilsTest.tsx b/public/app/features/dashboard/components/ShareModal/SharePublicDashboard/utilsTest.tsx index f3578f28bc2..3d2bc135502 100644 --- a/public/app/features/dashboard/components/ShareModal/SharePublicDashboard/utilsTest.tsx +++ b/public/app/features/dashboard/components/ShareModal/SharePublicDashboard/utilsTest.tsx @@ -50,7 +50,6 @@ export const renderSharePublicDashboard = async ( const store = configureStore({ dashboard: { getModel: () => props?.dashboard || mockDashboard, - permissions: [], initError: null, initPhase: DashboardInitPhase.Completed, }, diff --git a/public/app/features/dashboard/state/actions.ts b/public/app/features/dashboard/state/actions.ts index 7d449b7616f..184d9251d45 100644 --- a/public/app/features/dashboard/state/actions.ts +++ b/public/app/features/dashboard/state/actions.ts @@ -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 { - 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 { - 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 { - 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 { - 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 { return async (dispatch) => { diff --git a/public/app/features/dashboard/state/reducers.test.ts b/public/app/features/dashboard/state/reducers.test.ts index f2bd07126c5..0cb8ee5cd32 100644 --- a/public/app/features/dashboard/state/reducers.test.ts +++ b/public/app/features/dashboard/state/reducers.test.ts @@ -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; diff --git a/public/app/features/dashboard/state/reducers.ts b/public/app/features/dashboard/state/reducers.ts index 71356ec6c24..13c6d94dd32 100644 --- a/public/app/features/dashboard/state/reducers.ts +++ b/public/app/features/dashboard/state/reducers.ts @@ -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) => { - state.permissions = processAclItems(action.payload); - }, dashboardInitFetching: (state) => { state.initPhase = DashboardInitPhase.Fetching; }, @@ -74,7 +69,6 @@ export interface SetPanelInstanceStatePayload { } export const { - loadDashboardPermissions, dashboardInitFetching, dashboardInitFailed, dashboardInitCompleted, diff --git a/public/app/features/folders/FolderPermissions.tsx b/public/app/features/folders/FolderPermissions.tsx deleted file mode 100644 index e624a03a485..00000000000 --- a/public/app/features/folders/FolderPermissions.tsx +++ /dev/null @@ -1,130 +0,0 @@ -import React, { PureComponent } from 'react'; -import { connect, ConnectedProps } from 'react-redux'; - -import { Tooltip, Icon, Button } from '@grafana/ui'; -import { SlideDown } from 'app/core/components/Animations/SlideDown'; -import { Page } from 'app/core/components/Page/Page'; -import AddPermission from 'app/core/components/PermissionList/AddPermission'; -import PermissionList from 'app/core/components/PermissionList/PermissionList'; -import PermissionsInfo from 'app/core/components/PermissionList/PermissionsInfo'; -import { GrafanaRouteComponentProps } from 'app/core/navigation/types'; -import { getNavModel } from 'app/core/selectors/navModel'; -import { StoreState } from 'app/types'; -import { DashboardAcl, PermissionLevel, NewDashboardAclItem } from 'app/types/acl'; - -import { - getFolderByUid, - getFolderPermissions, - updateFolderPermission, - removeFolderPermission, - addFolderPermission, -} from './state/actions'; -import { getLoadingNav } from './state/navModel'; - -export interface OwnProps extends GrafanaRouteComponentProps<{ uid: string }> {} - -const mapStateToProps = (state: StoreState, props: OwnProps) => { - const uid = props.match.params.uid; - return { - pageNav: getNavModel(state.navIndex, `folder-permissions-${uid}`, getLoadingNav(1)), - folderUid: uid, - folder: state.folder, - }; -}; - -const mapDispatchToProps = { - getFolderByUid, - getFolderPermissions, - updateFolderPermission, - removeFolderPermission, - addFolderPermission, -}; - -const connector = connect(mapStateToProps, mapDispatchToProps); - -export type Props = OwnProps & ConnectedProps; - -export interface State { - isAdding: boolean; -} - -export class FolderPermissions extends PureComponent { - constructor(props: Props) { - super(props); - - this.state = { - isAdding: false, - }; - } - - componentDidMount() { - this.props.getFolderByUid(this.props.folderUid); - this.props.getFolderPermissions(this.props.folderUid); - } - - onOpenAddPermissions = () => { - this.setState({ isAdding: true }); - }; - - onRemoveItem = (item: DashboardAcl) => { - this.props.removeFolderPermission(item); - }; - - onPermissionChanged = (item: DashboardAcl, level: PermissionLevel) => { - this.props.updateFolderPermission(item, level); - }; - - onAddPermission = (newItem: NewDashboardAclItem) => { - return this.props.addFolderPermission(newItem); - }; - - onCancelAddPermission = () => { - this.setState({ isAdding: false }); - }; - - render() { - const { pageNav, folder } = this.props; - const { isAdding } = this.state; - - if (folder.id === 0) { - return ( - - - - - - ); - } - - const folderInfo = { title: folder.title, url: folder.url, id: folder.id }; - - return ( - - -
-

Folder Permissions

- }> - - -
- -
- - - - - - - ); - } -} - -export default connector(FolderPermissions); diff --git a/public/app/features/folders/FolderSettingsPage.test.tsx b/public/app/features/folders/FolderSettingsPage.test.tsx index 18b0e40ead8..21873f4d6dd 100644 --- a/public/app/features/folders/FolderSettingsPage.test.tsx +++ b/public/app/features/folders/FolderSettingsPage.test.tsx @@ -25,8 +25,6 @@ const setup = (propOverrides?: object) => { url: 'url', hasChanged: false, version: 1, - permissions: [], - canViewFolderPermissions: true, }, getFolderByUid: jest.fn(), setFolderTitle: mockToolkitActionCreator(setFolderTitle), diff --git a/public/app/features/folders/state/actions.test.ts b/public/app/features/folders/state/actions.test.ts deleted file mode 100644 index dd2d35e822b..00000000000 --- a/public/app/features/folders/state/actions.test.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { Observable, of, throwError } from 'rxjs'; -import { thunkTester } from 'test/core/thunk/thunkTester'; - -import { FetchResponse } from '@grafana/runtime'; -import { notifyApp } from 'app/core/actions'; -import { createWarningNotification } from 'app/core/copy/appNotification'; -import { backendSrv } from 'app/core/services/backend_srv'; - -import { checkFolderPermissions } from './actions'; -import { setCanViewFolderPermissions } from './reducers'; - -describe('folder actions', () => { - let fetchSpy: jest.SpyInstance>>; - - beforeAll(() => { - fetchSpy = jest.spyOn(backendSrv, 'fetch'); - }); - afterAll(() => { - fetchSpy.mockRestore(); - }); - - function mockFetch(resp: Observable) { - fetchSpy.mockReturnValueOnce(resp); - } - - const folderUid = 'abc123'; - - describe('checkFolderPermissions', () => { - it('should dispatch true when the api call is successful', async () => { - mockFetch(of({})); - - const dispatchedActions = await thunkTester({}) - .givenThunk(checkFolderPermissions) - .whenThunkIsDispatched(folderUid); - - expect(dispatchedActions).toEqual([setCanViewFolderPermissions(true)]); - }); - - it('should dispatch just "false" when the api call fails with 403', async () => { - mockFetch(throwError(() => ({ status: 403, data: { message: 'Access denied' } }))); - - const dispatchedActions = await thunkTester({}) - .givenThunk(checkFolderPermissions) - .whenThunkIsDispatched(folderUid); - - expect(dispatchedActions).toEqual([setCanViewFolderPermissions(false)]); - }); - - it('should also dispatch a notification when the api call fails with an error other than 403', async () => { - mockFetch(throwError(() => ({ status: 500, data: { message: 'Server error' } }))); - - const dispatchedActions = await thunkTester({}) - .givenThunk(checkFolderPermissions) - .whenThunkIsDispatched(folderUid); - - const notificationAction = notifyApp( - createWarningNotification('Error checking folder permissions', 'Server error') - ); - notificationAction.payload.id = expect.any(String); - notificationAction.payload.timestamp = expect.any(Number); - - expect(dispatchedActions).toEqual([ - expect.objectContaining(notificationAction), - setCanViewFolderPermissions(false), - ]); - }); - }); -}); diff --git a/public/app/features/folders/state/actions.ts b/public/app/features/folders/state/actions.ts index 0f08ca1cf98..3f9c869289f 100644 --- a/public/app/features/folders/state/actions.ts +++ b/public/app/features/folders/state/actions.ts @@ -1,16 +1,13 @@ -import { lastValueFrom } from 'rxjs'; - import { locationUtil } from '@grafana/data'; -import { getBackendSrv, isFetchError, locationService } from '@grafana/runtime'; +import { getBackendSrv, locationService } from '@grafana/runtime'; import { notifyApp, updateNavIndex } from 'app/core/actions'; -import { createSuccessNotification, createWarningNotification } from 'app/core/copy/appNotification'; +import { createSuccessNotification } from 'app/core/copy/appNotification'; import { contextSrv } from 'app/core/core'; import { backendSrv } from 'app/core/services/backend_srv'; import { FolderDTO, FolderState, ThunkResult } from 'app/types'; -import { DashboardAcl, DashboardAclUpdateDTO, NewDashboardAclItem, PermissionLevel } from 'app/types/acl'; import { buildNavModel } from './navModel'; -import { loadFolder, loadFolderPermissions, setCanViewFolderPermissions } from './reducers'; +import { loadFolder } from './reducers'; export function getFolderByUid(uid: string): ThunkResult> { return async (dispatch) => { @@ -41,110 +38,6 @@ export function deleteFolder(uid: string): ThunkResult { }; } -export function getFolderPermissions(uid: string): ThunkResult { - return async (dispatch) => { - const permissions = await backendSrv.get(`/api/folders/${uid}/permissions`); - dispatch(loadFolderPermissions(permissions)); - }; -} - -export function checkFolderPermissions(uid: string): ThunkResult { - return async (dispatch) => { - try { - await lastValueFrom( - backendSrv.fetch({ - method: 'GET', - showErrorAlert: false, - showSuccessAlert: false, - url: `/api/folders/${uid}/permissions`, - }) - ); - dispatch(setCanViewFolderPermissions(true)); - } catch (err) { - if (isFetchError(err) && err.status !== 403) { - dispatch(notifyApp(createWarningNotification('Error checking folder permissions', err.data?.message))); - } - - dispatch(setCanViewFolderPermissions(false)); - } - }; -} - -function toUpdateItem(item: DashboardAcl): DashboardAclUpdateDTO { - return { - userId: item.userId, - teamId: item.teamId, - role: item.role, - permission: item.permission, - }; -} - -export function updateFolderPermission(itemToUpdate: DashboardAcl, level: PermissionLevel): ThunkResult { - return async (dispatch, getStore) => { - const folder = getStore().folder; - const itemsToUpdate = []; - - for (const item of folder.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 backendSrv.post(`/api/folders/${folder.uid}/permissions`, { items: itemsToUpdate }); - await dispatch(getFolderPermissions(folder.uid)); - }; -} - -export function removeFolderPermission(itemToDelete: DashboardAcl): ThunkResult { - return async (dispatch, getStore) => { - const folder = getStore().folder; - const itemsToUpdate = []; - - for (const item of folder.permissions) { - if (item.inherited || item === itemToDelete) { - continue; - } - itemsToUpdate.push(toUpdateItem(item)); - } - - await backendSrv.post(`/api/folders/${folder.uid}/permissions`, { items: itemsToUpdate }); - await dispatch(getFolderPermissions(folder.uid)); - }; -} - -export function addFolderPermission(newItem: NewDashboardAclItem): ThunkResult { - return async (dispatch, getStore) => { - const folder = getStore().folder; - const itemsToUpdate = []; - - for (const item of folder.permissions) { - if (item.inherited) { - continue; - } - itemsToUpdate.push(toUpdateItem(item)); - } - - itemsToUpdate.push({ - userId: newItem.userId, - teamId: newItem.teamId, - role: newItem.role, - permission: newItem.permission, - }); - - await backendSrv.post(`/api/folders/${folder.uid}/permissions`, { items: itemsToUpdate }); - await dispatch(getFolderPermissions(folder.uid)); - }; -} - export function createNewFolder(folderName: string, uid?: string): ThunkResult { return async (dispatch) => { const newFolder = await getBackendSrv().post('/api/folders', { title: folderName, parentUid: uid }); diff --git a/public/app/features/folders/state/reducers.test.ts b/public/app/features/folders/state/reducers.test.ts index d6ea57ce82f..2665316f39e 100644 --- a/public/app/features/folders/state/reducers.test.ts +++ b/public/app/features/folders/state/reducers.test.ts @@ -1,15 +1,8 @@ -import { FolderDTO, FolderState, OrgRole, PermissionLevel } from 'app/types'; +import { FolderDTO, FolderState } from 'app/types'; import { reducerTester } from '../../../../test/core/redux/reducerTester'; -import { - folderReducer, - initialState, - loadFolder, - loadFolderPermissions, - setCanViewFolderPermissions, - setFolderTitle, -} from './reducers'; +import { folderReducer, initialState, loadFolder, setFolderTitle } from './reducers'; function getTestFolder(): FolderDTO { return { @@ -71,102 +64,4 @@ describe('folder reducer', () => { }); }); }); - - describe('when loadFolderPermissions is dispatched', () => { - it('then state should be correct', () => { - reducerTester() - .givenReducer(folderReducer, { ...initialState }) - .whenActionIsDispatched( - loadFolderPermissions([ - { id: 2, dashboardId: 1, role: OrgRole.Viewer, permission: PermissionLevel.View }, - { id: 3, dashboardId: 1, role: OrgRole.Editor, permission: PermissionLevel.Edit }, - { - id: 4, - dashboardId: 10, - permission: PermissionLevel.View, - teamId: 1, - team: 'MyTestTeam', - inherited: true, - }, - { - id: 5, - dashboardId: 1, - permission: PermissionLevel.View, - userId: 1, - userLogin: 'MyTestUser', - }, - { - id: 6, - dashboardId: 1, - permission: PermissionLevel.Edit, - teamId: 2, - team: 'MyTestTeam2', - }, - ]) - ) - .thenStateShouldEqual({ - ...initialState, - permissions: [ - { - dashboardId: 10, - id: 4, - inherited: true, - name: 'MyTestTeam', - permission: 1, - sortRank: 120, - team: 'MyTestTeam', - teamId: 1, - }, - { - dashboardId: 1, - icon: 'fa fa-fw fa-street-view', - id: 3, - name: 'Editor', - permission: 2, - role: OrgRole.Editor, - sortRank: 31, - }, - { - dashboardId: 1, - icon: 'fa fa-fw fa-street-view', - id: 2, - name: 'Viewer', - permission: 1, - role: OrgRole.Viewer, - sortRank: 30, - }, - { - dashboardId: 1, - id: 6, - name: 'MyTestTeam2', - permission: 2, - sortRank: 20, - team: 'MyTestTeam2', - teamId: 2, - }, - { - dashboardId: 1, - id: 5, - name: 'MyTestUser', - permission: 1, - sortRank: 10, - userId: 1, - userLogin: 'MyTestUser', - }, - ], - }); - }); - }); - - describe('setCanViewFolderPermissions', () => { - it('should set the canViewFolderPermissions value', () => { - reducerTester() - .givenReducer(folderReducer, { ...initialState }) - .whenActionIsDispatched(setCanViewFolderPermissions(true)) - .thenStateShouldEqual({ - ...initialState, - canViewFolderPermissions: true, - }); - }); - }); }); diff --git a/public/app/features/folders/state/reducers.ts b/public/app/features/folders/state/reducers.ts index 46bf07ec855..f544fde391a 100644 --- a/public/app/features/folders/state/reducers.ts +++ b/public/app/features/folders/state/reducers.ts @@ -1,8 +1,7 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'; -import { processAclItems } from 'app/core/utils/acl'; import { endpoints } from 'app/features/browse-dashboards/api/browseDashboardsAPI'; -import { DashboardAclDTO, FolderDTO, FolderState } from 'app/types'; +import { FolderDTO, FolderState } from 'app/types'; export const initialState: FolderState = { id: 0, @@ -13,8 +12,6 @@ export const initialState: FolderState = { canDelete: false, hasChanged: false, version: 1, - permissions: [], - canViewFolderPermissions: false, }; const loadFolderReducer = (state: FolderState, action: PayloadAction): FolderState => { @@ -37,23 +34,13 @@ const folderSlice = createSlice({ hasChanged: action.payload.trim().length > 0, }; }, - loadFolderPermissions: (state, action: PayloadAction): FolderState => { - return { - ...state, - permissions: processAclItems(action.payload), - }; - }, - setCanViewFolderPermissions: (state, action: PayloadAction): FolderState => { - state.canViewFolderPermissions = action.payload; - return state; - }, }, extraReducers: (builder) => { builder.addMatcher(endpoints.getFolder.matchFulfilled, loadFolderReducer); }, }); -export const { loadFolderPermissions, loadFolder, setFolderTitle, setCanViewFolderPermissions } = folderSlice.actions; +export const { loadFolder, setFolderTitle } = folderSlice.actions; export const folderReducer = folderSlice.reducer; diff --git a/public/app/types/acl.ts b/public/app/types/acl.ts index 5c9e80d71e4..c419632e955 100644 --- a/public/app/types/acl.ts +++ b/public/app/types/acl.ts @@ -9,65 +9,6 @@ export enum TeamPermissionLevel { export { OrgRole as OrgRole }; -export interface DashboardAclDTO { - id?: number; - dashboardId?: number; - userId?: number; - userLogin?: string; - userEmail?: string; - teamId?: number; - team?: string; - permission?: PermissionLevel; - role?: OrgRole; - icon?: string; - inherited?: boolean; -} - -export interface DashboardAclUpdateDTO { - userId?: number; - teamId?: number; - role?: OrgRole; - permission?: PermissionLevel; -} - -export interface DashboardAcl { - id?: number; - dashboardId?: number; - userId?: number; - userLogin?: string; - userEmail?: string; - teamId?: number; - team?: string; - permission?: PermissionLevel; - role?: OrgRole; - icon?: string; - name?: string; - inherited?: boolean; - sortRank?: number; - userAvatarUrl?: string; - teamAvatarUrl?: string; -} - -export interface DashboardPermissionInfo { - value: PermissionLevel; - label: string; - description: string; -} - -export interface NewDashboardAclItem { - teamId: number; - userId: number; - role?: OrgRole; - permission: PermissionLevel; - type: AclTarget; -} - -export enum PermissionLevel { - View = 1, - Edit = 2, - Admin = 4, -} - export enum PermissionLevelString { View = 'View', Edit = 'Edit', @@ -79,61 +20,3 @@ export enum SearchQueryType { Dashboard = 'dash-db', AlertFolder = 'dash-folder-alerting', } - -export enum DataSourcePermissionLevel { - Query = 1, - Admin = 2, -} - -export enum AclTarget { - Team = 'Team', - User = 'User', - ServiceAccount = 'ServiceAccount', - Viewer = 'Viewer', - Editor = 'Editor', -} - -export interface AclTargetInfo { - value: AclTarget; - label: string; -} - -export const dataSourceAclLevels = [ - { value: DataSourcePermissionLevel.Query, label: 'Query', description: 'Can query data source.' }, -]; - -export const dashboardAclTargets: AclTargetInfo[] = [ - { value: AclTarget.Team, label: 'Team' }, - { value: AclTarget.User, label: 'User' }, - { value: AclTarget.Viewer, label: 'Everyone With Viewer Role' }, - { value: AclTarget.Editor, label: 'Everyone With Editor Role' }, -]; - -export const dashboardPermissionLevels: DashboardPermissionInfo[] = [ - { value: PermissionLevel.View, label: PermissionLevelString.View, description: 'Can view dashboards.' }, - { - value: PermissionLevel.Edit, - label: PermissionLevelString.Edit, - description: 'Can add, edit and delete dashboards.', - }, - { - value: PermissionLevel.Admin, - label: 'Admin', - description: 'Can add/remove permissions and can add, edit and delete dashboards.', - }, -]; - -export interface TeamPermissionInfo { - value: TeamPermissionLevel; - label: string; - description: string; -} - -export const teamsPermissionLevels: TeamPermissionInfo[] = [ - { value: TeamPermissionLevel.Member, label: 'Member', description: 'Is team member' }, - { - value: TeamPermissionLevel.Admin, - label: 'Admin', - description: 'Can add/remove permissions, members and delete team.', - }, -]; diff --git a/public/app/types/dashboard.ts b/public/app/types/dashboard.ts index 73540389d23..8a37867ab97 100644 --- a/public/app/types/dashboard.ts +++ b/public/app/types/dashboard.ts @@ -2,8 +2,6 @@ import { DataQuery } from '@grafana/data'; import { Dashboard, DataSourceRef } from '@grafana/schema'; import { DashboardModel } from 'app/features/dashboard/state/DashboardModel'; -import { DashboardAcl } from './acl'; - export interface DashboardDTO { redirectUri?: string; dashboard: DashboardDataDTO; @@ -112,5 +110,4 @@ export interface DashboardState { initPhase: DashboardInitPhase; initialDatasource?: DataSourceRef['uid']; initError: DashboardInitError | null; - permissions: DashboardAcl[]; } diff --git a/public/app/types/folders.ts b/public/app/types/folders.ts index 2b79f57042e..6c80fe7ca0f 100644 --- a/public/app/types/folders.ts +++ b/public/app/types/folders.ts @@ -1,7 +1,5 @@ import { WithAccessControlMetadata } from '@grafana/data'; -import { DashboardAcl } from './acl'; - export interface FolderDTO extends WithAccessControlMetadata { canAdmin: boolean; canDelete: boolean; @@ -30,8 +28,6 @@ export interface FolderState { canDelete: boolean; hasChanged: boolean; version: number; - permissions: DashboardAcl[]; - canViewFolderPermissions: boolean; } export interface DescendantCountDTO { @@ -57,5 +53,4 @@ export interface FolderInfo { uid?: string; title?: string; url?: string; - canViewFolderPermissions?: boolean; }