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 validation for a single trial token, rename to active_trial_token
Oliver Günther06d78fe8f0e1
diff --git a/app/components/enterprise_edition/trial_teaser_component.rb b/app/components/enterprise_edition/trial_teaser_component.rbindex 8962cf8d69d..933374769ed 100644--- a/app/components/enterprise_edition/trial_teaser_component.rb+++ b/app/components/enterprise_edition/trial_teaser_component.rb@@ -59,7 +59,7 @@ module EnterpriseEditionenddef token- @token ||= EnterpriseToken.active_trial_tokens.last+ @token ||= EnterpriseToken.active_trial_tokenenddef titlediff --git a/app/models/enterprise_token.rb b/app/models/enterprise_token.rbindex c7b6af9c801..809cbc579ab 100644--- a/app/models/enterprise_token.rb+++ b/app/models/enterprise_token.rb@@ -45,8 +45,8 @@ class EnterpriseToken < ApplicationRecordactive_tokens.reject(&:trial?)end- def active_trial_tokens- active_tokens.select(&:trial?)+ def active_trial_token+ active_tokens.find(&:trial?)enddef table_exists?@@ -62,7 +62,7 @@ class EnterpriseToken < ApplicationRecordenddef trial_only?- active_non_trial_tokens.empty? && active_trial_tokens.any?+ active_non_trial_tokens.empty? && active_trial_token.present?enddef available_features@@ -88,8 +88,8 @@ class EnterpriseToken < ApplicationRecorddef user_limitif active_non_trial_tokens.any?get_user_limit_of(active_non_trial_tokens)- else- get_user_limit_of(active_trial_tokens)+ elsif active_trial_token+ get_user_limit_of([active_trial_token])endend@@ -122,6 +122,7 @@ class EnterpriseToken < ApplicationRecorduniqueness: { message: I18n.t("activerecord.errors.models.enterprise_token.already_added") }validate :valid_token_objectvalidate :valid_domain+ validate :one_trial_tokenbefore_validation :strip_encoded_tokenbefore_save :extract_validity_from_token@@ -247,6 +248,12 @@ class EnterpriseToken < ApplicationRecorderrors.add :domain, :invalid if invalid_domain?end+ def one_trial_token+ if self.class.active_trial_token.present?+ errors.add :base, :only_one_trial+ end+ end+def extract_validity_from_tokenreturn unless token_objectdiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 46e1c8d486c..fe507172c70 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1351,6 +1351,7 @@ en:failed_to_create: "Trial could not be created (%{status})"general_consent: "Please accept the terms and conditions."enterprise_token:+ only_one_trial: "Only one trial token can be active. Please delete the previous trial token before adding another."unreadable: "can't be read. Are you sure it is a support token?"already_added: "This token has already been added."grids/grid:diff --git a/spec/components/enterprise_edition/trial_teaser_component_spec.rb b/spec/components/enterprise_edition/trial_teaser_component_spec.rbindex 28d10d0e9c7..56cf2683b70 100644--- a/spec/components/enterprise_edition/trial_teaser_component_spec.rb+++ b/spec/components/enterprise_edition/trial_teaser_component_spec.rb@@ -40,7 +40,7 @@ RSpec.describe EnterpriseEdition::TrialTeaserComponent, type: :component doendbefore do- allow(EnterpriseToken).to receive(:active_trial_tokens).and_return([mock_token])+ allow(EnterpriseToken).to receive(:active_trial_token).and_return(mock_token)endcontext "for an admin user" do