Merge pull request #8415 from opf/feature/add-ee-infos-and-fix-issues

Add Enterprise trial infos and fix issues

[ci skip]
pull/8419/head
Oliver Günther 4 years ago committed by GitHub
commit 12ad2b8968
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      app/controllers/enterprises_controller.rb
  2. 4
      config/locales/js-en.yml
  3. 1
      config/routes.rb
  4. 3
      frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.html
  5. 2
      frontend/src/app/components/enterprise/enterprise-trial-waiting/ee-trial-waiting.component.html
  6. 35
      frontend/src/app/components/enterprise/enterprise-trial-waiting/ee-trial-waiting.component.ts
  7. 34
      frontend/src/app/components/enterprise/enterprise-trial.service.ts
  8. 26
      spec/features/admin/enterprise/enterprise_trial_spec.rb

@ -67,7 +67,10 @@ class EnterprisesController < ApplicationController
@token.encoded_token = saved_encoded_token
@current_token = @token || EnterpriseToken.new
end
render action: :show
respond_to do |format|
format.html { render action: :show }
format.json { render json: { description: @token.errors.full_messages.join(", ") }, status: 400 }
end
end
end
@ -77,8 +80,7 @@ class EnterprisesController < ApplicationController
token.destroy
flash[:notice] = t(:notice_successful_delete)
trial_key = Token::EnterpriseTrialKey.find_by(user_id: User.system.id)
trial_key&.destroy
delete_trial_key
redirect_to action: :show
else
@ -90,19 +92,25 @@ class EnterprisesController < ApplicationController
Token::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
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
value: @trial_key.value,
created: @trial_key.created_on
}
end
end
def write_augur_to_gon
gon.augur_url = OpenProject::Configuration.enterprise_trial_creation_host
gon.token_version = OpenProject::Token::VERSION
end
def default_breadcrumb

@ -185,7 +185,9 @@ en:
enterprise:
trial:
confirmation: "Confirmation of email address"
confirmation_info: "We sent you an email. Please check your emails and click the confirmation link provided to start your 14 days trial."
confirmation_info: >
We sent you an email on %{date} to %{email}.
Please check your inbox and click the confirmation link provided to start your 14 days trial.
form:
general_consent: >
I agree with the <a target="_blank" href="%{link_terms}">terms of service</a>

@ -342,6 +342,7 @@ OpenProject::Application.routes.draw do
resource :enterprise, only: %i[show create destroy]
scope controller: 'enterprises' do
post 'enterprise/save_trial_key' => 'enterprises#save_trial_key'
delete 'enterprise/delete_trial_key' => 'enterprises#delete_trial_key'
end
end
resources :enumerations

@ -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>

@ -1,6 +1,6 @@
<enterprise-active-trial></enterprise-active-trial>
<p>{{ text.confirmation_info }}</p>
<p>{{ text.confirmation_info(created, email) }}</p>
<p>
<span>{{ text.status_label }} </span>
<span *ngIf="!eeTrialService.confirmed; else confirmedStatus" class="status--waiting">

