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
Remove subclass loading and use base controller
Oliver Günther7cfebcdb72c5
diff --git a/app/components/admin/enumerations/reassign_form.rb b/app/components/admin/enumerations/reassign_form.rbindex c4636f62e91..ddbee19bf2a 100644--- a/app/components/admin/enumerations/reassign_form.rb+++ b/app/components/admin/enumerations/reassign_form.rb@@ -58,7 +58,7 @@ module Admintag: :a,label: I18n.t(:button_cancel),scheme: :default,- href: admin_time_entry_activities_path)+ href: admin_settings_time_entry_activities_path)button_group.submit(name: :submit, label: I18n.t(:button_apply), scheme: :primary)endenddiff --git a/app/controllers/admin/settings/enumerations_controller_base.rb b/app/controllers/admin/settings/enumerations_controller_base.rbnew file mode 100644index 00000000000..214e0ce9422--- /dev/null+++ b/app/controllers/admin/settings/enumerations_controller_base.rb@@ -0,0 +1,154 @@+# frozen_string_literal: true++# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2010-2024 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 Admin+ module Settings+ class EnumerationsControllerBase < ApplicationController+ extend ActiveSupport::Concern+ include OpTurbo::ComponentStream++ before_action :require_admin+ before_action :find_enumeration, only: %i[edit update destroy move reassign]+ layout "admin"++ helper_method :index_component_class++ def index+ @enumerations = enumeration_class.all+ end++ def new+ @enumeration = enumeration_class.new+ end++ def edit; end++ def create+ @enumeration = enumeration_class.new(enumeration_permitted_params)++ if @enumeration.save+ flash[:notice] = I18n.t(:notice_successful_update)+ redirect_to(action: :index)+ else+ render action: :new, status: :unprocessable_entity+ end+ end++ def update+ if @enumeration.update(enumeration_permitted_params)+ flash[:notice] = I18n.t(:notice_successful_update)+ redirect_to(action: :index)+ else+ render action: :edit, status: :unprocessable_entity+ end+ end++ def destroy+ if @enumeration.in_use?+ handle_reassignment_on_deletion+ elsif @enumeration.destroy+ flash[:notice] = I18n.t(:notice_successful_delete)+ redirect_to(action: :index)+ else+ flash.now[:error] = I18n.t(:error_can_not_delete_entry)+ redirect_to(action: :index)+ end+ end++ def move+ if @enumeration.update(move_params)+ render_success_flash_message_via_turbo_stream(+ message: I18n.t(:enumeration_caption_order_changed)+ )+ else+ render_error_flash_message_via_turbo_stream(+ message: I18n.t(:enumeration_could_not_be_moved)+ )+ end++ replace_via_turbo_stream(+ component: index_component_class.new(enumerations: enumeration_class.all)+ )++ respond_with_turbo_streams+ end++ def reassign+ @other_enumerations = enumeration_class.all - [@enumeration]+ end++ def default_breadcrumb; end++ private++ def move_params+ move_to = params[:move_to]+ position = Integer(params[:position], exception: false)++ if move_to.in? %w(highest higher lower lowest)+ { move_to: move_to }+ elsif position+ { position: position }+ else+ {}+ end+ end++ def handle_reassignment_on_deletion+ reassign_to_id = params.dig(:enumeration, :reassign_to_id)++ if reassign_to_id.present?+ reassign_to = enumeration_class.find_by(id: reassign_to_id)+ @enumeration.destroy(reassign_to)+ flash[:notice] = I18n.t(:notice_successful_delete)+ redirect_to(action: :index)+ else+ redirect_to(action: :reassign, id: @enumeration.id)+ end+ end++ def find_enumeration+ @enumeration = enumeration_class.find(params[:id])+ end++ def enumeration_class+ raise NotImplementedError+ end++ def enumeration_permitted_params+ permitted_params.enumerations+ end++ def index_component_class+ ::Admin::Enumerations::IndexComponent+ end+ end+ end+enddiff --git a/app/controllers/admin/settings/work_package_priorities_controller.rb b/app/controllers/admin/settings/work_package_priorities_controller.rbindex 5c4169d3280..83b46ad6e28 100644--- a/app/controllers/admin/settings/work_package_priorities_controller.rb+++ b/app/controllers/admin/settings/work_package_priorities_controller.rb@@ -29,9 +29,7 @@# ++module Admin::Settings- class WorkPackagePrioritiesController < ApplicationController- include ::Admin::EnumerationsController-+ class WorkPackagePrioritiesController < EnumerationsControllerBasemenu_item :prioritiesprivatediff --git a/app/controllers/concerns/admin/enumerations_controller.rb b/app/controllers/concerns/admin/enumerations_controller.rbdeleted file mode 100644index 0afe3ffb771..00000000000--- a/app/controllers/concerns/admin/enumerations_controller.rb+++ /dev/null@@ -1,154 +0,0 @@-# frozen_string_literal: true--# -- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2010-2024 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 Admin- module EnumerationsController- extend ActiveSupport::Concern- include OpTurbo::ComponentStream-- included do- before_action :require_admin- before_action :find_enumeration, only: %i[edit update destroy move reassign]- layout "admin"-- helper_method :index_component_class- end-- def index- @enumerations = enumeration_class.all- end-- def new- @enumeration = enumeration_class.new- end-- def edit; end-- def create- @enumeration = enumeration_class.new(enumeration_permitted_params)-- if @enumeration.save- flash[:notice] = I18n.t(:notice_successful_update)- redirect_to(action: :index)- else- render action: :new, status: :unprocessable_entity- end- end-- def update- if @enumeration.update(enumeration_permitted_params)- flash[:notice] = I18n.t(:notice_successful_update)- redirect_to(action: :index)- else- render action: :edit, status: :unprocessable_entity- end- end-- def destroy- if @enumeration.in_use?- handle_reassignment_on_deletion- elsif @enumeration.destroy- flash[:notice] = I18n.t(:notice_successful_delete)- redirect_to(action: :index)- else- flash.now[:error] = I18n.t(:error_can_not_delete_entry)- redirect_to(action: :index)- end- end-- def move- if @enumeration.update(move_params)- render_success_flash_message_via_turbo_stream(- message: I18n.t(:enumeration_caption_order_changed)- )- else- render_error_flash_message_via_turbo_stream(- message: I18n.t(:enumeration_could_not_be_moved)- )- end-- replace_via_turbo_stream(- component: index_component_class.new(enumerations: enumeration_class.all)- )-- respond_with_turbo_streams- end-- def reassign- @other_enumerations = enumeration_class.all - [@enumeration]- end-- def default_breadcrumb; end-- private-- def move_params- move_to = params[:move_to]- position = Integer(params[:position], exception: false)-- if move_to.in? %w(highest higher lower lowest)- { move_to: move_to }- elsif position- { position: position }- else- {}- end- end-- def handle_reassignment_on_deletion- reassign_to_id = params.dig(:enumeration, :reassign_to_id)-- if reassign_to_id.present?- reassign_to = enumeration_class.find_by(id: reassign_to_id)- @enumeration.destroy(reassign_to)- flash[:notice] = I18n.t(:notice_successful_delete)- redirect_to(action: :index)- else- redirect_to(action: :reassign, id: @enumeration.id)- end- end-- def find_enumeration- @enumeration = enumeration_class.find(params[:id])- end-- def enumeration_class- raise NotImplementedError- end-- def enumeration_permitted_params- permitted_params.enumerations- end-- def index_component_class- ::Admin::Enumerations::IndexComponent- end- end-enddiff --git a/app/helpers/colors_helper.rb b/app/helpers/colors_helper.rbindex 2b6f36f65c0..f3989c4e506 100644--- a/app/helpers/colors_helper.rb+++ b/app/helpers/colors_helper.rb@@ -88,7 +88,7 @@ module ColorsHelperdef icon_for_color(color, options = {})return unless color- return unless color.hexcode.present?+ return if color.hexcode.blank?style = join_style_arguments("background-color: #{color.hexcode}",diff --git a/app/models/enumeration.rb b/app/models/enumeration.rbindex f1a7546fc57..d6c653771df 100644--- a/app/models/enumeration.rb+++ b/app/models/enumeration.rb@@ -174,8 +174,3 @@ class Enumeration < ApplicationRecordraise "Can't delete enumeration" if in_use?endend--# Force load the subclasses in development mode-%w(time_entry_activity issue_priority).each do |enum_subclass|- require enum_subclass-enddiff --git a/modules/costs/app/controllers/admin/time_entry_activities_controller.rb b/modules/costs/app/controllers/admin/settings/time_entry_activities_controller.rbsimilarity index 81%rename from modules/costs/app/controllers/admin/time_entry_activities_controller.rbrename to modules/costs/app/controllers/admin/settings/time_entry_activities_controller.rbindex e63d1e02992..0dfe0801b43 100644--- a/modules/costs/app/controllers/admin/time_entry_activities_controller.rb+++ b/modules/costs/app/controllers/admin/settings/time_entry_activities_controller.rb@@ -29,19 +29,19 @@#++module Admin- class TimeEntryActivitiesController < ApplicationController- include EnumerationsController+ module Settings+ class TimeEntryActivitiesController < EnumerationsControllerBase+ menu_item :time_entry_activities- menu_item :time_entry_activities+ private- private+ def enumeration_class+ TimeEntryActivity+ end- def enumeration_class- TimeEntryActivity- end-- def enumeration_param_key- enumeration_class.model_name.param_key+ def enumeration_param_key+ enumeration_class.model_name.param_key+ endendendenddiff --git a/modules/costs/app/views/admin/time_entry_activities/edit.html.erb b/modules/costs/app/views/admin/settings/time_entry_activities/edit.html.erbsimilarity index 93%rename from modules/costs/app/views/admin/time_entry_activities/edit.html.erbrename to modules/costs/app/views/admin/settings/time_entry_activities/edit.html.erbindex 7262cec808d..a9016dffcd3 100644--- a/modules/costs/app/views/admin/time_entry_activities/edit.html.erb+++ b/modules/costs/app/views/admin/settings/time_entry_activities/edit.html.erb@@ -36,7 +36,7 @@ See COPYRIGHT and LICENSE files for more details.[{ href: admin_index_path, text: t("label_administration") },{ href: admin_costs_settings_path, text: t(:project_module_costs) },- { href: admin_time_entry_activities_path, text: TimeEntryActivity.model_name.human(count: :other) },+ { href: admin_settings_time_entry_activities_path, text: TimeEntryActivity.model_name.human(count: :other) },@enumeration.name])diff --git a/modules/costs/app/views/admin/time_entry_activities/index.html.erb b/modules/costs/app/views/admin/settings/time_entry_activities/index.html.erbsimilarity index 100%rename from modules/costs/app/views/admin/time_entry_activities/index.html.erbrename to modules/costs/app/views/admin/settings/time_entry_activities/index.html.erbdiff --git a/modules/costs/app/views/admin/time_entry_activities/new.html.erb b/modules/costs/app/views/admin/settings/time_entry_activities/new.html.erbsimilarity index 94%rename from modules/costs/app/views/admin/time_entry_activities/new.html.erbrename to modules/costs/app/views/admin/settings/time_entry_activities/new.html.erbindex cc6ec6f721f..196024c158b 100644--- a/modules/costs/app/views/admin/time_entry_activities/new.html.erb+++ b/modules/costs/app/views/admin/settings/time_entry_activities/new.html.erb@@ -36,7 +36,7 @@ See COPYRIGHT and LICENSE files for more details.[{ href: admin_index_path, text: t("label_administration") },{ href: admin_costs_settings_path, text: t(:project_module_costs) },- { href: admin_time_entry_activities_path, text: TimeEntryActivity.model_name.human(count: :other) },+ { href: admin_settings_time_entry_activities_path, text: TimeEntryActivity.model_name.human(count: :other) },I18n.t(:label_new_time_entry_activity)])diff --git a/modules/costs/app/views/admin/time_entry_activities/reassign.html.erb b/modules/costs/app/views/admin/settings/time_entry_activities/reassign.html.erbsimilarity index 94%rename from modules/costs/app/views/admin/time_entry_activities/reassign.html.erbrename to modules/costs/app/views/admin/settings/time_entry_activities/reassign.html.erbindex d12f07b93c9..5c1857768a7 100644--- a/modules/costs/app/views/admin/time_entry_activities/reassign.html.erb+++ b/modules/costs/app/views/admin/settings/time_entry_activities/reassign.html.erb@@ -36,7 +36,7 @@ See COPYRIGHT and LICENSE files for more details.[{ href: admin_index_path, text: t("label_administration") },{ href: admin_costs_settings_path, text: t(:project_module_costs) },- { href: admin_time_entry_activities_path, text: TimeEntryActivity.model_name.human(count: :other) },+ { href: admin_settings_time_entry_activities_path, text: TimeEntryActivity.model_name.human(count: :other) },@enumeration.name])diff --git a/modules/costs/config/routes.rb b/modules/costs/config/routes.rbindex ee10d22b7ef..dc129df6c34 100644--- a/modules/costs/config/routes.rb+++ b/modules/costs/config/routes.rb@@ -70,10 +70,12 @@ Rails.application.routes.draw doresources :hourly_rates, only: %i[edit update]namespace :admin do- resources :time_entry_activities, except: [:show] do- member do- put :move- get :reassign+ namespace :settings do+ resources :time_entry_activities, except: [:show] do+ member do+ put :move+ get :reassign+ endendenddiff --git a/modules/costs/lib/costs/engine.rb b/modules/costs/lib/costs/engine.rbindex 137897fbf51..e0268b78608 100644--- a/modules/costs/lib/costs/engine.rb+++ b/modules/costs/lib/costs/engine.rb@@ -140,7 +140,7 @@ module Costsmenu :admin_menu,:time_entry_activities,- { controller: "/admin/time_entry_activities", action: :index },+ { controller: "/admin/settings/time_entry_activities", action: :index },if: ->(*) { User.current.admin? },parent: :admin_costs,caption: :enumeration_activitiesdiff --git a/modules/costs/spec/features/time_entry/activity_spec.rb b/modules/costs/spec/features/time_entry/activity_spec.rbindex 33377a8273d..bc3bcb0d2d9 100644--- a/modules/costs/spec/features/time_entry/activity_spec.rb+++ b/modules/costs/spec/features/time_entry/activity_spec.rb@@ -37,7 +37,7 @@ RSpec.describe "Time entry activity" doendit "allows creating new activities and activating them on projects" do- visit admin_time_entry_activities_path+ visit admin_settings_time_entry_activities_pathpage.find_test_selector("add-enumeration-button").click@@ -45,7 +45,7 @@ RSpec.describe "Time entry activity" doclick_on("Save")# we are redirected back to the index page- expect(page).to have_current_path(admin_time_entry_activities_path)+ expect(page).to have_current_path(admin_settings_time_entry_activities_path)expect(page).to have_content("A new activity")diff --git a/modules/documents/app/controllers/admin/settings/document_categories_controller.rb b/modules/documents/app/controllers/admin/settings/document_categories_controller.rbindex 342febef3ba..9526f256279 100644--- a/modules/documents/app/controllers/admin/settings/document_categories_controller.rb+++ b/modules/documents/app/controllers/admin/settings/document_categories_controller.rb@@ -30,9 +30,7 @@module Adminmodule Settings- class DocumentCategoriesController < ApplicationController- include EnumerationsController-+ class DocumentCategoriesController < EnumerationsControllerBasemenu_item :document_categoriesprivatediff --git a/spec/routing/admin/settings/work_package_priorities_spec.rb b/spec/routing/admin/settings/work_package_priorities_spec.rbindex 8e224969816..1680db5a503 100644--- a/spec/routing/admin/settings/work_package_priorities_spec.rb+++ b/spec/routing/admin/settings/work_package_priorities_spec.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH