2019-11-04 01:37:06 +00:00
|
|
|
import { action, Action, thunk, Thunk } from 'easy-peasy';
|
2022-02-27 17:25:31 +00:00
|
|
|
import { getSystemPermissions } from '@/api/account';
|
2019-11-04 01:37:06 +00:00
|
|
|
|
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>;
|
2020-07-05 01:30:50 +00:00
|
|
|
getPermissions: Thunk<GloablPermissionsStore, void, Record<string, unknown>, any, Promise<void>>;
|
2019-11-04 01:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|