2019-11-04 01:37:06 +00:00
|
|
|
import { action, Action, thunk, Thunk } from 'easy-peasy';
|
|
|
|
import getSystemPermissions from '@/api/getSystemPermissions';
|
|
|
|
|
2020-03-26 04:58:37 +00:00
|
|
|
export interface PanelPermissions {
|
|
|
|
[key: string]: {
|
|
|
|
description: string;
|
|
|
|
keys: { [k: string]: string };
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-11-04 01:37:06 +00:00
|
|
|
export interface GloablPermissionsStore {
|
2020-03-26 04:58:37 +00:00
|
|
|
data: PanelPermissions;
|
|
|
|
setPermissions: Action<GloablPermissionsStore, PanelPermissions>;
|
2019-11-04 01:37:06 +00:00
|
|
|
getPermissions: Thunk<GloablPermissionsStore, void, {}, any, Promise<void>>;
|
|
|
|
}
|
|
|
|
|
|
|
|
const permissions: GloablPermissionsStore = {
|
2020-03-26 04:58:37 +00:00
|
|
|
data: {},
|
2019-11-04 01:37:06 +00:00
|
|
|
|
|
|
|
setPermissions: action((state, payload) => {
|
|
|
|
state.data = payload;
|
|
|
|
}),
|
|
|
|
|
|
|
|
getPermissions: thunk(async (actions) => {
|
|
|
|
const permissions = await getSystemPermissions();
|
|
|
|
|
|
|
|
actions.setPermissions(permissions);
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
export default permissions;
|