mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
dashfolders: use react component for dashboard permissions
Switch out the angular component for the new react component on the dashboard permissions editview on the settings page.
This commit is contained in:
@@ -11,12 +11,11 @@ describe('PermissionsStore', () => {
|
||||
{ id: 3, dashboardId: 1, role: 'Editor', permission: 1, permissionName: 'Edit' },
|
||||
{
|
||||
id: 4,
|
||||
dashboardId: 1,
|
||||
userId: 2,
|
||||
userLogin: 'danlimerick',
|
||||
userEmail: 'dan.limerick@gmail.com',
|
||||
permission: 4,
|
||||
permissionName: 'Admin',
|
||||
dashboardId: 10,
|
||||
permission: 1,
|
||||
permissionName: 'View',
|
||||
teamId: 1,
|
||||
teamName: 'MyTestTeam',
|
||||
},
|
||||
])
|
||||
);
|
||||
@@ -33,7 +32,7 @@ describe('PermissionsStore', () => {
|
||||
}
|
||||
);
|
||||
|
||||
return store.load(1, true);
|
||||
return store.load(1, false);
|
||||
});
|
||||
|
||||
it('should save update on permission change', () => {
|
||||
@@ -72,4 +71,78 @@ describe('PermissionsStore', () => {
|
||||
expect(backendSrv.post.mock.calls.length).toBe(1);
|
||||
expect(backendSrv.post.mock.calls[0][0]).toBe('/api/dashboards/id/1/acl');
|
||||
});
|
||||
|
||||
describe('when duplicate user permissions are added', () => {
|
||||
beforeEach(() => {
|
||||
const newItem = {
|
||||
userId: 10,
|
||||
userLogin: 'tester1',
|
||||
permission: 1,
|
||||
};
|
||||
store.addStoreItem(newItem);
|
||||
store.addStoreItem(newItem);
|
||||
});
|
||||
|
||||
it('should return a validation error', () => {
|
||||
expect(store.items.length).toBe(4);
|
||||
expect(store.error).toBe('This permission exists already.');
|
||||
expect(backendSrv.post.mock.calls.length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when duplicate team permissions are added', () => {
|
||||
beforeEach(() => {
|
||||
const newItem = {
|
||||
teamId: 1,
|
||||
teamName: 'testerteam',
|
||||
permission: 1,
|
||||
};
|
||||
store.addStoreItem(newItem);
|
||||
store.addStoreItem(newItem);
|
||||
});
|
||||
|
||||
it('should return a validation error', () => {
|
||||
expect(store.items.length).toBe(4);
|
||||
expect(store.error).toBe('This permission exists already.');
|
||||
expect(backendSrv.post.mock.calls.length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when duplicate role permissions are added', () => {
|
||||
beforeEach(() => {
|
||||
const newItem = {
|
||||
team: 'MyTestTeam',
|
||||
teamId: 1,
|
||||
permission: 1,
|
||||
};
|
||||
store.addStoreItem(newItem);
|
||||
store.addStoreItem(newItem);
|
||||
});
|
||||
|
||||
it('should return a validation error', () => {
|
||||
expect(store.items.length).toBe(4);
|
||||
expect(store.error).toBe('This permission exists already.');
|
||||
expect(backendSrv.post.mock.calls.length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when one inherited and one not inherited team permission are added', () => {
|
||||
beforeEach(() => {
|
||||
const teamItem = {
|
||||
team: 'MyTestTeam',
|
||||
dashboardId: 1,
|
||||
teamId: 1,
|
||||
permission: 2,
|
||||
};
|
||||
store.addStoreItem(teamItem);
|
||||
});
|
||||
|
||||
it('should not throw a validation error', () => {
|
||||
expect(store.error).toBe(null);
|
||||
});
|
||||
|
||||
it('should add both permissions', () => {
|
||||
expect(store.items.length).toBe(4);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -57,12 +57,12 @@ export const PermissionsStore = types
|
||||
}
|
||||
|
||||
self.items.push(prepareItem(item, self.dashboardId, self.isFolder));
|
||||
updateItems(self);
|
||||
return updateItems(self);
|
||||
}),
|
||||
removeStoreItem: flow(function* removeStoreItem(idx: number) {
|
||||
self.error = null;
|
||||
self.items.splice(idx, 1);
|
||||
updateItems(self);
|
||||
return updateItems(self);
|
||||
}),
|
||||
updatePermissionOnIndex: flow(function* updatePermissionOnIndex(
|
||||
idx: number,
|
||||
@@ -71,7 +71,7 @@ export const PermissionsStore = types
|
||||
) {
|
||||
self.error = null;
|
||||
self.items[idx].updatePermission(permission, permissionName);
|
||||
updateItems(self);
|
||||
return updateItems(self);
|
||||
}),
|
||||
setNewType(newType: string) {
|
||||
self.newType = newType;
|
||||
@@ -118,8 +118,7 @@ const prepareServerResponse = (response, dashboardId: number, isFolder: boolean)
|
||||
};
|
||||
|
||||
const prepareItem = (item, dashboardId: number, isFolder: boolean) => {
|
||||
item.inherited = !isFolder && dashboardId !== item.dashboardId;
|
||||
|
||||
item.inherited = !isFolder && item.dashboardId > 0 && dashboardId !== item.dashboardId;
|
||||
item.sortRank = 0;
|
||||
if (item.userId > 0) {
|
||||
item.icon = 'fa fa-fw fa-user';
|
||||
|
||||
Reference in New Issue
Block a user