Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,7 @@ const translations: TranslationDeepObject<typeof en> = {
},
newContactMethod: 'Neue Kontaktmethode',
goBackContactMethods: 'Zurück zu den Kontaktmethoden',
yourDefaultContactMethodRestrictedSwitch: 'Dies ist Ihre derzeitige standardmäßige Kontaktmethode. Ihr Unternehmen hat das Entfernen oder Ändern eingeschränkt.',
},
pronouns: {
coCos: 'Co / Cos',
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1779,6 +1779,7 @@ const translations = {
enterMagicCode: (contactMethod: string) => `Please enter the magic code sent to ${contactMethod}. It should arrive within a minute or two.`,
setAsDefault: 'Set as default',
yourDefaultContactMethod: "This is your current default contact method. Before you can delete it, you'll need to choose another contact method and click “Set as default”.",
yourDefaultContactMethodRestrictedSwitch: 'This is your current default contact method. Your company has restricted removing or changing it.',
removeContactMethod: 'Remove contact method',
removeAreYouSure: "Are you sure you want to remove this contact method? This action can't be undone.",
failedNewContact: 'Failed to add this contact method.',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,7 @@ const translations: TranslationDeepObject<typeof en> = {
setAsDefault: 'Establecer como predeterminado',
yourDefaultContactMethod:
'Este es tu método de contacto predeterminado. Antes de poder eliminarlo, tendrás que elegir otro método de contacto y haz clic en "Establecer como predeterminado".',
yourDefaultContactMethodRestrictedSwitch: 'Este es tu método de contacto predeterminado actual. Tu empresa ha restringido su eliminación o modificación.',
removeContactMethod: 'Eliminar método de contacto',
removeAreYouSure: '¿Estás seguro de que quieres eliminar este método de contacto? Esta acción no se puede deshacer.',
failedNewContact: 'Se ha producido un error al añadir este método de contacto.',
Expand Down
1 change: 1 addition & 0 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1764,6 +1764,7 @@ const translations: TranslationDeepObject<typeof en> = {
},
newContactMethod: 'Nouveau moyen de contact',
goBackContactMethods: 'Revenir aux méthodes de contact',
yourDefaultContactMethodRestrictedSwitch: 'Ceci est votre méthode de contact par défaut actuelle. Votre entreprise a restreint sa suppression ou sa modification.',
},
pronouns: {
coCos: 'Copropriétaire / Cosigner',
Expand Down
1 change: 1 addition & 0 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,7 @@ const translations: TranslationDeepObject<typeof en> = {
},
newContactMethod: 'Nuovo metodo di contatto',
goBackContactMethods: 'Torna ai metodi di contatto',
yourDefaultContactMethodRestrictedSwitch: 'Questo è il tuo metodo di contatto predefinito attuale. La tua azienda ne ha limitato la rimozione o la modifica.',
},
pronouns: {
coCos: 'Co / Cos',
Expand Down
1 change: 1 addition & 0 deletions src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,7 @@ const translations: TranslationDeepObject<typeof en> = {
},
newContactMethod: '新しい連絡方法',
goBackContactMethods: '連絡方法に戻る',
yourDefaultContactMethodRestrictedSwitch: 'これは現在のデフォルトの連絡方法です。会社により、これを削除または変更することは制限されています。',
},
pronouns: {
coCos: '会社 / コスト',
Expand Down
1 change: 1 addition & 0 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,7 @@ const translations: TranslationDeepObject<typeof en> = {
},
newContactMethod: 'Nieuwe contactmethode',
goBackContactMethods: 'Ga terug naar contactmethoden',
yourDefaultContactMethodRestrictedSwitch: 'Dit is je huidige standaardcontactmethode. Je bedrijf heeft beperkt dat je deze kunt verwijderen of wijzigen.',
},
pronouns: {
coCos: 'Co / Cos',
Expand Down
1 change: 1 addition & 0 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,7 @@ const translations: TranslationDeepObject<typeof en> = {
},
newContactMethod: 'Nowy sposób kontaktu',
goBackContactMethods: 'Wróć do metod kontaktu',
yourDefaultContactMethodRestrictedSwitch: 'To jest Twoja domyślna metoda kontaktu. Twoja firma zablokowała możliwość usuwania lub zmiany tej metody.',
},
pronouns: {
coCos: 'Co / Coś',
Expand Down
1 change: 1 addition & 0 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1749,6 +1749,7 @@ const translations: TranslationDeepObject<typeof en> = {
},
newContactMethod: 'Novo método de contato',
goBackContactMethods: 'Voltar para métodos de contato',
yourDefaultContactMethodRestrictedSwitch: 'Este é seu método de contato padrão atual. Sua empresa restringiu a remoção ou alteração dele.',
},
pronouns: {
coCos: 'Co / Cos',
Expand Down
1 change: 1 addition & 0 deletions src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,7 @@ const translations: TranslationDeepObject<typeof en> = {
},
newContactMethod: '新联系方式',
goBackContactMethods: '返回联系方式',
yourDefaultContactMethodRestrictedSwitch: '这是你当前的默认联系方式。你的公司已限制移除或更改它。',
},
pronouns: {
coCos: '公司/成本',
Expand Down
54 changes: 36 additions & 18 deletions src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,35 @@ function ContactMethodDetailsPage({route}: ContactMethodDetailsPageProps) {
}, [currentUserPersonalDetails, contactMethod, formatPhoneNumber, backTo]);

/**
* Checks if the user is allowed to change their default contact method. This should only be allowed if:
* 1. The viewed contact method is not already their default contact method
* 2. The viewed contact method is validated
* 3. If the user is on a private domain, their security group must allow primary login switching
* Determines whether the user's primary login switching is restricted
* by their domain security group.
*
* If:
* - The user does not belong to a private domain security group → NOT restricted.
* - The security group exists and has `enableRestrictedPrimaryLogin` enabled → restricted.
*/
const isRestrictedDefaultContactMethodSwitch = useMemo(() => {
const domainName = Str.extractEmailDomain(session?.email ?? '');
const primaryDomainSecurityGroupID = myDomainSecurityGroups?.[domainName];

// If there's no security group associated with the user for the primary domain,
// default to NOT restricting the user from switching their default contact method.
if (!primaryDomainSecurityGroupID) {
return false;
}

/// Restrict the user from switching their default contact method if their security group
// restricts primary login switching.
return !!securityGroups?.[`${ONYXKEYS.COLLECTION.SECURITY_GROUP}${primaryDomainSecurityGroupID}`]?.enableRestrictedPrimaryLogin;
}, [session?.email, myDomainSecurityGroups, securityGroups]);

/**
* Checks if the user is allowed to change their default contact method.
*
* This is allowed only if:
* 1. The viewed contact method is NOT already their default contact method.
* 2. The viewed contact method is validated.
* 3. The user's domain security group does NOT restrict primary login switching.
*/
const canChangeDefaultContactMethod = useMemo(() => {
// Cannot set this contact method as default if:
Expand All @@ -107,19 +132,10 @@ function ContactMethodDetailsPage({route}: ContactMethodDetailsPageProps) {
return false;
}

const domainName = Str.extractEmailDomain(session?.email ?? '');
const primaryDomainSecurityGroupID = myDomainSecurityGroups?.[domainName];

// If there's no security group associated with the user for the primary domain,
// default to allowing the user to change their default contact method.
if (!primaryDomainSecurityGroupID) {
return true;
}

// Allow user to change their default contact method if they don't have a security group OR if their security group
// does NOT restrict primary login switching.
return !securityGroups?.[`${ONYXKEYS.COLLECTION.SECURITY_GROUP}${primaryDomainSecurityGroupID}`]?.enableRestrictedPrimaryLogin;
}, [isDefaultContactMethod, loginData?.validatedDate, session?.email, myDomainSecurityGroups, securityGroups]);
// If the domain restricts primary login switching,
// the user is not allowed to change their default contact method.
return !isRestrictedDefaultContactMethodSwitch;
}, [isDefaultContactMethod, loginData?.validatedDate, isRestrictedDefaultContactMethodSwitch]);

/**
* Toggle delete confirm modal visibility
Expand Down Expand Up @@ -246,7 +262,9 @@ function ContactMethodDetailsPage({route}: ContactMethodDetailsPageProps) {
errorRowStyles={[themeStyles.ml8, themeStyles.mr5]}
onClose={() => clearContactMethodErrors(contactMethod, isFailedRemovedContactMethod ? 'deletedLogin' : 'defaultLogin')}
>
<Text style={[themeStyles.ph5, themeStyles.mv3]}>{translate('contacts.yourDefaultContactMethod')}</Text>
<Text style={[themeStyles.ph5, themeStyles.mv3]}>
{translate(isRestrictedDefaultContactMethodSwitch ? 'contacts.yourDefaultContactMethodRestrictedSwitch' : 'contacts.yourDefaultContactMethod')}
</Text>
</OfflineWithFeedback>
) : (
<OfflineWithFeedback
Expand Down
Loading