-
Notifications
You must be signed in to change notification settings - Fork 121
/
AllStaticReader.ts
32 lines (29 loc) · 1016 Bytes
/
AllStaticReader.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
import type { CredentialGroup } from '../authentication/Credentials';
import type { Permission, PermissionSet } from '../ldp/permissions/Permissions';
import type { PermissionReaderInput } from './PermissionReader';
import { PermissionReader } from './PermissionReader';
/**
* PermissionReader which sets all permissions to true or false
* independently of the identifier and requested permissions.
*/
export class AllStaticReader extends PermissionReader {
private readonly permissions: Permission;
public constructor(allow: boolean) {
super();
this.permissions = Object.freeze({
read: allow,
write: allow,
append: allow,
control: allow,
});
}
public async handle({ credentials }: PermissionReaderInput): Promise<PermissionSet> {
const result: PermissionSet = {};
for (const [ key, value ] of Object.entries(credentials) as [CredentialGroup, Permission][]) {
if (value) {
result[key] = this.permissions;
}
}
return result;
}
}