Merge branch 'IDTEAM-1.26.0' into 'main'
[ProtonMail-WebClient.git] / packages / shared / lib / drive / permissions.ts
blob5182a7a77864d35290341f52f42f15cd0aad4a6b
1 import { hasBit } from '@proton/shared/lib/helpers/bitset';
3 // This is deprecated, so we don't put it in enum SHARE_MEMBER_PERMISSIONS
4 const EXEC = 1;
6 export enum DRIVE_PERMISSIONS {
7     READ = 4,
8     WRITE = 2,
9     ADMIN = 16,
10     SUPER_ADMIN = 32,
13 const { READ, WRITE, ADMIN, SUPER_ADMIN } = DRIVE_PERMISSIONS;
15 export enum SHARE_URL_PERMISSIONS {
16     VIEWER = READ,
17     EDITOR = WRITE + READ,
20 export enum SHARE_MEMBER_PERMISSIONS {
21     OWNER = EXEC + READ + WRITE + ADMIN + SUPER_ADMIN,
22     VIEWER = READ,
23     EDITOR = WRITE + READ,
24     ADMIN_EDITOR = WRITE + READ + ADMIN,
27 export const getCanWrite = (permissions: SHARE_MEMBER_PERMISSIONS | SHARE_URL_PERMISSIONS) => {
28     return hasBit(permissions, DRIVE_PERMISSIONS.WRITE);
31 export const getCanAdmin = (permissions: SHARE_MEMBER_PERMISSIONS) => {
32     return hasBit(permissions, DRIVE_PERMISSIONS.ADMIN);
35 export const getIsOwner = (permissions: SHARE_MEMBER_PERMISSIONS) => {
36     return permissions === SHARE_MEMBER_PERMISSIONS.OWNER;