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