fix: add permission fixes

pull/13278/head
Torkel Ödegaard 7 years ago
parent 776d81189f
commit 331be7d47a
  1. 26
      public/app/core/components/PermissionList/AddPermission.tsx
  2. 24
      public/app/features/dashboard/state/reducers.test.ts
  3. 2
      public/app/types/acl.ts

@ -26,28 +26,34 @@ class AddPermissions extends Component<Props, NewDashboardAclItem> {
return { return {
userId: 0, userId: 0,
teamId: 0, teamId: 0,
role: OrgRole.Viewer,
type: AclTarget.Team, type: AclTarget.Team,
permission: PermissionLevel.View, permission: PermissionLevel.View,
}; };
} }
onTypeChanged = evt => { onTypeChanged = evt => {
this.setState({ type: evt.target.value as AclTarget }); const type = evt.target.value as AclTarget;
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: User) => { onUserSelected = (user: User) => {
this.setState({ this.setState({ userId: user ? user.id : 0 });
userId: user ? user.id : 0,
teamId: 0,
});
}; };
onTeamSelected = (team: Team) => { onTeamSelected = (team: Team) => {
this.setState({ this.setState({ teamId: team ? team.id : 0 });
userId: 0,
teamId: team ? team.id : 0,
});
}; };
onPermissionChanged = (permission: OptionWithDescription) => { onPermissionChanged = (permission: OptionWithDescription) => {

@ -0,0 +1,24 @@
import { Action, ActionTypes } from './actions';
import { OrgRole, PermissionLevel, DashboardState } from 'app/types';
import { inititalState, dashboardReducer } from './reducers';
describe('dashboard reducer', () => {
describe('loadDashboardPermissions', () => {
let state: DashboardState;
beforeEach(() => {
const action: Action = {
type: ActionTypes.LoadDashboardPermissions,
payload: [
{ id: 2, dashboardId: 1, role: OrgRole.Viewer, permission: PermissionLevel.View },
{ id: 3, dashboardId: 1, role: OrgRole.Editor, permission: PermissionLevel.Edit },
],
};
state = dashboardReducer(inititalState, action);
});
it('should add permissions to state', async () => {
expect(state.permissions.length).toBe(2);
});
});
});

@ -50,7 +50,7 @@ export interface DashboardPermissionInfo {
export interface NewDashboardAclItem { export interface NewDashboardAclItem {
teamId: number; teamId: number;
userId: number; userId: number;
role: OrgRole; role?: OrgRole;
permission: PermissionLevel; permission: PermissionLevel;
type: AclTarget; type: AclTarget;
} }

Loading…
Cancel
Save