-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcanPerformAction.ts
More file actions
26 lines (23 loc) · 829 Bytes
/
canPerformAction.ts
File metadata and controls
26 lines (23 loc) · 829 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
import { User } from '@sentry/react'
import { UserType } from '../entities/user'
export enum PermissionBasedAction {
DELETE_LEADERBOARD,
DELETE_STAT,
DELETE_GROUP,
DELETE_FEEDBACK_CATEGORY,
VIEW_PLAYER_AUTH_ACTIVITIES,
UPDATE_PLAYER_STAT
}
export default function canPerformAction(user: User, action: PermissionBasedAction) {
if (user.type === UserType.OWNER) return true
switch (action) {
case PermissionBasedAction.DELETE_LEADERBOARD:
case PermissionBasedAction.DELETE_STAT:
case PermissionBasedAction.DELETE_FEEDBACK_CATEGORY:
case PermissionBasedAction.VIEW_PLAYER_AUTH_ACTIVITIES:
case PermissionBasedAction.UPDATE_PLAYER_STAT:
return user.type === UserType.ADMIN
case PermissionBasedAction.DELETE_GROUP:
return [UserType.DEV, UserType.ADMIN].includes(user.type)
}
}