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

restructure aaj configuration

ulferts7f811f7931dd
diff --git a/lib/ar_condition.rb b/lib/ar_condition.rb
index 42f9cc69082..56ed981d1d6 100644
--- a/lib/ar_condition.rb
+++ b/lib/ar_condition.rb
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2020 the OpenProject GmbH
diff --git a/lib/plugins/acts_as_journalized/lib/acts_as_journalized.rb b/lib/plugins/acts_as_journalized/lib/acts_as_journalized.rb
index 3fad6c13f02..6f30e622042 100644
--- a/lib/plugins/acts_as_journalized/lib/acts_as_journalized.rb
+++ b/lib/plugins/acts_as_journalized/lib/acts_as_journalized.rb
@@ -27,6 +27,7 @@
#++
#-- encoding: UTF-8
+
# This file is part of the acts_as_journalized plugin for the redMine
# project management software
#
@@ -50,7 +51,6 @@ require 'journal_changes'
require 'journal_formatter'
Dir[File.expand_path('../redmine/acts/journalized/*.rb', __FILE__)].each { |f| require f }
Dir[File.expand_path('../acts/journalized/*.rb', __FILE__)].each { |f| require f }
-require 'ar_condition'
module Redmine
module Acts
@@ -70,24 +70,11 @@ module Redmine
# Versioning and acting as an Event may only be applied once.
# To apply more than on activity, use acts_as_activity
def acts_as_journalized(options = {}, &block)
- _, _, journal_hash = split_option_hashes(options)
-
return if journaled?
- include Options
- include Creation
- include Reversion
- include Permissions
- include SaveHooks
- include FormatHooks
-
- # FIXME: When the transition to the new API is complete, remove me
- include Deprecated
-
- (journal_hash[:except] ||= []) << primary_key << inheritance_column <<
- :updated_on << :updated_at << :lock_version << :lft << :rgt
+ include_aaj_modules
- journal_hash = prepare_journaled_options(journal_hash)
+ journal_hash = prepare_journaled_options(options)
has_many :journals, -> {
order("#{Journal.table_name}.version ASC")
@@ -96,40 +83,16 @@ module Redmine
private
- # Splits an option has into three hashes:
- ## => [{ options prefixed with "activity_" }, { options prefixed with "event_" }, { other options }]
- def split_option_hashes(options)
- activity_hash = {}
- event_hash = {}
- journal_hash = {}
-
- options.each_pair do |k, v|
- case
- when k.to_s =~ /\Aactivity_(.+)\z/
- activity_hash[$1.to_sym] = v
- when k.to_s =~ /\Aevent_(.+)\z/
- event_hash[$1.to_sym] = v
- else
- journal_hash[k.to_sym] = v
- end
- end
- [activity_hash, event_hash, journal_hash]
- end
+ def include_aaj_modules
+ include Options
+ include Creation
+ include Reversion
+ include Permissions
+ include SaveHooks
+ include FormatHooks
- # Merges the event hashes defaults with the options provided by the user
- # The defaults take their details from the journal
- def journalized_event_hash(options)
- unless options.has_key? :url
- options[:url] = Proc.new do |data|
- { controller: plural_name,
- action: 'show',
- id: data.journal.journable_id,
- anchor: ("note-#{data.journal.anchor}" unless data.journal.initial?) }
- end
- end
- options[:type] ||= name.underscore.dasherize # Make sure the name of the journalized model and not the name of the journal is used for events
- options[:author] ||= :user
- { description: :notes }.reverse_merge options
+ # FIXME: When the transition to the new API is complete, remove me
+ include Deprecated
end
end
end
diff --git a/lib/plugins/acts_as_journalized/lib/redmine/acts/journalized/options.rb b/lib/plugins/acts_as_journalized/lib/redmine/acts/journalized/options.rb
index 90f44f2f060..74e938810d9 100644
--- a/lib/plugins/acts_as_journalized/lib/redmine/acts/journalized/options.rb
+++ b/lib/plugins/acts_as_journalized/lib/redmine/acts/journalized/options.rb
@@ -88,13 +88,7 @@ module Redmine::Acts::Journalized
# The method is overridden in feature modules that require specific options outside the
# standard +has_many+ associations.
def prepare_journaled_options(options)
- result_options = options.symbolize_keys
- result_options.reverse_merge!(
- class_name: Journal.name,
- dependent: :delete_all,
- foreign_key: :journable_id,
- as: :journable
- )
+ result_options = options_with_defaults(options)
class_attribute :vestal_journals_options
self.vestal_journals_options = result_options.dup
@@ -105,6 +99,44 @@ module Redmine::Acts::Journalized
result_options
end
+
+ private
+
+ def options_with_defaults(options)
+ journal_options = split_option_hashes(options)
+
+ journal_options[:except] ||= []
+ journal_options[:except] += [primary_key, inheritance_column, :updated_on, :updated_at, :lock_version, :lft, :rgt]
+
+ result_options = journal_options.symbolize_keys
+ result_options.reverse_merge!(
+ class_name: Journal.name,
+ dependent: :delete_all,
+ foreign_key: :journable_id,
+ as: :journable
+ )
+
+ result_options
+ end
+
+ # Splits an option has into three hashes:
+ ## => [{ options prefixed with "activity_" }, { options prefixed with "event_" }, { other options }]
+ def split_option_hashes(options)
+ journal_hash = {}
+
+ options.each_pair do |k, v|
+ case k.to_s
+ when /\Aactivity_(.+)\z/
+ raise "Configuring activity via acts_as_journalized is no longer supported."
+ when /\Aevent_(.+)\z/
+ raise "Configuring events via acts_as_journalized is no longer supported."
+ else
+ journal_hash[k.to_sym] = v
+ end
+ end
+
+ journal_hash
+ end
end
end
end