Use same lock values as mobile clients
[ProtonMail-WebClient.git] / packages / shared / lib / helpers / organization.ts
blobcade50a71ac2bf6aa81b3eda97af6c229a352978
1 import { MEMBER_PERMISSIONS, 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 hasBonuses = (organization: Partial<Organization> = {}) => {
38     return !!organization.Flags || !!organization.LoyaltyCounter;
41 export const hasTwoFARequiredForAdminOnly = (organization: Partial<Organization> = {}) => {
42     return organization.TwoFactorRequired === ORGANIZATION_TWOFA_SETTING.REQUIRED_ADMIN_ONLY;
45 export const hasTwoFARequiredForAll = (organization: Partial<Organization> = {}) => {
46     return organization.TwoFactorRequired === ORGANIZATION_TWOFA_SETTING.REQUIRED_ALL;
49 export const humanReadableFlags = (organization: Partial<Organization> = {}) => {
50     let flags = [];
52     if (isLoyal(organization)) {
53         flags.push('Loyal');
54     }
55     if (hasCovid(organization)) {
56         flags.push('Covid');
57     }
58     if (hasSMTPSubmission(organization)) {
59         flags.push('SMTP Submission');
60     }
61     if (isDissident(organization)) {
62         flags.push('Dissident');
63     }
64     if (hasNoCycleScheduled(organization)) {
65         flags.push('No Cycle Scheduled');
66     }
67     if (isProtoneer(organization)) {
68         flags.push('Proton');
69     }
70     if (hasPhoneSupport(organization)) {
71         flags.push('Phone Support');
72     }
73     if (hasToMigrateOrgKey(organization)) {
74         flags.push('Passwordless migration enabled');
75     }
77     return flags.length > 0 ? flags.join(', ') : '-';
80 export const humanReadablePermissions = (organization: Partial<Organization> = {}) => {
81     let permissions = [];
83     if (hasBit(organization.Permissions, MEMBER_PERMISSIONS.MANAGE_FORWARDING)) {
84         permissions.push('Forwarding');
85     }
87     return permissions.length > 0 ? permissions.join(', ') : '-';
90 export const hasFlag = (organization: Partial<Organization> = {}, mask: number) => {
91     return hasBit(Number(organization.Flags), Number(mask));
94 export const hasPermission = (organization: Partial<Organization> = {}, mask: number) => {
95     return hasBit(Number(organization.Permissions), Number(mask));
98 export const hasOrganizationSetup = (organization: Partial<Organization> = {}) => {
99     return !organization.RequiresKey && !!organization.Name;
102 export const hasOrganizationSetupWithKeys = (organization: Partial<Organization> = {}) => {
103     return !!organization.RequiresKey && !!organization.HasKeys;