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

avoid reference to Project in initializer

ulfertsaedfa6ba2c42
diff --git a/app/models/projects/activity.rb b/app/models/projects/activity.rb
index 36961dee53d..6f34bd5a301 100644
--- a/app/models/projects/activity.rb
+++ b/app/models/projects/activity.rb
@@ -26,23 +26,15 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-require Rails.root.join('config/constants/project_activity')
-
module Projects::Activity
def self.included(base)
base.send :extend, ActivityScopes
end
module ActivityScopes
- def register_latest_project_activity(on:, attribute:, chain: [])
- Constants::ProjectActivity.register(on: on,
- chain: chain,
- attribute: attribute)
- end
-
def latest_project_activity
@latest_project_activity ||=
- Constants::ProjectActivity.registered.map do |params|
+ OpenProject::ProjectActivity.registered.map do |params|
build_latest_project_activity_for(on: params[:on].constantize,
chain: Array(params[:chain]).map(&:constantize),
attribute: params[:attribute])
diff --git a/config/constants/open_project/project_activity.rb b/config/constants/open_project/project_activity.rb
new file mode 100644
index 00000000000..394a712fc0e
--- /dev/null
+++ b/config/constants/open_project/project_activity.rb
@@ -0,0 +1,41 @@
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2022 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+
+module OpenProject
+ module ProjectActivity
+ class << self
+ def register(on:, attribute:, chain: [])
+ @registered ||= Set.new
+
+ @registered << { on: on,
+ chain: chain,
+ attribute: attribute }
+ end
+
+ attr_reader :registered
+ end
+ end
+end
diff --git a/config/constants/project_activity.rb b/config/constants/project_activity.rb
deleted file mode 100644
index faaff8c380c..00000000000
--- a/config/constants/project_activity.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2022 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-module Constants
- module ProjectActivity
- class << self
- def register(on:, attribute:, chain: [])
- @registered ||= Set.new
-
- @registered << { on: on,
- chain: chain,
- attribute: attribute }
- end
-
- attr_reader :registered
- end
- end
-end
diff --git a/config/initializers/activity.rb b/config/initializers/activity.rb
index 555266553a6..c687f92378b 100644
--- a/config/initializers/activity.rb
+++ b/config/initializers/activity.rb
@@ -26,6 +26,8 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+require_relative '../constants/open_project/project_activity'
+
Rails.application.reloader.to_prepare do
OpenProject::Activity.map do |activity|
activity.register :work_packages, class_name: '::Activities::WorkPackageActivityProvider'
@@ -38,21 +40,21 @@ Rails.application.reloader.to_prepare do
default: false
end
- Project.register_latest_project_activity on: 'WorkPackage',
- attribute: :updated_at
+ OpenProject::ProjectActivity.register on: 'WorkPackage',
+ attribute: :updated_at
- Project.register_latest_project_activity on: 'News',
- attribute: :updated_at
+ OpenProject::ProjectActivity.register on: 'News',
+ attribute: :updated_at
- Project.register_latest_project_activity on: 'Changeset',
- chain: 'Repository',
- attribute: :committed_on
+ OpenProject::ProjectActivity.register on: 'Changeset',
+ chain: 'Repository',
+ attribute: :committed_on
- Project.register_latest_project_activity on: 'WikiContent',
- chain: %w(Wiki WikiPage),
- attribute: :updated_at
+ OpenProject::ProjectActivity.register on: 'WikiContent',
+ chain: %w(Wiki WikiPage),
+ attribute: :updated_at
- Project.register_latest_project_activity on: 'Message',
- chain: 'Forum',
- attribute: :updated_at
+ OpenProject::ProjectActivity.register on: 'Message',
+ chain: 'Forum',
+ attribute: :updated_at
end
diff --git a/modules/budgets/lib/budgets/engine.rb b/modules/budgets/lib/budgets/engine.rb
index 9e5dcd24d18..93a566c78a0 100644
--- a/modules/budgets/lib/budgets/engine.rb
+++ b/modules/budgets/lib/budgets/engine.rb
@@ -48,8 +48,8 @@ module Budgets
end
config.to_prepare do
- Project.register_latest_project_activity on: 'Budget',
- attribute: :updated_at
+ OpenProject::ProjectActivity.register on: 'Budget',
+ attribute: :updated_at
# Add to the budget to the costs group
::Type.add_default_mapping(:costs, :budget)
diff --git a/modules/costs/lib/costs/engine.rb b/modules/costs/lib/costs/engine.rb
index a10b13a8af7..09496bde7cc 100644
--- a/modules/costs/lib/costs/engine.rb
+++ b/modules/costs/lib/costs/engine.rb
@@ -249,8 +249,8 @@ module Costs
end
config.to_prepare do
- Project.register_latest_project_activity on: 'TimeEntry',
- attribute: :updated_at
+ OpenProject::ProjectActivity.register on: 'TimeEntry',
+ attribute: :updated_at
Costs::Patches::MembersPatch.mixin!
diff --git a/modules/meeting/lib/open_project/meeting/engine.rb b/modules/meeting/lib/open_project/meeting/engine.rb
index 1c9387f861b..4900c4f4a29 100644
--- a/modules/meeting/lib/open_project/meeting/engine.rb
+++ b/modules/meeting/lib/open_project/meeting/engine.rb
@@ -81,8 +81,8 @@ module OpenProject::Meeting
end
config.to_prepare do
- Project.register_latest_project_activity on: 'Meeting',
- attribute: :updated_at
+ OpenProject::ProjectActivity.register on: 'Meeting',
+ attribute: :updated_at
PermittedParams.permit(:search, :meetings)
end