Skip to content

Commit

Permalink
feat(web.mxplan): add dkim feature
Browse files Browse the repository at this point in the history
ref: MANAGER-14925

Signed-off-by: Guillaume Hyenne <[email protected]>
  • Loading branch information
ghyenne committed Nov 22, 2024
1 parent 4939db8 commit e447dac
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -689,11 +689,13 @@
"emailpro_tab_domain_diagnostic_spf_toolbox_ok": "Configuration automatique effectuée",
"emailpro_tab_domain_diagnostic_dkim": "DKIM",
"emailpro_tab_domain_diagnostic_dkim_text_field": "Champ Texte",
"emailpro_tab_domain_diagnostic_dkim_cname_field": "Champ CNAME",
"emailpro_tab_domain_diagnostic_dkim_configurate_dns_records_info": "Pour configurer votre DKIM vous devez ajouter ces deux entrées à vos DNS",
"emailpro_tab_domain_diagnostic_dkim_title_error": "Diagnostic DKIM",
"emailpro_tab_domain_diagnostic_dkim_configurate_activation_time": "L'activation de DKIM peut prendre 48 heures.",
"emailpro_tab_domain_diagnostic_dkim_configurate_activation_guide": "Référez-vous à la documentation de votre fournisseur de domaine. Retrouvez de l'aide sur notre <a href=\"{{url}}\" target=\"_blank\">guide</a>.",
"emailpro_tab_domain_diagnostic_dkim_id_generation_no_ovhcloud": "La génération de vos identifiants est en cours, veuillez patienter...",
"emailpro_tab_domain_diagnostic_dkim_id_generation_no_ovhcloud_doing": "La génération de vos identifiants est en cours, veuillez patienter...",
"emailpro_tab_domain_diagnostic_dkim_id_generation_no_ovhcloud_done": "La génération de vos identifiants est terminée. Vous trouverez les informations de configuration à l'étape suivante.",
"emailpro_tab_domain_diagnostic_dkim_next_no_ovhcloud": "Suivant",
"emailpro_tab_domain_diagnostic_dkim_confirm_no_ovhcloud": "Fermer",
"emailpro_tab_domain_diagnostic_dkim_title_activation": "Activer DKIM",
Expand All @@ -708,8 +710,10 @@
"emailpro_tab_domain_diagnostic_dkim_configuration_nok": "Votre module DKIM n'est pas correctement configuré. Veuillez vous reporter au <a href=\"{{url}}\" target=\"_blank\">guide</a> d'aide à la configuration avec le code d'erreur {{errorCode}}.",
"emailpro_tab_domain_diagnostic_dkim_activation_no_ovhcloud": "Votre domaine n'étant pas hébergé chez OVHCloud nous ne pouvons pas le configurer automatiquement. Vous pouvez configurer DKIM en suivant ce <a href=\"{{url}}\" target=\"_blank\">guide</a>.",
"emailpro_tab_domain_diagnostic_dkim_configurate_no_ovhcloud": "Configurer",
"emailpro_tab_domain_diagnostic_dkim_name": "Nom",
"emailpro_tab_domain_diagnostic_dkim_target": "Cible",
"emailpro_tab_domain_diagnostic_dkim_mxplan_no_ovhcloud": "Après modification, attendre quelques minutes et cliquer sur \"Activer\".",
"emailpro_tab_domain_diagnostic_dkim_subdomain": "Sous-domaine {{ value }}",
"emailpro_tab_domain_diagnostic_dkim_target": "Cible {{ value }}",
"emailpro_tab_domain_diagnostic_dkim_cname": "CNAME {{ value }}",
"emailpro_tab_domain_diagnostic_dkim_activation_ovhcloud": "Nous allons configurer DKIM pour vous, l'activation complète peut prendre 24 heures.",
"emailpro_tab_domain_diagnostic_dkim_activation_success": "Configuration DKIM en cours, veuillez noter que la mise à jour peut prendre jusqu'à 24 heures pour se propager.",
"emailpro_tab_domain_diagnostic_dkim_error": "Une erreur est survenue pendant la configuration DKIM.<br />{{message}}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ export default class DkimAutoConfigurator {
this.showConfiguratingBtn = true;
}

