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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Prevent that a wrong domain can be entered. If (for any other reason) saving the returned token fails, we would be stuck in a state of a confirmed mail and no saved token. Because of that, we delete the trial key in the error case to avoid an infinite page reloading.
Henriette Darged0785ebf3551
diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rbindex 2b3510db2b4..44d80968c3b 100644--- a/app/controllers/enterprises_controller.rb+++ b/app/controllers/enterprises_controller.rb@@ -67,7 +67,10 @@ class EnterprisesController < ApplicationController@token.encoded_token = saved_encoded_token@current_token = @token || EnterpriseToken.newend- render action: :show+ respond_to do |format|+ format.html { render action: :show }+ format.json { render json: { description: @token.errors.full_messages.join(", ") }, status: 400 }+ endendend@@ -77,8 +80,7 @@ class EnterprisesController < ApplicationControllertoken.destroyflash[:notice] = t(:notice_successful_delete)- trial_key = Token::EnterpriseTrialKey.find_by(user_id: User.system.id)- trial_key&.destroy+ delete_trial_keyredirect_to action: :showelse@@ -90,6 +92,10 @@ class EnterprisesController < ApplicationControllerToken::EnterpriseTrialKey.create(user_id: User.system.id, value: params[:trial_key])end+ def delete_trial_key+ Token::EnterpriseTrialKey.where(user_id: User.system.id).delete_all+ end+privatedef write_trial_key_to_gondiff --git a/config/routes.rb b/config/routes.rbindex cda42eac4ce..3d0916160ee 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -342,6 +342,7 @@ OpenProject::Application.routes.draw doresource :enterprise, only: %i[show create destroy]scope controller: 'enterprises' dopost 'enterprise/save_trial_key' => 'enterprises#save_trial_key'+ delete 'enterprise/delete_trial_key' => 'enterprises#delete_trial_key'endendresources :enumerationsdiff --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.htmlindex a8932a63e7b..19c770089aa 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@@ -53,7 +53,8 @@<input type="text"id="trial-domain-name"class="form--text-field"- formControlName="domain">+ formControlName="domain"+ disabled></div></div><div *ngIf="eeTrialService.domainTaken" class="form--field-instructions">{{ eeTrialService.errorMsg }}</div>diff --git a/frontend/src/app/components/enterprise/enterprise-trial.service.ts b/frontend/src/app/components/enterprise/enterprise-trial.service.tsindex 1d3b68c321c..102270a38a1 100644--- a/frontend/src/app/components/enterprise/enterprise-trial.service.ts+++ b/frontend/src/app/components/enterprise/enterprise-trial.service.ts@@ -1,6 +1,6 @@import {Injectable} from "@angular/core";import {I18nService} from "core-app/modules/common/i18n/i18n.service";-import {HttpClient, HttpErrorResponse} from "@angular/common/http";+import {HttpClient, HttpErrorResponse, HttpHeaders} from "@angular/common/http";import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";import {NotificationsService} from "core-app/modules/common/notifications/notifications.service";import {FormGroup} from "@angular/forms";@@ -91,13 +91,6 @@ export class EnterpriseTrialService {if (!res.token_retrieved) {await this.saveToken(res.token);}-- // load page if mail was confirmed and modal window is not open- if (!this.modalOpen) {- setTimeout(() => { // display confirmed status before reloading- window.location.reload();- }, 500);- }}).catch((error:HttpErrorResponse) => {// returns error 422 while waiting of confirmation@@ -144,7 +137,24 @@ export class EnterpriseTrialService {{ withCredentials: true }).toPromise()+ .then(() => {+ // load page if mail was confirmed and modal window is not open+ if (!this.modalOpen) {+ setTimeout(() => { // display confirmed status before reloading+ window.location.reload();+ }, 500);+ }+ }).catch((error:HttpErrorResponse) => {+ // Delete the trial key as the token could not be saved and thus something is wrong with the token.+ // Without this deletion, we run into an endless loop of an confirmed mail, but no saved token.+ this.http+ .delete(+ this.pathHelper.api.v3.appBasePath + '/admin/enterprise/delete_trial_key',+ { withCredentials: true }+ )+ .toPromise();+this.notificationsService.addError(error.error.description || I18n.t('js.error.internal'));});}