Files
CommunitySolidServer/src/authorization/AllStaticReader.ts
Joachim Van Herwegen 6248ed0938 refactor: Replace linting configurations
The previous package was outdated, preventing us from updating TS.
This one also lints YAML and JSON,
and applies many more rules to the test files,
explaining all the changes in this PR.
2023-11-02 09:49:17 +01:00

32 lines
1.0 KiB
TypeScript

import { IdentifierMap } from '../util/map/IdentifierMap';
import type { PermissionReaderInput } from './PermissionReader';
import { PermissionReader } from './PermissionReader';
import type { PermissionMap, PermissionSet } from './permissions/Permissions';
/**
* PermissionReader which sets all permissions to true or false
* independently of the identifier and requested permissions.
*/
export class AllStaticReader extends PermissionReader {
private readonly permissionSet: PermissionSet;
public constructor(allow: boolean) {
super();
this.permissionSet = Object.freeze({
read: allow,
write: allow,
append: allow,
create: allow,
delete: allow,
});
}
public async handle({ requestedModes }: PermissionReaderInput): Promise<PermissionMap> {
const availablePermissions = new IdentifierMap<PermissionSet>();
for (const [ identifier ] of requestedModes) {
availablePermissions.set(identifier, this.permissionSet);
}
return availablePermissions;
}
}