async getSelectorNameForNoOvhCloud() {
getSelectorNameForNoOvhCloud() {
if (!this.dkimSelectorsNoDomain) {
return;
return false;
}
this.loading = true;
const promises = this.dkimSelectorsNoDomain.map((dkimSelector) => {
return this.services.EmailProDomains.getDkimSelectorName(
this.services.$stateParams.productId,
Expand All @@ -26,55 +27,90 @@ export default class DkimAutoConfigurator {
);
});

const [selector1NoDomain, selector2NoDomain] = await this.services.$q.all(
promises,
);
this.selector1NoDomain = selector1NoDomain;
this.selector1NameInfos = this.getDkimName(1);
this.selector1RecordInfos = this.getDkimRecord(1);
this.selector2NoDomain = selector2NoDomain;
this.selector2NameInfos = this.getDkimName(2);
this.selector2RecordInfos = this.getDkimRecord(2);
return this.services.$q
.all(promises)
.then((data) => {
const [selector1NoDomain, selector2NoDomain] = data;
this.selector1NoDomain = selector1NoDomain;
this.selector1NameInfos = this.getDkimName(1);
this.selector1RecordInfos = this.getDkimRecord(1);
this.selector2NoDomain = selector2NoDomain;
this.selector2NameInfos = this.getDkimName(2);
this.selector2RecordInfos = this.getDkimRecord(2);
this.loading = false;
return data;
})
.catch(() => []);
}

async loadDataForDkim() {
this.showConfiguratingBtn = false;
this.loading = true;
this.dkimSelectorsNoDomain = await this.getDkimSelectorForCurrentState();
await this.configureDkim();
this.isStepConfigureValid = true;
this.loading = false;
if (!this.isMXPlan) {
this.dkimSelectorsNoDomain = await this.getDkimSelectorForCurrentState();
}
this.configureDkim().then(() => {
if (!this.isMXPlan) {
return this.activationSelectorsStatus();
}
this.isStepConfigureValid = true;
this.loading = false;
return null;
});
}

getDkimSelector() {
return this.getDkimSelectorForCurrentState().then((dkimSelectors) => {
this.dkimSelectorsNoDomain = dkimSelectors;
});
return this.isMXPlan
? null
: this.getDkimSelectorForCurrentState()
.then((dkimSelectors) => {
this.dkimSelectorsNoDomain = dkimSelectors;
})
.catch(({ data }) => {
this.writeError('emailpro_tab_domain_diagnostic_dkim_error', data);
});
}

leaveDkimConfigurator(reload = false) {
this.services.navigation.resetAction();
this.services.$scope.resetAction();
this.initializeDkimConfiguratorNoOvh();
this.services.$state.go(
'email-pro.dashboard.domain',
{},
reload ? { reload: 'email-pro.dashboard.domain' } : null,
this.services.$state.current.name,
{ productId: this.services.$stateParams.productId },
reload ? { reload: this.services.$state.current.name } : null,
);
}

configureDkim() {
const promises = this.postDkim(this.dkimSelectorsNoDomain);
return this.services.$q
.all(promises)
.then(() => {
this.writeSuccess(
`${this.serviceType}_tab_domain_diagnostic_dkim_activation_success`,
);
})
.catch(() => {
if (!this.isMXPlan || this.dkimMXplanSelectors.length === 0) {
const promises =
this.isMXPlan && this.dkimMXplanSelectors.length === 0
? this.services.EmailProDomains.enableDkimForMXplan(this.domain.name)
: this.postDkim(this.dkimSelectorsNoDomain);
return this.services.$q.all(promises).catch(({ data }) => {
this.leaveDkimConfigurator();
this.writeError(`${this.serviceType}_tab_domain_diagnostic_dkim_error`);
return this.writeError(
`${this.serviceType}_tab_domain_diagnostic_dkim_error`,
data,
);
});
}
return this.services.$q.resolve();
}

activationSelectorsStatus() {
if (
this.dkimSelectorsNoDomain &&
(!this.selector1NoDomain || !this.selector2NoDomain)
) {
setTimeout(async () => {
await this.getSelectorNameForNoOvhCloud();
return this.activationSelectorsStatus();
}, 5000);
return false;
}
this.isStepConfigureValid = true;
return this.services.$q.resolve();
}

getTitleDkimConfigurator() {
Expand All @@ -88,33 +124,52 @@ export default class DkimAutoConfigurator {
}

initContext() {
return this.getSelectorNameForNoOvhCloud();
if (this.isMXPlan) {
this.selector1NoDomain = {
customerRecord: this.dkimMXplanSelectors[0].selectorName,
targetRecord: this.dkimMXplanSelectors[0].cname,
};
this.selector1RecordInfos = this.getDkimRecord(1);
this.selector2NoDomain = {
customerRecord: this.dkimMXplanSelectors[1].selectorName,
targetRecord: this.dkimMXplanSelectors[1].cname,
};
this.selector2RecordInfos = this.getDkimRecord(2);
} else {
this.getSelectorNameForNoOvhCloud();
}
}

getDkimName(index) {
return [
`<b>${this.services.$translate.instant(
`${this.serviceType}_tab_domain_diagnostic_dkim_name`,
)}`,
`${index}</b>: `,
`${this.serviceType}_tab_domain_diagnostic_dkim_subdomain`,
{ value: index },
)}</b>: `,
this[`selector${index}NoDomain`].customerRecord,
].join('');
}

getDkimRecord(index) {
return [
`<b>${this.services.$translate.instant(
`${this.serviceType}_tab_domain_diagnostic_dkim_target`,
)}`,
`${index}</b>: `,
`${this.serviceType}_tab_domain_diagnostic_dkim_${
this.isMXPlan ? 'cname' : 'target'
}`,
{ value: index },
)}</b>: `,
this[`selector${index}NoDomain`].targetRecord,
].join('');
}

hideConfirmButton() {
return (
this.dkimStatus === this.DKIM_STATUS.TO_CONFIGURE &&
this.domainDiag.isOvhDomain
(!this.isMXPlan &&
([this.DKIM_STATUS.TO_CONFIGURE, this.DKIM_STATUS.IN_PROGRESS].includes(
this.dkimStatus,
) ||
this.dkimErrorMessage)) ||
(this.isMXPlan && [this.DKIM_STATUS.MODIFYING].includes(this.dkimStatus))
);
}

Expand Down
Loading

0 comments on commit e447dac

Please sign in to comment.