Skip to content

Commit

Permalink
Add input validation for email address settings (#6360)
Browse files Browse the repository at this point in the history
Signed-off-by: Giovanni Ferrari <giovanni.ferrari@soft.it>
  • Loading branch information
quinarygio authored and ClementBouvierN committed May 14, 2024
1 parent 306b4ad commit 40c7a8c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
12 changes: 11 additions & 1 deletion src/test/cypress/cypress/integration/Settings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@ describe('Settings', function () {

it('Should proposed to save settings ', () => {
opfab.loginWithUser('operator1_fr');

checkEmailValidation();
checkCancelNavigation();
checkExitWithoutSaving();
checkAcceptSaving();
});


function checkEmailValidation() {
opfab.navigateToSettings();
cy.get('#opfab-settings-btn-save').should('be.enabled')
cy.get('#opfab-setting-input-email').type('test');
cy.get('#opfab-settings-btn-save').should('be.disabled')
cy.get('#opfab-setting-input-email').type('@domain');
cy.get('#opfab-settings-btn-save').should('be.enabled')
}

function checkCancelNavigation() {
opfab.navigateToSettings();
settings.clickOnSeverity('alarm');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@
<div class="opfab-settings-item" *ngIf="settingsView.isSettingVisible('email')">
<div class="opfab-input">
<label for="opfab-setting-email" translate>settings.email</label>
<input id="opfab-setting-input-email" type="text" formControlName="email" autocomplete="off">
<input id="opfab-setting-input-email" type="email" formControlName="email" autocomplete="off">
</div>
<div *ngIf="email.invalid" class="row alert alert-danger">
<div *ngIf="email.errors.email" translate>settings.input.errors.invalidEmail</div>
</div>
</div>
<div class="opfab-settings-item" id="opfab-setting-input-remoteLoggingEnabled"
Expand All @@ -153,7 +156,7 @@
<br />

<div style="text-align: center;width:100%">
<button id="opfab-settings-btn-save" type="button" class="opfab-btn"
<button id="opfab-settings-btn-save" type="button" class="opfab-btn" [disabled]="!settingsForm.valid"
(click)='saveSettings()' style="text-align: center;min-width: 243px;"
translate>shared.confirmSettings</button>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit} from '@angular/core';
import {TranslateService} from '@ngx-translate/core';
import {SettingsView} from 'app/business/view/settings/settings.view';
import {FormControl, FormGroup} from '@angular/forms';
import {FormControl, FormGroup, Validators} from '@angular/forms';
import {MultiSelectConfig} from '@ofModel/multiselect.model';
import {Subject, takeUntil} from 'rxjs';
import {ServerResponseStatus} from 'app/business/server/serverResponse';
Expand Down Expand Up @@ -76,9 +76,10 @@ export class SettingsComponent implements OnInit, OnDestroy {

const formGroupConfig = {};
settings.forEach((setting) => {
formGroupConfig[setting] = new FormControl(this.settingsView.getSetting(setting));
if (setting === 'email')
formGroupConfig[setting] = new FormControl(this.settingsView.getSetting(setting), Validators.email);
else formGroupConfig[setting] = new FormControl(this.settingsView.getSetting(setting));
});

this.settingsForm = new FormGroup(formGroupConfig, {updateOn: 'change'});
this.initLocaleMultiselect();
}
Expand Down Expand Up @@ -143,4 +144,8 @@ export class SettingsComponent implements OnInit, OnDestroy {
}
return true;
}

get email() {
return this.settingsForm.get('email');
}
}
7 changes: 6 additions & 1 deletion ui/main/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,12 @@
"emailToPlainText": "Send emails in plain text",
"sendDailyEmail": "Send daily email to recap the cards of the day",
"email": "Email",
"settingsSaved": "Settings saved"
"settingsSaved": "Settings saved",
"input": {
"errors": {
"invalidEmail": "Invalid email"
}
}
},
"archive": {
"cardLoadingInProgress":"Loading card ...",
Expand Down
7 changes: 6 additions & 1 deletion ui/main/src/assets/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,12 @@
"emailToPlainText": "Envoi des mails en texte brut",
"sendDailyEmail": "Envoi un mail quotidien récapitulatif des cartes du jour",
"email": "Email",
"settingsSaved": "Paramètres sauvegardés"
"settingsSaved": "Paramètres sauvegardés",
"input": {
"errors": {
"invalidEmail": "Email invalide"
}
}
},
"archive": {
"cardLoadingInProgress":"Chargement de la carte...",
Expand Down
7 changes: 6 additions & 1 deletion ui/main/src/assets/i18n/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,12 @@
"emailToPlainText": "De e-mails versturen in platte tekst",
"sendDailyEmail": "Stuur dagelijks een e-mail om de kaarten van de dag samen te vatten",
"email": "Email",
"settingsSaved": "Instellingen bewaard"
"settingsSaved": "Instellingen bewaard",
"input": {
"errors": {
"invalidEmail": "Ongeldige e-mail"
}
}
},
"archive": {
"cardLoadingInProgress":"Bezig met laden van de kaart ...",
Expand Down

0 comments on commit 40c7a8c

Please sign in to comment.