Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / shared / lib / helpers / organization.ts
bloba6f375156528f59e4c292c83f9097edfc238d9cf
1 import { ORGANIZATION_FLAGS, ORGANIZATION_TWOFA_SETTING } from '../constants';
2 import type { Organization } from '../interfaces';
3 import { hasBit } from './bitset';
5 export const isLoyal = (organization: Partial<Organization> = {}) => {
6     return hasBit(organization.Flags, ORGANIZATION_FLAGS.LOYAL);
7 };
9 export const hasCovid = (organization: Partial<Organization> = {}) => {
10     return hasBit(organization.Flags, ORGANIZATION_FLAGS.COVID);
13 export const hasSMTPSubmission = (organization: Partial<Organization> = {}) => {
14     return hasBit(organization.Flags, ORGANIZATION_FLAGS.SMTP_SUBMISSION);
17 export const isDissident = (organization: Partial<Organization> = {}) => {
18     return hasBit(organization.Flags, ORGANIZATION_FLAGS.DISSIDENT);
21 export const hasNoCycleScheduled = (organization: Partial<Organization> = {}) => {
22     return hasBit(organization.Flags, ORGANIZATION_FLAGS.NO_CYCLE_SCHEDULED);
25 export const isProtoneer = (organization: Partial<Organization> = {}) => {
26     return hasBit(organization.Flags, ORGANIZATION_FLAGS.PROTON);
29 export const hasPhoneSupport = (organization: Partial<Organization> = {}) => {
30     return hasBit(organization.Flags, ORGANIZATION_FLAGS.PHONE_SUPPORT);
33 export const hasToMigrateOrgKey = (organization: Partial<Organization> = {}) => {
34     return hasBit(organization.Flags, ORGANIZATION_FLAGS.TO_MIGRATE_ORG_KEY);
37 export const hasDeletionWhitelisted = (organization: Partial<Organization> = {}) => {
38     return hasBit(organization.Flags, ORGANIZATION_FLAGS.DELETION_WHITELISTED);
41 export const hasBonuses = (organization: Partial<Organization> = {}) => {
42     return !!organization.Flags || !!organization.LoyaltyCounter;
45 export const hasTwoFARequiredForAdminOnly = (organization: Partial<Organization> = {}) => {
46     return organization.TwoFactorRequired === ORGANIZATION_TWOFA_SETTING.REQUIRED_ADMIN_ONLY;
49 export const hasTwoFARequiredForAll = (organization: Partial<Organization> = {}) => {
50     return organization.TwoFactorRequired === ORGANIZATION_TWOFA_SETTING.REQUIRED_ALL;
53 export const hasFlag = (organization: Partial<Organization> = {}, mask: number) => {
54     return hasBit(Number(organization.Flags), Number(mask));
57 export const hasPermission = (organization: Partial<Organization> = {}, mask: number) => {
58     return hasBit(Number(organization.Permissions), Number(mask));
61 export const hasOrganizationSetup = (organization: Partial<Organization> = {}) => {
62     return !organization.RequiresKey && !!organization.Name;
65 export const hasOrganizationSetupWithKeys = (organization: Partial<Organization> = {}) => {
66     return !!organization.RequiresKey && !!organization.HasKeys;