-
Notifications
You must be signed in to change notification settings - Fork 1
/
access.ts
36 lines (33 loc) · 1.06 KB
/
access.ts
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
31
32
33
34
35
36
import { ListAccessArgs } from './types';
/*
The basic level of access to the system is being signed in as a valid user. This gives you access
to the Admin UI, access to your own User and other schema items, and read access to roles.
*/
export const isSignedIn = ({ session }: ListAccessArgs) => {
return !!session;
};
/*
Permissions are shorthand functions for checking that the current user's role has the specified
permission boolean set to true
*/
export const permissions = {
isAdmin: ({ session }: ListAccessArgs) => !!session?.data.isAdmin,
};
/*
Rules are logical functions that can be used for list access, and may return a boolean (meaning
all or no items are available) or a set of filters that limit the available items
*/
export const rules = {
canUpdateUsers: ({ session }: ListAccessArgs) => {
if (!session) {
// No session? No Users.
return false;
} else if (session.data.isAdmin) {
// Can update everyone
return true;
} else {
// Can update yourself
return { id: session.itemId };
}
},
};