@ -26,21 +26,28 @@
// See docs/COPYRIGHT.rdoc for more details.
// ++
import {Component, ElementRef} from "@angular/core";
import {Component, ElementRef, OnInit} from "@angular/core";
import {I18nService} from "app/modules/common/i18n/i18n.service";
import {EnterpriseTrialService} from "app/components/enterprise/enterprise-trial.service";
import {HttpClient} from "@angular/common/http";
import {NotificationsService} from "core-app/modules/common/notifications/notifications.service";
import {distinctUntilChanged} from "rxjs/operators";
import {TimezoneService} from "core-components/datetime/timezone.service";
@Component({
selector: 'enterprise-trial-waiting',
templateUrl: './ee-trial-waiting.component.html',
styleUrls: ['./ee-trial-waiting.component.sass']
})
export class EETrialWaitingComponent {
export class EETrialWaitingComponent implements OnInit {
created = this.timezoneService.formattedDate(new Date().toString());
email:string = '';
public text = {
confirmation_info: this.I18n.t('js.admin.enterprise.trial.confirmation_info'),
confirmation_info: (date:string, email:string) => this.I18n.t('js.admin.enterprise.trial.confirmation_info',{
date: date,
email: email
}),
resend: this.I18n.t('js.admin.enterprise.trial.resend_link'),
resend_success: this.I18n.t('js.admin.enterprise.trial.resend_success'),
resend_warning: this.I18n.t('js.admin.enterprise.trial.resend_warning'),
@ -54,7 +61,25 @@ export class EETrialWaitingComponent {
readonly I18n:I18nService,
protected http:HttpClient,
protected notificationsService:NotificationsService,
public eeTrialService:EnterpriseTrialService) {
public eeTrialService:EnterpriseTrialService,
readonly timezoneService:TimezoneService) {
}
ngOnInit() {
let eeTrialKey = (window as any).gon.ee_trial_key;
if (eeTrialKey) {
let savedDateStr = eeTrialKey.created.split(' ')[0];
this.created = this.timezoneService.formattedDate(savedDateStr);
}
this.eeTrialService.userData$
.values$()
.pipe(
distinctUntilChanged(),
)
.subscribe(userForm => {
this.email = userForm.email;
});
}
// resend mail if resend link has been clicked

@ -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";
@ -22,8 +22,8 @@ export class EnterpriseTrialService {
// user data needs to be sync in ee-active-trial.component.ts
userData$ = input<EnterpriseTrialData>();
public baseUrlAugur:string;
public readonly baseUrlAugur:string;
public readonly tokenVersion:string;
public trialLink:string;
public resendLink:string;
@ -46,6 +46,7 @@ export class EnterpriseTrialService {
protected notificationsService:NotificationsService) {
let gon = (window as any).gon;
this.baseUrlAugur = gon.augur_url;
this.tokenVersion = gon.token_version;
if ((window as any).gon.ee_trial_key) {
this.setMailSubmittedStatus();
@ -55,7 +56,8 @@ export class EnterpriseTrialService {
// send POST request with form object
// receive an enterprise trial link to access a token
public sendForm(form:FormGroup) {
this.http.post(this.baseUrlAugur + '/public/v1/trials', form.value)
const request = { ...form.value, token_version: this.tokenVersion};
this.http.post(this.baseUrlAugur + '/public/v1/trials', request)
.toPromise()
.then((enterpriseTrial:any) => {
this.userData$.putValue(form.value);
@ -91,13 +93,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 +139,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'));
});
}

@ -148,6 +148,19 @@ describe 'Enterprise trial management',
}
end
let(:other_error_body) do
{
_type: "error",
code: 409,
description: "Token version is invalid",
identifier: "token_version_too_old",
errors: {
token_version: [
"does not have a valid value"
]
}
}
end
before do
login_as(admin)
@ -159,7 +172,6 @@ describe 'Enterprise trial management',
fill_in 'First name', with: 'Foo'
fill_in 'Last name', with: 'Bar'
fill_in 'Email', with: mail
fill_in 'Domain', with: 'foo.example.com'
find('#trial-general-consent').check
end
@ -190,6 +202,18 @@ describe 'Enterprise trial management',
expect(page).to have_no_text 'email sent - waiting for confirmation'
end
it 'shows an error in case of other errors' do
proxy.stub('https://augur.openproject-edge.com:443/public/v1/trials', method: 'post')
.and_return(headers: { 'Access-Control-Allow-Origin' => '*' }, code: 409, body: other_error_body.to_json)
find('.button', text: 'Start free trial').click
fill_out_modal
find('.button:not(:disabled)', text: 'Submit').click
expect(page).to have_text('Token version is invalid')
expect(page).to have_no_text 'email sent - waiting for confirmation'
end
context 'with a waiting request pending' do
before do
proxy.stub('https://augur.openproject-edge.com:443/public/v1/trials', method: 'post')

Loading…
Cancel
Save