-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvalidate-permissions.ts
30 lines (28 loc) · 1.02 KB
/
validate-permissions.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
import type { Client } from '../models';
import type { ExerciseState } from '../state';
import type { ExerciseAction } from './action-reducers';
import { getExerciseActionTypeDictionary } from './action-reducers/action-reducers';
const exerciseActionTypeDictionary = getExerciseActionTypeDictionary();
/**
*
* @param client The {@link Client} that proposed the {@link action}.
* @param action The {@link ExerciseAction} that got proposed.
* @param state The current {@link ExerciseState} before the {@link action} gets applied.
* @returns true when the {@link action} can be applied, false otherwise.
*/
export function validatePermissions(
client: Client,
action: ExerciseAction,
state: ExerciseState
) {
const rights = exerciseActionTypeDictionary[action.type].rights;
// Check role permissions
if (
(client.role === 'participant' && rights !== 'participant') ||
rights === 'server'
) {
return false;
}
// TODO: Validate e.g. only actions in own viewport
return true;
}