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);
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> = {}) => {
52 if (isLoyal(organization)) {
55 if (hasCovid(organization)) {
58 if (hasSMTPSubmission(organization)) {
59 flags.push('SMTP Submission');
61 if (isDissident(organization)) {
62 flags.push('Dissident');
64 if (hasNoCycleScheduled(organization)) {
65 flags.push('No Cycle Scheduled');
67 if (isProtoneer(organization)) {
70 if (hasPhoneSupport(organization)) {
71 flags.push('Phone Support');
73 if (hasToMigrateOrgKey(organization)) {
74 flags.push('Passwordless migration enabled');
77 return flags.length > 0 ? flags.join(', ') : '-';
80 export const humanReadablePermissions = (organization: Partial<Organization> = {}) => {
83 if (hasBit(organization.Permissions, MEMBER_PERMISSIONS.MANAGE_FORWARDING)) {
84 permissions.push('Forwarding');
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;