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

write trial key to gon in all places that we need it, not only in enterprise module

bsatarnejad67cb501373be
diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb
index da5e5f02d7c..a4ff929711e 100644
--- a/app/controllers/enterprises_controller.rb
+++ b/app/controllers/enterprises_controller.rb
@@ -45,7 +45,7 @@ class EnterprisesController < ApplicationController
helpers.write_augur_to_gon
if !@current_token.present?
- write_trial_key_to_gon
+ helpers.write_trial_key_to_gon
end
end
@@ -96,16 +96,6 @@ class EnterprisesController < ApplicationController
private
- def write_trial_key_to_gon
- @trial_key = Token::EnterpriseTrialKey.find_by(user_id: User.system.id)
- if @trial_key
- gon.ee_trial_key = {
- value: @trial_key.value,
- created: @trial_key.created_at
- }
- end
- end
-
def default_breadcrumb
t(:label_enterprise_edition)
end
diff --git a/app/helpers/enterprise_helper.rb b/app/helpers/enterprise_helper.rb
index d6a7478ae6c..c3b74d53bff 100644
--- a/app/helpers/enterprise_helper.rb
+++ b/app/helpers/enterprise_helper.rb
@@ -3,4 +3,14 @@ module EnterpriseHelper
gon.augur_url = OpenProject::Configuration.enterprise_trial_creation_host
gon.token_version = OpenProject::Token::VERSION
end
+
+ def write_trial_key_to_gon
+ @trial_key = Token::EnterpriseTrialKey.find_by(user_id: User.system.id)
+ if @trial_key
+ gon.ee_trial_key = {
+ value: @trial_key.value,
+ created: @trial_key.created_at
+ }
+ end
+ end
end
diff --git a/app/views/common/upsale.html.erb b/app/views/common/upsale.html.erb
index c937d4c2d17..9832d74ce68 100644
--- a/app/views/common/upsale.html.erb
+++ b/app/views/common/upsale.html.erb
@@ -1,5 +1,9 @@
<% write_augur_to_gon %>
+<% if !EnterpriseToken.current.present? %>
+ <% write_trial_key_to_gon %>
+<% end %>
+
<div class="upsale-notification">
<h2><%= feature_title %></h2>
<% if feature_description.empty? %>
diff --git a/frontend/src/app/features/enterprise/enterprise-base.component.ts b/frontend/src/app/features/enterprise/enterprise-base.component.ts
index e8fb0168226..1724d773afb 100644
--- a/frontend/src/app/features/enterprise/enterprise-base.component.ts
+++ b/frontend/src/app/features/enterprise/enterprise-base.component.ts
@@ -66,6 +66,7 @@ export class EnterpriseBaseComponent {
}
public get noTrialRequested() {
- return this.eeTrialService.status === undefined;
+
+ return window.gon.ee_trial_key === undefined;
}
}
diff --git a/frontend/src/app/features/enterprise/free-trial-button/free-trial-button.component.html b/frontend/src/app/features/enterprise/free-trial-button/free-trial-button.component.html
index 937e839d54b..49555912e5b 100644
--- a/frontend/src/app/features/enterprise/free-trial-button/free-trial-button.component.html
+++ b/frontend/src/app/features/enterprise/free-trial-button/free-trial-button.component.html
@@ -1,3 +1,5 @@
-<button class="button -alt-highlight -round" (click)="openTrialModal()">
- {{ text.button_trial }}
-</button>
\ No newline at end of file
+<div [attr.data-tooltip]="text.confirmation_info(created, email)" [ngClass]="{'tooltip--top': trialRequested}">
+ <button [disabled]="trialRequested" class="button -alt-highlight -round" (click)="openTrialModal()">
+ {{ text.button_trial }}
+ </button>
+</div>
\ No newline at end of file
diff --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.ts
index 679d00186d7..524023cdd5b 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
@@ -36,6 +36,8 @@ import { I18nService } from 'core-app/core/i18n/i18n.service';
import { EnterpriseTrialModalComponent } from 'core-app/features/enterprise/enterprise-modal/enterprise-trial.modal';
import { OpModalService } from 'core-app/shared/components/modal/modal.service';
import { EnterpriseTrialService } from 'core-app/features/enterprise/enterprise-trial.service';
+import { TimezoneService } from 'core-app/core/datetime/timezone.service';
+import { distinctUntilChanged } from 'rxjs/operators';
export const freeTrialButtonSelector = 'free-trial-button';
@@ -45,14 +47,38 @@ export const freeTrialButtonSelector = 'free-trial-button';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FreeTrialButtonComponent {
+ created = this.timezoneService.formattedDate(new Date().toString());
+
+ email = '';
+
public text = {
button_trial: this.I18n.t('js.admin.enterprise.upsale.button_start_trial'),
+ confirmation_info: (date:string, email:string) => this.trialRequested ? this.I18n.t('js.admin.enterprise.trial.confirmation_info', {
+ date,
+ email,
+ }): '',
};
constructor(protected I18n:I18nService,
protected opModalService:OpModalService,
readonly injector:Injector,
- public eeTrialService:EnterpriseTrialService) {
+ public eeTrialService:EnterpriseTrialService,
+ readonly timezoneService:TimezoneService) {
+ }
+ ngOnInit() {
+ const eeTrialKey = (window as any).gon.ee_trial_key;
+ if (eeTrialKey) {
+ const savedDateStr = eeTrialKey.created.split(' ')[0];
+ this.created = this.timezoneService.formattedDate(savedDateStr);
+ }
+ this.eeTrialService.userData$
+ .values$()
+ .pipe(
+ distinctUntilChanged(),
+ )
+ .subscribe((userForm) => {
+ this.email = userForm.email;
+ });
}
public openTrialModal():void {
// cancel request and open first modal window
@@ -60,7 +86,7 @@ export class FreeTrialButtonComponent {
this.eeTrialService.modalOpen = true;
this.opModalService.show(EnterpriseTrialModalComponent, this.injector);
}
- public get noTrialRequested() {
- return this.eeTrialService.status === undefined;
+ public get trialRequested() {
+ return window.gon.ee_trial_key !== undefined;
}
}