From aedfa6ba2c421b49b74ef677f8745247b23da0c5 Mon Sep 17 00:00:00 2001 From: ulferts Date: Wed, 30 Mar 2022 22:00:09 +0200 Subject: [PATCH] avoid reference to Project in initializer --- app/models/projects/activity.rb | 10 +---- .../open_project/project_activity.rb | 41 ++++++++++++++++++ config/constants/project_activity.rb | 43 ------------------- config/initializers/activity.rb | 28 ++++++------ modules/budgets/lib/budgets/engine.rb | 4 +- modules/costs/lib/costs/engine.rb | 4 +- .../lib/open_project/meeting/engine.rb | 4 +- 7 files changed, 63 insertions(+), 71 deletions(-) create mode 100644 config/constants/open_project/project_activity.rb delete mode 100644 config/constants/project_activity.rb diff --git a/app/models/projects/activity.rb b/app/models/projects/activity.rb index 36961dee53..6f34bd5a30 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 0000000000..394a712fc0 --- /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 faaff8c380..0000000000 --- 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 555266553a..c687f92378 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 9e5dcd24d1..93a566c78a 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 a10b13a8af..09496bde7c 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 1c9387f861..4900c4f4a2 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