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
Add limit for retrying to confirm mail
Inga Maia24040faf4af
diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rbindex 2ed98b73b79..5dd1605a562 100644--- a/app/controllers/enterprises_controller.rb+++ b/app/controllers/enterprises_controller.rb@@ -26,9 +26,13 @@# See docs/COPYRIGHT.rdoc for more details.#++class EnterprisesController < ApplicationController+ include EnterpriseTrialHelper+layout 'admin'menu_item :enterprise+ before_action :augur_content_security_policy+ before_action :chargebee_content_security_policybefore_action :require_adminbefore_action :check_user_limit, only: [:show]diff --git a/app/helpers/augur_helper.rb b/app/helpers/augur_helper.rbdeleted file mode 100644index b116c2886d6..00000000000--- a/app/helpers/augur_helper.rb+++ /dev/null@@ -1,7 +0,0 @@-module AugurHelper- def augur_content_security_policy- controller.append_content_security_policy_directives(- connect_src: %w(augur.openproject-edge.com)- )- end-enddiff --git a/app/helpers/enterprise_trial_helper.rb b/app/helpers/enterprise_trial_helper.rbnew file mode 100644index 00000000000..cbbec620756--- /dev/null+++ b/app/helpers/enterprise_trial_helper.rb@@ -0,0 +1,15 @@+module EnterpriseTrialHelper+ def augur_content_security_policy+ append_content_security_policy_directives(+ connect_src: %w(augur.openproject-edge.com)+ )+ end++ def chargebee_content_security_policy+ append_content_security_policy_directives(+ script_src: %w(js.chargebee.com),+ style_src: %w(js.chargebee.com openproject-enterprise-test.chargebee.com),+ frame_src: %w(js.chargebee.com openproject-enterprise-test.chargebee.com)+ )+ end+end\ No newline at end of filediff --git a/app/views/enterprises/_info.html.erb b/app/views/enterprises/_info.html.erbindex a1965907e63..63314f1a275 100644--- a/app/views/enterprises/_info.html.erb+++ b/app/views/enterprises/_info.html.erb@@ -26,16 +26,21 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.See docs/COPYRIGHT.rdoc for more details.++#%>-<span hidden><%= augur_content_security_policy %></span>+<% content_for :header_tags do %>+ <script src="https://js.chargebee.com/v2/chargebee.js"+ data-cb-site="openproject-enterprise-test">+ </script>+<% end %><p>- <b><%= t('js.admin.enterprise.upsale.become_hero') %></b><br> <%= t('js.admin.enterprise.upsale.you_contribute') %>+ <b><%= t('js.admin.enterprise.upsale.become_hero') %></b><br>+ <%= t('js.admin.enterprise.upsale.you_contribute') %></p><enterprise></enterprise><div class="info-boxes upsale-benefits">- <h2>What are the benefits</h2>+ <h2><%= t('homescreen.blocks.upsale.description') %></h2><div class="info-boxes--container"><div class="info-boxes--item"><%= image_tag "https://1t1rycb9er64f1pgy2iuseow-wpengine.netdna-ssl.com/wp-content/uploads/2017/06/icon-security-features.png",diff --git a/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial.modal.html b/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial.modal.htmlindex a856be6b2ee..6bd3f701b75 100644--- a/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial.modal.html+++ b/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial.modal.html@@ -90,8 +90,7 @@<div class="form--check-box-container"><input type="checkbox"class="form--check-box"- formControlName="newsletter_consent"- (change)="receiveNewsletter($event)">+ formControlName="newsletter_consent"></div><span>I want to receive the OpenProject<a href="https://www.openproject.com/newsletter/" target="_blank">@@ -111,6 +110,7 @@<span *ngIf="!confirmed; else confirmedStatus" class="status--waiting">email sent - waiting for confirmation<a id="resend-link" (click)="resendMail()">{{ text.resend }}</a>+ <p *ngIf="cancelled">Sorry, something went wrong. Please try to resend mail.</p></span><ng-template #confirmedStatus><span class="status--confirmed">confirmed ✓</span>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.tsindex 502a53cd7b5..0d713a7db7c 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@@ -117,8 +117,8 @@ export class EnterpriseTrialModal extends OpModalComponent {this.text = _.defaults(this.options.text, this.text);}+ // checks if form is valid and submits itpublic onSubmit() {- // check if form is valid and handle input errorsif (this.enterpriseTrialForm.valid) {this.enterpriseTrialForm.addControl('_type', new FormControl('enterprise-trial'));@@ -126,15 +126,20 @@ export class EnterpriseTrialModal extends OpModalComponent {}}- public sendForm(form:FormGroup) {+ // sends POST request with form object+ // receives an enterprise trial link to access a token+ private sendForm(form:FormGroup) {+ const delay = 5000; // wait 5s until next request+ const retries = 60; // keep trying for 5 minutesconst trialPath = 'https://augur.openproject-edge.com/public/v1/trials';- // POST /public/v1/trials/ (send POST with form object)++ // POST /public/v1/trials/this.http.post(trialPath, form).toPromise().then((enterpriseTrial:any) => {this.trialLink = enterpriseTrial._links.self.href;- this.confirmMailAddress();+ this.retryConfirmation(delay, retries);}).catch((error:HttpErrorResponse) => {// mail is invalid or user already created a trial@@ -147,7 +152,8 @@ export class EnterpriseTrialModal extends OpModalComponent {});}- public confirmMailAddress() {+ // gets a token from the trial link if user confirmed mail+ private getToken() {// 2) GET /public/v1/trials/:idthis.http.get<any>(this.baseUrlAugur + this.trialLink)@@ -161,20 +167,10 @@ export class EnterpriseTrialModal extends OpModalComponent {.catch((error:HttpErrorResponse) => {// returns error 422 while waiting of confirmationif (error.status === 422 && error.error.identifier === 'waiting_for_email_verification') {- // open next modal window- // status waiting+ // open next modal window -> status waitingthis.status = 'mailSubmitted';-// get resend button linkthis.resendLink = error.error._links.resend.href;-- // TODO add limit for retrying- setTimeout( () => {- // retry as long as modal is open and action is not cancelled- if (!this.cancelled) {- this.confirmMailAddress();- }- }, 5000);} else if (_.get(error, 'error._type') === 'Error') {this.notificationsService.addWarning(error.error.message);} else {@@ -184,45 +180,54 @@ export class EnterpriseTrialModal extends OpModalComponent {});}- // TODO+ // saves received token in controllerprivate saveToken(token:string) {// POST /admin/enterprise (params[:enterprise_token][:encoded_token])// -> if token is new (token_retrieved: false) save token in ruby controllerthis.http.post(this.pathHelper.api.v3.appBasePath + '/admin/enterprise', { enterprise_token: { encoded_token: token } }, { withCredentials: true }).toPromise().then((res:any) => {- // TODO: needs clarification: show token to copy?console.log('saveToken() success: ', res);}).catch((error:HttpErrorResponse) => {console.log('saveToken() failed: ', error.error);+ this.notificationsService.addWarning(error.error.description || I18n.t('js.error.internal'));});}- // TODO: needs specification+ // retries request while waiting for mail confirmation+ private retryConfirmation(delay:number, retries:number) {+ if (this.cancelled || this.confirmed) {+ // stop if action was cancelled or confirmation link was clicked+ return;+ } else if (retries === 0) {+ // action timed out -> show message+ this.cancelled = true;+ } else {+ // retry as long as limit isn't reached+ this.getToken();+ setTimeout( () => {+ this.retryConfirmation(delay, retries - 1);+ }, delay);+ }+ }++ // TODO: add enterprise onboarding youtube videopublic startEnterpriseTrial() {// open onboarding modalthis.status = 'startTrial';- console.log(this.status);- // on continue:- // this.closeModal();- // reload page to show enterprise trial- }-- public checkMailField() {- if (this.enterpriseTrialForm.value.email !== '' && this.enterpriseTrialForm.controls.email.errors) {- this.errorMsg = 'Invalid e-mail address';- } else {- this.errorMsg = undefined;- }}+ // resends mail if resend link has been clickedpublic resendMail() {this.http.post(this.baseUrlAugur + this.resendLink, {}).toPromise().then((enterpriseTrial:any) => {console.log('Mail has been resent.');this.notificationsService.addSuccess('Mail has been resent. Please check your mails and click the confirmation link provided.');++ this.cancelled = false;+ this.retryConfirmation(5000, 6);}).catch((error:HttpErrorResponse) => {console.log('An Error occured: ', error);@@ -230,9 +235,13 @@ export class EnterpriseTrialModal extends OpModalComponent {});}- public receiveNewsletter(event:any) {- if (event.target.checked) {- // subscribe to newsletter+ // checks if mail is valid after input field was edited by the user+ // displays message for user+ public checkMailField() {+ if (this.enterpriseTrialForm.value.email !== '' && this.enterpriseTrialForm.controls.email.errors) {+ this.errorMsg = 'Invalid e-mail address';+ } else {+ this.errorMsg = undefined;}}@@ -240,7 +249,7 @@ export class EnterpriseTrialModal extends OpModalComponent {// cancel all actions (e.g. an already send request)this.cancelled = true;this.closeMe(event);- // refresh page to show trial+ // refresh page to show enterprise trialif (this.status === 'startTrial' || this.confirmed) {window.location.reload();}diff --git a/frontend/src/app/components/enterprise/enterprise.component.html b/frontend/src/app/components/enterprise/enterprise.component.htmlindex cb29a8f8ba3..fc05b932306 100644--- a/frontend/src/app/components/enterprise/enterprise.component.html+++ b/frontend/src/app/components/enterprise/enterprise.component.html@@ -1,6 +1,11 @@<div class='upsale--actions'><button class="button -alt-highlight" (click)="openTrialModal()">{{ text.button_trial }}</button>- <button class="button -highlight">{{ text.button_book }}</button>+ <a href="javascript:void(0)"+ class="button -highlight"+ data-cb-type="checkout"+ data-cb-plan-id="enterprise-edition---annual-user-license">+ {{ text.button_book }}+ </a><a href="https://www.openproject.org/upgrade-enterprise-edition/" target="_blank">{{ text.link_quote }}</a>