-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.ts
More file actions
30 lines (27 loc) · 1001 Bytes
/
index.ts
File metadata and controls
30 lines (27 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { can, cannot, has, hasnt } from './lib/Directives';
import type { App } from '@vue/runtime-core';
import type { Config, Directives } from '../types/config';
import ACL from './lib/ACL';
const defaults: Required<Config> = {
roles: [],
permissions: [],
forceRemove: false,
accessor: '$vacl',
directives: {
can: 'can',
cannot: 'cannot',
has: 'has',
hasnt: 'hasnt'
} as Required<Directives>
};
export default {
install: (app: App, options?: Config): void => {
const directives = { ...defaults.directives, ...Object(options?.directives) };
const acl = app.config.globalProperties[options?.accessor ?? defaults.accessor] = new ACL(options);
app.directive(directives.can, can(acl));
app.directive(directives.cannot, cannot(acl));
app.directive(directives.has, has(acl));
app.directive(directives.hasnt, hasnt(acl));
}
};