From 9d525328743191638edc4421bb45a5903c2671ec Mon Sep 17 00:00:00 2001 From: ulferts Date: Tue, 25 Feb 2020 16:53:20 +0100 Subject: [PATCH 1/3] replace unloadable constants in initializers --- app/models/project/activity.rb | 8 ++++---- config/initializers/activity.rb | 20 +++++++++---------- .../costs/lib/open_project/costs/engine.rb | 2 +- .../lib/open_project/meeting/engine.rb | 2 +- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/app/models/project/activity.rb b/app/models/project/activity.rb index af48dc8f517..297df9dd8f2 100644 --- a/app/models/project/activity.rb +++ b/app/models/project/activity.rb @@ -43,11 +43,11 @@ module Project::Activity def latest_project_activity @latest_project_activity ||= - Constants::ProjectActivity.registered.map { |params| - build_latest_project_activity_for(on: params[:on], - chain: params[:chain], + Constants::ProjectActivity.registered.map do |params| + build_latest_project_activity_for(on: params[:on].constantize, + chain: Array(params[:chain]).map(&:constantize), attribute: params[:attribute]) - } + end end def with_latest_activity diff --git a/config/initializers/activity.rb b/config/initializers/activity.rb index 24d38a6d423..cab899a75fd 100644 --- a/config/initializers/activity.rb +++ b/config/initializers/activity.rb @@ -40,25 +40,23 @@ Redmine::Activity.map do |activity| default: false end -# TODO: replace by string based references to avoid stale -# objects when reloading in dev mode. -Project.register_latest_project_activity on: WorkPackage, +Project.register_latest_project_activity on: 'WorkPackage', attribute: :updated_at -Project.register_latest_project_activity on: News, +Project.register_latest_project_activity on: 'News', attribute: :updated_at -Project.register_latest_project_activity on: Changeset, - chain: Repository, +Project.register_latest_project_activity on: 'Changeset', + chain: 'Repository', attribute: :committed_on -Project.register_latest_project_activity on: WikiContent, - chain: [Wiki, WikiPage], +Project.register_latest_project_activity on: 'WikiContent', + chain: %w(Wiki WikiPage), attribute: :updated_on -Project.register_latest_project_activity on: Message, - chain: Forum, +Project.register_latest_project_activity on: 'Message', + chain: 'Forum', attribute: :updated_on -Project.register_latest_project_activity on: TimeEntry, +Project.register_latest_project_activity on: 'TimeEntry', attribute: :updated_on diff --git a/modules/costs/lib/open_project/costs/engine.rb b/modules/costs/lib/open_project/costs/engine.rb index 263ef36f359..cc551a725b1 100644 --- a/modules/costs/lib/open_project/costs/engine.rb +++ b/modules/costs/lib/open_project/costs/engine.rb @@ -351,7 +351,7 @@ module OpenProject::Costs end initializer 'costs.register_latest_project_activity' do - Project.register_latest_project_activity on: ::CostObject, + Project.register_latest_project_activity on: 'CostObject', attribute: :updated_on end diff --git a/modules/meeting/lib/open_project/meeting/engine.rb b/modules/meeting/lib/open_project/meeting/engine.rb index bc5ca50ff49..259301be43a 100644 --- a/modules/meeting/lib/open_project/meeting/engine.rb +++ b/modules/meeting/lib/open_project/meeting/engine.rb @@ -90,7 +90,7 @@ module OpenProject::Meeting end initializer 'meeting.register_latest_project_activity' do - Project.register_latest_project_activity on: ::Meeting, + Project.register_latest_project_activity on: 'Meeting', attribute: :updated_at end From 9a11f0c9bdf42a6bd2a70ffe908af67c33a95334 Mon Sep 17 00:00:00 2001 From: ulferts Date: Wed, 26 Feb 2020 08:25:18 +0100 Subject: [PATCH 2/3] place language/framework/gem patches in distinct folder --- .../{reform.rb => 10-load_patches.rb} | 26 ++----------- config/initializers/assets.rb | 1 - config/initializers/health_checks.rb | 1 - config/initializers/menus.rb | 3 +- config/initializers/zeitwerk.rb | 1 + .../patches/action_view_accessible_errors.rb | 31 +-------------- .../action_view_helpers_asset_tag_helper.rb | 4 +- .../patches/active_model_errors.rb | 0 .../patches/active_record_i18n.rb | 38 +++++++++++++++++++ lib/open_project/patches/array.rb | 7 ---- .../patches}/eager_load_with_hours.rb | 0 .../open_project/patches}/i18n_patch.rb | 0 lib/open_project/patches/reform.rb | 25 ++++++++++++ .../open_project/patches/representable.rb | 6 +-- 14 files changed, 76 insertions(+), 67 deletions(-) rename config/initializers/{reform.rb => 10-load_patches.rb} (68%) rename config/initializers/10-patches.rb => lib/open_project/patches/action_view_accessible_errors.rb (88%) rename config/initializers/action_view_helpers_asset_tag_helper_patch.rb => lib/open_project/patches/action_view_helpers_asset_tag_helper.rb (89%) rename config/initializers/active_model_errors_patch.rb => lib/open_project/patches/active_model_errors.rb (100%) create mode 100644 lib/open_project/patches/active_record_i18n.rb rename {config/initializers => lib/open_project/patches}/eager_load_with_hours.rb (100%) rename {config/initializers => lib/open_project/patches}/i18n_patch.rb (100%) rename config/initializers/representable_patch.rb => lib/open_project/patches/representable.rb (92%) diff --git a/config/initializers/reform.rb b/config/initializers/10-load_patches.rb similarity index 68% rename from config/initializers/reform.rb rename to config/initializers/10-load_patches.rb index bc83a8e674a..6a7e79ecf30 100644 --- a/config/initializers/reform.rb +++ b/config/initializers/10-load_patches.rb @@ -28,27 +28,9 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -require "reform/form/active_model/validations" +# Do not place any patches within this file. Add a file to lib/open_project/patches -Reform::Form.class_eval do - include Reform::Form::ActiveModel::Validations -end - -Reform::Contract.class_eval do - include Reform::Form::ActiveModel::Validations -end - -Reform::Form::ActiveModel::Validations::Validator.class_eval do - ## - # use activerecord as the base scope instead of 'activemodel' to be compatible - # to the messages we have already stored - def self.i18n_scope - :activerecord - end -end - -require 'reform/contract' - -class Reform::Form::ActiveModel::Errors - prepend OpenProject::Patches::Reform +# Whatever ruby file is placed in lib/open_project/patches is required +Dir.glob(File.expand_path("../../../lib/open_project/patches/*.rb", __FILE__)).each do |path| + require path end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 2dd504cdce1..3b506310481 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -24,6 +24,5 @@ OpenProject::Application.configure do work_packages.js vendor/ckeditor/ckeditor.*js vendor/enjoyhint.js - bundles/openproject-legacy-app.js ) end diff --git a/config/initializers/health_checks.rb b/config/initializers/health_checks.rb index 88639771113..fc3a675c091 100644 --- a/config/initializers/health_checks.rb +++ b/config/initializers/health_checks.rb @@ -46,7 +46,6 @@ OkComputer::CheckCollection.new('full').tap do |collection| OkComputer::Registry.default_collection.register 'full', collection end - # Check if authentication required authentication_password = OpenProject::Configuration.health_checks_authentication_password if authentication_password.present? diff --git a/config/initializers/menus.rb b/config/initializers/menus.rb index ff0a0871829..3fbd59f543c 100644 --- a/config/initializers/menus.rb +++ b/config/initializers/menus.rb @@ -57,7 +57,8 @@ Redmine::MenuManager.map :top_menu do |menu| (User.current.logged? || !Setting.login_required?) && User.current.allowed_to?(:view_time_entries, nil, global: true) } - menu.push :help, OpenProject::Static::Links.help_link, + menu.push :help, + OpenProject::Static::Links.help_link, last: true, caption: '', icon: 'icon5 icon-help', diff --git a/config/initializers/zeitwerk.rb b/config/initializers/zeitwerk.rb index c61389026b4..61b61201bc2 100644 --- a/config/initializers/zeitwerk.rb +++ b/config/initializers/zeitwerk.rb @@ -55,5 +55,6 @@ end # Instruct zeitwerk to ignore all the engine gems' lib initialization files Rails.autoloaders.main.ignore(Rails.root.join('modules/*/lib/openproject-*.rb')) Rails.autoloaders.main.ignore(Rails.root.join('lib/plugins')) +Rails.autoloaders.main.ignore(Rails.root.join('lib/open_project/patches')) Rails.autoloaders.main.ignore(Rails.root.join('lib/generators')) Rails.autoloaders.main.ignore(Bundler.bundle_path.join('**/*.rb')) diff --git a/config/initializers/10-patches.rb b/lib/open_project/patches/action_view_accessible_errors.rb similarity index 88% rename from config/initializers/10-patches.rb rename to lib/open_project/patches/action_view_accessible_errors.rb index ea46d0a24ee..8b0a961e79a 100644 --- a/config/initializers/10-patches.rb +++ b/lib/open_project/patches/action_view_accessible_errors.rb @@ -1,5 +1,3 @@ -#-- encoding: UTF-8 - #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -28,19 +26,6 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -require 'active_record' - -module ActiveRecord - class Base - include Redmine::I18n - - def self.human_attribute_name(attr, options = {}) - attr = attr.to_s.gsub(/_id\z/, '') - super - end - end -end - module ActionView module Helpers module Tags @@ -138,8 +123,6 @@ module ActionView end end -ActionView::Base.send :include, ActionView::Helpers::AccessibleErrors - ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| if html_tag.include?(' Date: Wed, 26 Feb 2020 09:32:35 +0100 Subject: [PATCH 3/3] remove now unnecessary initializer API reloading is handled by zeitwerk --- config/initializers/reload_api.rb | 39 ------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 config/initializers/reload_api.rb diff --git a/config/initializers/reload_api.rb b/config/initializers/reload_api.rb deleted file mode 100644 index d24bbdb7687..00000000000 --- a/config/initializers/reload_api.rb +++ /dev/null @@ -1,39 +0,0 @@ -#-- copyright -# OpenProject is an open source project management software. -# Copyright (C) 2012-2020 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-2017 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 docs/COPYRIGHT.rdoc for more details. -#++ - -if Rails.env.development? - ActiveSupport::Dependencies.explicitly_unloadable_constants << 'API' - - api_files = Dir[Rails.root.join('lib', 'api', '**', '*.rb')] - api_reloader = ActiveSupport::FileUpdateChecker.new(api_files) do - Rails.application.reload_routes! - end - ActiveSupport::Reloader.to_prepare do - api_reloader.execute_if_updated - end -end