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
extract validity period and use as a scope
Klaus Zanders0bc9074a8bee
diff --git a/app/models/enterprise_token.rb b/app/models/enterprise_token.rbindex 1f1fc763c5e..e92d44607f2 100644--- a/app/models/enterprise_token.rb+++ b/app/models/enterprise_token.rb@@ -97,6 +97,7 @@ class EnterpriseToken < ApplicationRecorddef set_active_tokensEnterpriseToken+ .active.order(Arel.sql("created_at DESC")).to_a.reject(&:expired?)@@ -121,9 +122,18 @@ class EnterpriseToken < ApplicationRecordvalidate :valid_token_objectvalidate :valid_domain+ before_validation :extract_validity_from_tokenbefore_save :clear_current_tokens_cachebefore_destroy :clear_current_tokens_cache+ scope :active, ->(date = Date.current) {+ where(<<~SQL.squish, date: date)+ (valid_from IS NULL OR valid_from <= :date)+ AND+ (valid_until IS NULL OR valid_until >= :date)+ SQL+ }+delegate :will_expire?,:subscriber,:mail,@@ -193,4 +203,13 @@ class EnterpriseToken < ApplicationRecorddef valid_domainerrors.add :domain, :invalid if invalid_domain?end++ def extract_validity_from_token+ return unless token_object++ self.valid_from = token_object.starts_at+ self.valid_until = if token_object.will_expire?+ token_object.expires_at.next_day(token_object.reprieve_days.to_i)+ end+ endenddiff --git a/db/migrate/20250610111413_add_validity_period_to_enterprise_token.rb b/db/migrate/20250610111413_add_validity_period_to_enterprise_token.rbnew file mode 100644index 00000000000..5634b94844c--- /dev/null+++ b/db/migrate/20250610111413_add_validity_period_to_enterprise_token.rb@@ -0,0 +1,12 @@+# frozen_string_literal: true++class AddValidityPeriodToEnterpriseToken < ActiveRecord::Migration[8.0]+ def change+ change_table :enterprise_tokens, bulk: true do |table|+ table.column :valid_from, :date+ table.column :valid_until, :date++ table.index %i[valid_from valid_until]+ end+ end+end