Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Highlight correct error field in EE trial form (#8290)

Henriette Dargef2b89d083878
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index 51cacc32794..5e22c334f13 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -201,6 +201,8 @@ en:
label_starts_at: "Starts at"
label_expires_at: "Expires at"
receive_newsletter: I want to receive the OpenProject <a target="_blank" href="%{link}">newsletter</a>.
+ taken_domain: There can only be one active trial per domain.
+ taken_email: Each user can only create one trial.
email_not_received: "You did not receive an email? You can resend the email with the link on the right."
try_another_email: "Or try it with another email address."
try_another_email_hint: "Please be aware that your previous email address gets invalid if you try again with a new one."
diff --git a/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.html b/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.html
index e86d04d9a8a..a8932a63e7b 100644
--- a/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.html
+++ b/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.html
@@ -32,29 +32,31 @@
</div>
</div>
</div>
- <div class="form--field -wide-label -required" [ngClass]="{ '-error': eeTrialService.errorMsg }">
+ <div class="form--field -wide-label -required">
<label class="form--label" for="trial-email">{{ text.label_email }}</label>
<div class="form--field-container">
<div class="form--text-field-container"
- [ngClass]="{ '-required-highlighting' : eeTrialService.errorMsg }">
+ [ngClass]="{ '-required-highlighting' : eeTrialService.emailError }">
<input type="email"
class="form--text-field"
id="trial-email"
formControlName="email" (blur)="checkMailField()">
</div>
</div>
- <div *ngIf="eeTrialService.errorMsg" class="form--field-instructions">{{ eeTrialService.errorMsg }}</div>
+ <div *ngIf="eeTrialService.emailError" class="form--field-instructions">{{ eeTrialService.errorMsg }}</div>
</div>
<div class="form--field -wide-label -required">
<label class="form--label" for="trial-domain-name">{{ text.label_domain }}</label>
<div class="form--field-container">
- <div class="form--text-field-container">
+ <div class="form--text-field-container"
+ [ngClass]="{ '-required-highlighting' : eeTrialService.domainTaken }">
<input type="text"
id="trial-domain-name"
class="form--text-field"
formControlName="domain">
</div>
</div>
+ <div *ngIf="eeTrialService.domainTaken" class="form--field-instructions">{{ eeTrialService.errorMsg }}</div>
</div>
<div class="form--field -required">
<div class="form--field-container">
diff --git a/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.ts b/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.ts
index ff795fbb125..634d75fc0d8 100644
--- a/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.ts
+++ b/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.ts
@@ -65,7 +65,6 @@ export class EETrialFormComponent {
de: 'https://www.openproject.org/de/datenschutz/'
})
}),
- invalid_email: this.I18n.t('js.admin.enterprise.trial.form.invalid_email'),
label_test_ee: this.I18n.t('js.admin.enterprise.trial.form.test_ee'),
label_company: this.I18n.t('js.admin.enterprise.trial.form.label_company'),
label_first_name: this.I18n.t('js.admin.enterprise.trial.form.label_first_name'),
@@ -89,9 +88,10 @@ export class EETrialFormComponent {
// displays message for user
public checkMailField() {
if (this.trialForm.value.email !== '' && this.trialForm.controls.email.errors) {
- this.eeTrialService.errorMsg = this.text.invalid_email;
+ this.eeTrialService.emailInvalid = true;
} else {
- this.eeTrialService.errorMsg = undefined;
+ this.eeTrialService.emailInvalid = false;
+ this.eeTrialService.error = undefined;
}
}
}
diff --git a/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial.modal.ts b/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial.modal.ts
index 2e81756e0a2..06971c986c9 100644
--- a/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial.modal.ts
+++ b/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial.modal.ts
@@ -48,7 +48,6 @@ export class EnterpriseTrialModal extends OpModalComponent implements AfterViewI
@Input() public opReferrer:string;
public trialForm:FormGroup;
- public errorMsg:string|undefined;
// modal configuration
public showClose = true;
diff --git a/frontend/src/app/components/enterprise/enterprise-trial.service.ts b/frontend/src/app/components/enterprise/enterprise-trial.service.ts
index 4eaf8070bc2..1d3b68c321c 100644
--- a/frontend/src/app/components/enterprise/enterprise-trial.service.ts
+++ b/frontend/src/app/components/enterprise/enterprise-trial.service.ts
@@ -32,7 +32,13 @@ export class EnterpriseTrialService {
public confirmed:boolean;
public cancelled = false;
public status:'mailSubmitted'|'startTrial'|undefined;
- public errorMsg:string|undefined;
+ public error:HttpErrorResponse|undefined;
+ public emailInvalid:boolean = false;
+ public text = {
+ invalid_email: this.I18n.t('js.admin.enterprise.trial.form.invalid_email'),
+ taken_email: this.I18n.t('js.admin.enterprise.trial.form.taken_email'),
+ taken_domain: this.I18n.t('js.admin.enterprise.trial.form.taken_domain'),
+ };
constructor(readonly I18n:I18nService,
protected http:HttpClient,
@@ -49,12 +55,12 @@ export class EnterpriseTrialService {
// send POST request with form object
// receive an enterprise trial link to access a token
public sendForm(form:FormGroup) {
- this.userData$.putValue(form.value);
-
- this.cancelled = false;
this.http.post(this.baseUrlAugur + '/public/v1/trials', form.value)
.toPromise()
.then((enterpriseTrial:any) => {
+ this.userData$.putValue(form.value);
+ this.cancelled = false;
+
this.trialLink = enterpriseTrial._links.self.href;
this.saveTrialKey(this.trialLink);
@@ -63,7 +69,7 @@ export class EnterpriseTrialService {
.catch((error:HttpErrorResponse) => {
// mail is invalid or user already created a trial
if (error.status === 422 || error.status === 400) {
- this.errorMsg = error.error.description;
+ this.error = error;
} else {
this.notificationsService.addWarning(error.error.description || I18n.t('js.error.internal'));
}
@@ -172,4 +178,35 @@ export class EnterpriseTrialService {
public get mailSubmitted():boolean {
return this.status === 'mailSubmitted';
}
+
+ public get domainTaken():boolean {
+ return this.error ? this.error.error.identifier === 'domain_taken' : false;
+ }
+
+ public get emailTaken():boolean {
+ return this.error ? this.error.error.identifier === 'user_already_created_trial' : false;
+ }
+
+ public get emailError():boolean {
+ if (this.emailInvalid) {
+ return true;
+ } else if (this.error) {
+ return this.emailTaken;
+ } else {
+ return false;
+ }
+ }
+
+ public get errorMsg() {
+ let error:string = '';
+ if (this.emailInvalid) {
+ error = this.text.invalid_email;
+ } else if (this.domainTaken) {
+ error = this.text.taken_domain;
+ } else if (this.emailTaken) {
+ error = this.text.taken_email;
+ }
+
+ return error;
+ }
}
diff --git a/spec/features/admin/enterprise/enterprise_trial_spec.rb b/spec/features/admin/enterprise/enterprise_trial_spec.rb
index 83e23503f84..3c24e14b217 100644
--- a/spec/features/admin/enterprise/enterprise_trial_spec.rb
+++ b/spec/features/admin/enterprise/enterprise_trial_spec.rb
@@ -139,6 +139,16 @@ describe 'Enterprise trial management',
}
end
+ let(:domain_in_use_body) do
+ {
+ _type: "error",
+ code: 422,
+ identifier: "domain_taken",
+ description: "There can only be one active trial per domain."
+ }
+ end
+
+
before do
login_as(admin)
visit enterprise_path
@@ -162,8 +172,21 @@ describe 'Enterprise trial management',
fill_out_modal
find('.button:not(:disabled)', text: 'Submit').click
- expect(page).to have_selector('.form--field.-error #trial-email')
- expect(page).to have_text 'Each user can only create one trial.'
+ expect(page).to have_selector('.-required-highlighting #trial-email')
+ expect(page).to have_text('Each user can only create one trial.')
+ expect(page).to have_no_text 'email sent - waiting for confirmation'
+ end
+
+ it 'blocks the request assuming the domain was used' do
+ proxy.stub('https://augur.openproject-edge.com:443/public/v1/trials', method: 'post')
+ .and_return(headers: {'Access-Control-Allow-Origin' => '*'}, code: 422, body: domain_in_use_body.to_json)
+
+ find('.button', text: 'Start free trial').click
+ fill_out_modal
+ find('.button:not(:disabled)', text: 'Submit').click
+
+ expect(page).to have_selector('.-required-highlighting #trial-domain-name')
+ expect(page).to have_text('There can only be one active trial per domain.')
expect(page).to have_no_text 'email sent - waiting for confirmation'
end