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
Only load user data once in service
Oliver Güntherc58539abde44
diff --git a/frontend/src/app/features/enterprise/enterprise-active-trial/ee-active-trial.component.ts b/frontend/src/app/features/enterprise/enterprise-active-trial/ee-active-trial.component.tsindex 225c4d80a81..51b7968e6a6 100644--- a/frontend/src/app/features/enterprise/enterprise-active-trial/ee-active-trial.component.ts+++ b/frontend/src/app/features/enterprise/enterprise-active-trial/ee-active-trial.component.ts@@ -26,23 +26,12 @@// See COPYRIGHT and LICENSE files for more details.//++-import {- ChangeDetectorRef,- ChangeDetectionStrategy,- Component,- ElementRef,- OnInit, Input,-} from '@angular/core';+import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, OnInit } from '@angular/core';import { distinctUntilChanged } from 'rxjs/operators';import { I18nService } from 'core-app/core/i18n/i18n.service';import { EnterpriseTrialService } from 'core-app/features/enterprise/enterprise-trial.service';-import {- HttpClient,- HttpErrorResponse,-} from '@angular/common/http';+import { HttpClient } from '@angular/common/http';import { EEActiveTrialBase } from 'core-app/features/enterprise/enterprise-active-trial/ee-active-trial.base';-import { GonService } from 'core-app/core/gon/gon.service';-import { EXTERNAL_REQUEST_HEADER } from 'core-app/features/hal/http/openproject-header-interceptor';import { IEnterpriseData } from 'core-app/features/enterprise/enterprise-trial.model';@Component({@@ -52,8 +41,6 @@ import { IEnterpriseData } from 'core-app/features/enterprise/enterprise-trial.mchangeDetection: ChangeDetectionStrategy.OnPush,})export class EEActiveTrialComponent extends EEActiveTrialBase implements OnInit {- @Input() public trialKey:string|undefined;-public subscriber:string;public email:string;@@ -93,46 +80,9 @@ export class EEActiveTrialComponent extends EEActiveTrialBase implements OnInitthis.formatUserData(data);this.cdRef.detectChanges();});-- this.initialize();- }- }-- private initialize():void {- const { data } = this.eeTrialService.current;-- if (this.trialKey && !data) {- // after reload: get data from Augur using the trial key saved in gon- const trialLink = `${this.eeTrialService.baseUrlAugur}/public/v1/trials/${this.trialKey}`;- this.eeTrialService.store.update({ trialLink });- this.getUserDataFromAugur(trialLink);}}- // use the trial key saved in the db- // to get the user data from Augur- private getUserDataFromAugur(trialLink:string) {- this- .http- .get(- `${trialLink}/details`,- {- headers: {- [EXTERNAL_REQUEST_HEADER]: 'true',- },- },- )- .toPromise()- .then((data:IEnterpriseData) => {- this.eeTrialService.store.update({ data });- this.eeTrialService.retryConfirmation();- })- .catch(() => {- // Check whether the mail has been confirmed by now- this.eeTrialService.getToken();- });- }-private formatUserData(userForm:IEnterpriseData) {this.subscriber = `${userForm.first_name} ${userForm.last_name}`;this.email = userForm.email;diff --git a/frontend/src/app/features/enterprise/enterprise-trial.service.ts b/frontend/src/app/features/enterprise/enterprise-trial.service.tsindex 77b90e25120..e1a418b1d7a 100644--- a/frontend/src/app/features/enterprise/enterprise-trial.service.ts+++ b/frontend/src/app/features/enterprise/enterprise-trial.service.ts@@ -36,8 +36,12 @@ import { PathHelperService } from 'core-app/core/path-helper/path-helper.serviceimport { ToastService } from 'core-app/shared/components/toaster/toast.service';import { EXTERNAL_REQUEST_HEADER } from 'core-app/features/hal/http/openproject-header-interceptor';import { EnterpriseTrialStore } from 'core-app/features/enterprise/enterprise-trial.store';-import { GonService } from 'core-app/core/gon/gon.service';-import { EnterpriseTrialErrorHalResource, EnterpriseTrialHalResource, IEnterpriseData, IEnterpriseTrial } from 'core-app/features/enterprise/enterprise-trial.model';+import {+ EnterpriseTrialErrorHalResource,+ EnterpriseTrialHalResource,+ IEnterpriseData,+ IEnterpriseTrial,+} from 'core-app/features/enterprise/enterprise-trial.model';import isDefinedEntity from 'core-app/core/state/is-defined-entity';@Injectable()@@ -116,6 +120,9 @@ export class EnterpriseTrialService {this.trialKey = trialKey;if (this.trialKey) {+ const trialLink = `${this.baseUrlAugur}/public/v1/trials/${this.trialKey}`;+ this.store.update({ trialLink });+ this.getUserDataFromAugur(trialLink);this.setMailSubmittedStatus();}}@@ -159,6 +166,30 @@ export class EnterpriseTrialService {});}+ // use the trial key saved in the db+ // to get the user data from Augur+ public getUserDataFromAugur(trialLink:string) {+ this+ .http+ .get(+ `${trialLink}/details`,+ {+ headers: {+ [EXTERNAL_REQUEST_HEADER]: 'true',+ },+ },+ )+ .toPromise()+ .then((data:IEnterpriseData) => {+ this.store.update({ data });+ this.retryConfirmation();+ })+ .catch(() => {+ // Check whether the mail has been confirmed by now+ this.getToken();+ });+ }+// get a token from the trial link if user confirmed mailpublic getToken():void {// 2) GET /public/v1/trials/:iddiff --git a/frontend/src/app/features/enterprise/free-trial-button/free-trial-button.component.ts b/frontend/src/app/features/enterprise/free-trial-button/free-trial-button.component.tsindex e583dfff5d6..4477a3e4051 100644--- a/frontend/src/app/features/enterprise/free-trial-button/free-trial-button.component.ts+++ b/frontend/src/app/features/enterprise/free-trial-button/free-trial-button.component.ts@@ -107,31 +107,9 @@ export class FreeTrialButtonComponent implements OnInit {private initialize():void {if (this.trialCreatedAt) {this.created = this.timezoneService.formattedDate(this.trialCreatedAt);-- const { data } = this.eeTrialService.store.getValue();- if (data) {- // after reload: get data from Augur using the trial key saved in gon- const trialLink = `${this.eeTrialService.baseUrlAugur}/public/v1/trials/${this.trialKey}`;- this.eeTrialService.store.update({ trialLink });- this.getUserDataFromAugur(trialLink);- }}}- private getUserDataFromAugur(trialLink:string):void {- this.http- .get<IEnterpriseData>(`${trialLink}/details`)- .toPromise()- .then((data:IEnterpriseData) => {- this.eeTrialService.store.update({ data });- this.eeTrialService.retryConfirmation();- })- .catch(() => {- // Check whether the mail has been confirmed by now- this.eeTrialService.getToken();- });- }-public openTrialModal():void {// cancel request and open first modal windowthis.eeTrialService.store.update({ cancelled: true, modalOpen: true });