Files
calendar/packages/platform/utils/permissions.ts
T
Eunjae LeeGitHubDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
357c2882ad refactor: apply biome formatting to several packages (#27439)
* refactor: apply biome formatting to Phase 1 packages

Packages formatted:
- packages/app-store-cli
- packages/config
- packages/dayjs
- packages/debugging
- packages/embeds/embed-react
- packages/embeds/embed-snippet
- packages/kysely
- packages/platform/constants
- packages/platform/utils
- packages/testing
- packages/tsconfig

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>

* fix: restore non-null assertions in embed-snippet to fix type error

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>

* fix: remove ESM import from CommonJS config file

Biome incorrectly added 'import process from node:process' to a CommonJS
file that uses require(). This breaks Jest which expects CommonJS syntax.
The process global is already available in Node.js without explicit import.

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>

* refactor: exclude packages/embeds from Phase 1 formatting

Per user request, reverting all biome formatting changes in packages/embeds
to handle separately.

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>

* fix: restore const enum for BookingLocations

Biome changed 'const enum' to 'enum' which is a semantic change.
Reverting to keep the PR purely formatting-only.

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-02-05 07:24:34 -03:00

74 lines
2.4 KiB
TypeScript

import {
APPS_READ,
APPS_WRITE,
BOOKING_READ,
BOOKING_WRITE,
EVENT_TYPE_READ,
EVENT_TYPE_WRITE,
PERMISSIONS,
PROFILE_READ,
PROFILE_WRITE,
SCHEDULE_READ,
SCHEDULE_WRITE,
} from "@calcom/platform-constants";
import type { PLATFORM_PERMISSION } from "@calcom/platform-types";
export const hasPermission = (userPermissions: number, permission: PLATFORM_PERMISSION): boolean => {
// use bitwise AND to check if user has the permission
return (userPermissions & permission) === permission;
};
export const hasPermissions = (userPermissions: number, permissions: PLATFORM_PERMISSION[]): boolean => {
// use bitwise AND to check if each required permission is present
return permissions.every((permission) => hasPermission(userPermissions, permission));
};
export const hasEventTypeReadPermission = (userPermissions: number): boolean => {
return hasPermission(userPermissions, EVENT_TYPE_READ);
};
export const hasEventTypeWritePermission = (userPermissions: number): boolean => {
return hasPermission(userPermissions, EVENT_TYPE_WRITE);
};
export const hasBookingReadPermission = (userPermissions: number): boolean => {
return hasPermission(userPermissions, BOOKING_READ);
};
export const hasBookingWritePermission = (userPermissions: number): boolean => {
return hasPermission(userPermissions, BOOKING_WRITE);
};
export const hasScheduleReadPermission = (userPermissions: number): boolean => {
return hasPermission(userPermissions, SCHEDULE_READ);
};
export const hasScheduleWritePermission = (userPermissions: number): boolean => {
return hasPermission(userPermissions, SCHEDULE_WRITE);
};
export const hasAppsReadPermission = (userPermissions: number): boolean => {
return hasPermission(userPermissions, APPS_READ);
};
export const hasAppsWritePermission = (userPermissions: number): boolean => {
return hasPermission(userPermissions, APPS_WRITE);
};
export const hasProfileReadPermission = (userPermissions: number): boolean => {
return hasPermission(userPermissions, PROFILE_READ);
};
export const hasProfileWritePermission = (userPermissions: number): boolean => {
return hasPermission(userPermissions, PROFILE_WRITE);
};
export const listPermissions = (userPermissions: number): PLATFORM_PERMISSION[] => {
return PERMISSIONS.reduce((acc, permission) => {
if (hasPermission(userPermissions, permission)) {
return [...acc, permission];
}
return acc;
}, [] as PLATFORM_PERMISSION[]);
};