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
Validate admin guard for all settings writers (#9012)
Oliver Günther34f8e9dff8ad
diff --git a/app/contracts/settings/update_contract.rb b/app/contracts/settings/update_contract.rbnew file mode 100644index 00000000000..9841156a882--- /dev/null+++ b/app/contracts/settings/update_contract.rb@@ -0,0 +1,35 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++module Settings+ class UpdateContract < ::BaseContract+ include RequiresAdminGuard+ end+enddiff --git a/app/controllers/admin/mail_notifications_controller.rb b/app/controllers/admin/mail_notifications_controller.rbdeleted file mode 100644index d5b2c79f91b..00000000000--- a/app/controllers/admin/mail_notifications_controller.rb+++ /dev/null@@ -1,50 +0,0 @@-#-- encoding: UTF-8--#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.-#++--class Admin::MailNotificationsController < ApplicationController- include AdminSettingsUpdater-- current_menu_item [:show] do- :mail_notifications- end-- def show- @deliveries = ActionMailer::Base.perform_deliveries- @notifiables = Redmine::Notifiable.all- end-- def default_breadcrumb- t(:'activerecord.attributes.user.mail_notification')- end-- def show_local_breadcrumb- true- end-enddiff --git a/app/controllers/admin/settings/api_settings_controller.rb b/app/controllers/admin/settings/api_settings_controller.rbnew file mode 100644index 00000000000..4f0990752be--- /dev/null+++ b/app/controllers/admin/settings/api_settings_controller.rb@@ -0,0 +1,45 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++module Admin::Settings+ class APISettingsController < ::Admin::SettingsController+ menu_item :settings_api++ def default_breadcrumb+ t(:label_api_access_key_type)+ end++ def settings_params+ super.tap do |settings|+ settings["apiv3_cors_origins"] = settings["apiv3_cors_origins"].split(/\r?\n/)+ end+ end+ end+enddiff --git a/app/controllers/admin/incoming_mails_controller.rb b/app/controllers/admin/settings/authentication_settings_controller.rbsimilarity index 83%rename from app/controllers/admin/incoming_mails_controller.rbrename to app/controllers/admin/settings/authentication_settings_controller.rbindex 846d597a8ec..3d16360e4f1 100644--- a/app/controllers/admin/incoming_mails_controller.rb+++ b/app/controllers/admin/settings/authentication_settings_controller.rb@@ -28,18 +28,16 @@# See docs/COPYRIGHT.rdoc for more details.#++-class Admin::IncomingMailsController < ApplicationController- include AdminSettingsUpdater+module Admin::Settings+ class AuthenticationSettingsController < ::Admin::SettingsController+ menu_item :authentication_settings- current_menu_item [:show] do- :incoming_mails- end-- def default_breadcrumb- t(:label_incoming_emails)- end+ def default_breadcrumb+ t(:label_authentication)+ end- def show_local_breadcrumb- true+ def show_local_breadcrumb+ true+ endendenddiff --git a/app/controllers/settings/display_controller.rb b/app/controllers/admin/settings/display_settings_controller.rbsimilarity index 78%rename from app/controllers/settings/display_controller.rbrename to app/controllers/admin/settings/display_settings_controller.rbindex 9b2cdb722d3..f09a91cba76 100644--- a/app/controllers/settings/display_controller.rb+++ b/app/controllers/admin/settings/display_settings_controller.rb@@ -28,19 +28,19 @@# See docs/COPYRIGHT.rdoc for more details.#++-class Settings::DisplayController < SettingsController- include AdminSettingsUpdater+module Admin::Settings+ class DisplaySettingsController < ::Admin::SettingsController+ menu_item :settings_display- menu_item :settings_display+ def show+ @options = {}+ @options[:user_format] = User::USER_FORMATS_STRUCTURE.keys.map { |f| [User.current.name(f), f.to_s] }- def show- @options = {}- @options[:user_format] = User::USER_FORMATS_STRUCTURE.keys.map { |f| [User.current.name(f), f.to_s] }+ respond_to :html+ end- render template: 'settings/_display'- end-- def default_breadcrumb- t(:label_display)+ def default_breadcrumb+ t(:label_display)+ endendenddiff --git a/app/controllers/admin/settings/general_settings_controller.rb b/app/controllers/admin/settings/general_settings_controller.rbnew file mode 100644index 00000000000..4fae4d3ea7f--- /dev/null+++ b/app/controllers/admin/settings/general_settings_controller.rb@@ -0,0 +1,39 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++module Admin::Settings+ class GeneralSettingsController < ::Admin::SettingsController+ menu_item :settings_general++ def default_breadcrumb+ t(:label_general)+ end+ end+end\ No newline at end of filediff --git a/app/controllers/admin/settings/incoming_mails_settings_controller.rb b/app/controllers/admin/settings/incoming_mails_settings_controller.rbnew file mode 100644index 00000000000..735dcecf76b--- /dev/null+++ b/app/controllers/admin/settings/incoming_mails_settings_controller.rb@@ -0,0 +1,45 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++module Admin::Settings+ class IncomingMailsSettingsController < ::Admin::SettingsController+ current_menu_item [:show] do+ :incoming_mails+ end++ def default_breadcrumb+ t(:label_incoming_emails)+ end++ def show_local_breadcrumb+ true+ end+ end+enddiff --git a/app/controllers/settings/api_controller.rb b/app/controllers/admin/settings/mail_notifications_settings_controller.rbsimilarity index 73%rename from app/controllers/settings/api_controller.rbrename to app/controllers/admin/settings/mail_notifications_settings_controller.rbindex 32f83793eb2..a072dc77eea 100644--- a/app/controllers/settings/api_controller.rb+++ b/app/controllers/admin/settings/mail_notifications_settings_controller.rb@@ -28,22 +28,25 @@# See docs/COPYRIGHT.rdoc for more details.#++-class Settings::APIController < SettingsController- include AdminSettingsUpdater+module Admin::Settings+ class MailNotificationsSettingsController < ::Admin::SettingsController+ current_menu_item [:show] do+ :mail_notifications+ end- menu_item :settings_api+ def show+ @deliveries = ActionMailer::Base.perform_deliveries+ @notifiables = Redmine::Notifiable.all- def show- render template: 'settings/_api'- end+ respond_to :html+ end- def default_breadcrumb- t(:label_api_access_key_type)- end+ def default_breadcrumb+ t(:'activerecord.attributes.user.mail_notification')+ end- def settings_params- super.tap do |settings|- settings["apiv3_cors_origins"] = settings["apiv3_cors_origins"].split(/\r?\n/)+ def show_local_breadcrumb+ trueendendenddiff --git a/app/controllers/settings/general_controller.rb b/app/controllers/admin/settings/projects_settings_controller.rbsimilarity index 84%rename from app/controllers/settings/general_controller.rbrename to app/controllers/admin/settings/projects_settings_controller.rbindex 250b0341cb6..565e4578312 100644--- a/app/controllers/settings/general_controller.rb+++ b/app/controllers/admin/settings/projects_settings_controller.rb@@ -28,16 +28,12 @@# See docs/COPYRIGHT.rdoc for more details.#++-class Settings::GeneralController < SettingsController- include AdminSettingsUpdater+module Admin::Settings+ class ProjectsSettingsController < ::Admin::SettingsController+ menu_item :settings_projects- menu_item :settings_general-- def show- render template: 'settings/_general'- end-- def default_breadcrumb- t(:label_general)+ def default_breadcrumb+ t(:label_project_plural)+ endendenddiff --git a/app/controllers/settings/projects_controller.rb b/app/controllers/admin/settings/repositories_settings_controller.rbsimilarity index 84%rename from app/controllers/settings/projects_controller.rbrename to app/controllers/admin/settings/repositories_settings_controller.rbindex 80d9723bba5..7bb2d1e4ced 100644--- a/app/controllers/settings/projects_controller.rb+++ b/app/controllers/admin/settings/repositories_settings_controller.rb@@ -28,16 +28,13 @@# See docs/COPYRIGHT.rdoc for more details.#++-class Settings::ProjectsController < SettingsController- include AdminSettingsUpdater+module Admin::Settings+ class RepositoriesSettingsController < ::Admin::SettingsController+ menu_item :settings_repositories- menu_item :settings_projects-- def show- render template: 'settings/_projects'- end-- def default_breadcrumb- t(:label_project_plural)+ def default_breadcrumb+ t(:label_repository_plural)+ endendend+diff --git a/app/controllers/settings/repositories_controller.rb b/app/controllers/admin/settings/users_settings_controller.rbsimilarity index 83%rename from app/controllers/settings/repositories_controller.rbrename to app/controllers/admin/settings/users_settings_controller.rbindex f1b50fb468e..3abc459be82 100644--- a/app/controllers/settings/repositories_controller.rb+++ b/app/controllers/admin/settings/users_settings_controller.rb@@ -28,16 +28,16 @@# See docs/COPYRIGHT.rdoc for more details.#++-class Settings::RepositoriesController < SettingsController- include AdminSettingsUpdater+module Admin::Settings+ class UsersSettingsController < ::Admin::SettingsController+ menu_item :user_settings- menu_item :settings_repositories+ def default_breadcrumb+ t(:label_user_settings)+ end- def show- render template: 'settings/_repositories'- end-- def default_breadcrumb- t(:label_repository_plural)+ def show_local_breadcrumb+ true+ endendenddiff --git a/app/controllers/admin/settings/work_packages_settings_controller.rb b/app/controllers/admin/settings/work_packages_settings_controller.rbnew file mode 100644index 00000000000..7aaed649bf9--- /dev/null+++ b/app/controllers/admin/settings/work_packages_settings_controller.rb@@ -0,0 +1,45 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++module Admin::Settings+ class WorkPackagesSettingsController < ::Admin::SettingsController+ current_menu_item :show do+ :work_packages_setting+ end++ def default_breadcrumb+ t(:label_work_package_tracking)+ end++ def show_local_breadcrumb+ true+ end+ end+enddiff --git a/app/controllers/concerns/admin_settings_updater.rb b/app/controllers/admin/settings_controller.rbsimilarity index 52%rename from app/controllers/concerns/admin_settings_updater.rbrename to app/controllers/admin/settings_controller.rbindex a9215a64f89..9c47ad35546 100644--- a/app/controllers/concerns/admin_settings_updater.rb+++ b/app/controllers/admin/settings_controller.rb@@ -28,29 +28,74 @@# See docs/COPYRIGHT.rdoc for more details.#++-module AdminSettingsUpdater- extend ActiveSupport::Concern-- included do+module Admin+ class SettingsController < ApplicationControllerlayout 'admin'-before_action :require_admin+ before_action :find_plugin, only: %i[show_plugin update_plugin]++ helper_method :gon++ current_menu_item [:show] do+ :settings+ end++ current_menu_item :show_plugin do |controller|+ plugin = Redmine::Plugin.find(controller.params[:id])+ plugin.settings[:menu_item] || :settings+ rescue Redmine::PluginNotFound+ :settings+ end++ def show+ respond_to :html+ enddef updateif params[:settings]- Settings::UpdateService+ call = ::Settings::UpdateService.new(user: current_user)- .call(settings: settings_params)+ .call(settings_params)- flash[:notice] = t(:notice_successful_update)+ call.on_success { flash[:notice] = t(:notice_successful_update) }+ call.on_failure { flash[:error] = call.message || I18n.t(:notice_internal_server_error) }redirect_to action: 'show', tab: params[:tab]endend+ def show_plugin+ @partial = @plugin.settings[:partial]+ @settings = Setting["plugin_#{@plugin.id}"]+ end++ def update_plugin+ Setting["plugin_#{@plugin.id}"] = params[:settings].permit!.to_h+ flash[:notice] = I18n.t(:notice_successful_update)+ redirect_to action: :show_plugin, id: @plugin.id+ end++ def show_local_breadcrumb+ true+ end++ def default_breadcrumb+ if @plugin+ @plugin.name+ else+ I18n.t(:label_setting_plural)+ end+ end+protected+ def find_plugin+ @plugin = Redmine::Plugin.find(params[:id])+ rescue Redmine::PluginNotFound+ render_404+ end+def settings_paramspermitted_params.settings.to_hendend-end+end\ No newline at end of filediff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rbindex 25bf9c8e52d..49254cbaddc 100644--- a/app/controllers/admin_controller.rb+++ b/app/controllers/admin_controller.rb@@ -68,7 +68,7 @@ class AdminController < ApplicationControllerflash[:error] = I18n.t(:notice_email_error, value: Redmine::CodesetUtil.replace_invalid_utf8(e.message.dup))endActionMailer::Base.raise_delivery_errors = raise_delivery_errors- redirect_to admin_mail_notifications_path+ redirect_to admin_settings_mail_notifications_pathenddef force_user_languagediff --git a/app/controllers/authentication_controller.rb b/app/controllers/authentication_controller.rbdeleted file mode 100644index 827313b587e..00000000000--- a/app/controllers/authentication_controller.rb+++ /dev/null@@ -1,64 +0,0 @@-#-- encoding: UTF-8--#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.-#++--class AuthenticationController < ApplicationController- before_action :require_admin- layout 'admin'- menu_item :authentication_settings-- def index- respond_to do |format|- format.html- end- end-- def edit- if params[:settings]- Settings::UpdateService- .new(user: current_user)- .call(settings: permitted_params.settings.to_h)-- flash[:notice] = I18n.t(:notice_successful_update)- redirect_to action: 'authentication_settings'- end- end-- def authentication_settings- render 'authentication_settings'- end-- def default_breadcrumb- t(:label_authentication)- end-- def show_local_breadcrumb- true- end-enddiff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rbdeleted file mode 100644index 23a2955839b..00000000000--- a/app/controllers/settings_controller.rb+++ /dev/null@@ -1,68 +0,0 @@-#-- encoding: UTF-8--#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.-#++--class SettingsController < ApplicationController- include AdminSettingsUpdater-- helper_method :gon-- current_menu_item [:show] do- :settings- end-- current_menu_item :plugin do |controller|- plugin = Redmine::Plugin.find(controller.params[:id])- plugin.settings[:menu_item] || :settings- rescue Redmine::PluginNotFound- :settings- end-- def show- redirect_to general_settings_path- end-- def plugin- @plugin = Redmine::Plugin.find(params[:id])- if request.post?- Setting["plugin_#{@plugin.id}"] = params[:settings].permit!.to_h- flash[:notice] = I18n.t(:notice_successful_update)- redirect_to action: 'plugin', id: @plugin.id- else- @partial = @plugin.settings[:partial]- @settings = Setting["plugin_#{@plugin.id}"]- end- rescue Redmine::PluginNotFound- render_404- end-- def show_local_breadcrumb- true- end-enddiff --git a/app/controllers/users_settings_controller.rb b/app/controllers/users_settings_controller.rbdeleted file mode 100644index e2033d43187..00000000000--- a/app/controllers/users_settings_controller.rb+++ /dev/null@@ -1,58 +0,0 @@-#-- encoding: UTF-8--#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.-#++--class UsersSettingsController < ::ApplicationController- layout 'admin'- before_action :require_admin- menu_item :user_settings-- def index- render 'users/users_settings'- end-- def edit- if params[:settings]- Settings::UpdateService- .new(user: current_user)- .call(settings: permitted_params.settings.to_h)-- flash[:notice] = I18n.t(:notice_successful_update)- redirect_to action: 'index'- end- end-- def default_breadcrumb- t(:label_user_settings)- end-- def show_local_breadcrumb- true- end-enddiff --git a/app/controllers/work_packages/settings_controller.rb b/app/controllers/work_packages/settings_controller.rbdeleted file mode 100644index 96af585f671..00000000000--- a/app/controllers/work_packages/settings_controller.rb+++ /dev/null@@ -1,60 +0,0 @@-#-- encoding: UTF-8--#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.-#++--class WorkPackages::SettingsController < ::ApplicationController- layout 'admin'- before_action :require_admin- current_menu_item :index do- :work_packages_setting- end-- def index- render 'work_packages/settings/work_package_tracking'- end-- def edit- if params[:settings]- Settings::UpdateService- .new(user: current_user)- .call(settings: permitted_params.settings.to_h)-- flash[:notice] = I18n.t(:notice_successful_update)- redirect_to action: 'index'- end- end-- def default_breadcrumb- t(:label_work_package_tracking)- end-- def show_local_breadcrumb- true- end-enddiff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rbindex 5504148d3d4..0da641f811e 100644--- a/app/helpers/settings_helper.rb+++ b/app/helpers/settings_helper.rb@@ -38,27 +38,27 @@ module SettingsHelper[{name: 'general',- action: { controller: '/settings/general', action: 'show' },+ controller: '/admin/settings/general_settings',label: :label_general},{name: 'display',- action: { controller: '/settings/display', action: 'show' },+ controller: '/admin/settings/display_settings',label: :label_display},{name: 'projects',- action: { controller: '/settings/projects', action: 'show' },+ controller: '/admin/settings/projects_settings',label: :label_project_plural},{name: 'api',- action: { controller: '/settings/api', action: 'show' },+ controller: '/admin/settings/api_settings',label: :label_api_access_key_type},{name: 'repositories',- action: { controller: '/settings/repositories', action: 'show' },+ controller:'/admin/settings/repositories_settings',label: :label_repository_plural}]diff --git a/app/services/concerns/contracted.rb b/app/services/concerns/contracted.rbindex 9c03c1692e6..ca5029e49cc 100644--- a/app/services/concerns/contracted.rb+++ b/app/services/concerns/contracted.rb@@ -36,8 +36,8 @@ module Contractedattr_accessor :contract_optionsdef contract_class=(cls)- unless cls <= ::ModelContract- raise ArgumentError "#{cls.name} is not an instance of ModelContract."+ unless cls <= ::BaseContract+ raise ArgumentError "#{cls.name} is not an instance of BaseContract."end@contract_class = cls@@ -83,10 +83,9 @@ module Contractedif !contract.validate[false, contract.errors]- elsif !yield- [false, object.errors]else- [true, object.errors]+ success = !!yield+ [success, object&.errors]endenddiff --git a/app/services/settings/update_service.rb b/app/services/settings/update_service.rbindex a2a91fed24b..56449c20cd4 100644--- a/app/services/settings/update_service.rb+++ b/app/services/settings/update_service.rb@@ -28,24 +28,31 @@# See docs/COPYRIGHT.rdoc for more details.#++-class Settings::UpdateService < ::BaseServices::Update- attr_accessor :user+class Settings::UpdateService < ::BaseServices::BaseContracted+ def initialize(user:)+ super user: user,+ contract_class: Settings::UpdateContract+ end++ def after_validate(params, call)+ params.each do |name, value|+ Setting[name] = derive_value(value)+ end- def initialize(user)- self.user = user+ callend- def call(settings:)- settings.each do |name, value|- if value.is_a?(Array)- # remove blank values in array settings- value.delete_if(&:blank?)- elsif value.is_a?(Hash)- value.delete_if { |_, v| v.blank? }- else- value = value.strip- end- Setting[name] = value+ private++ def derive_value(value)+ case value+ when Array+ # remove blank values in array settings+ value.delete_if(&:blank?)+ when Hash+ value.delete_if { |_, v| v.blank? }+ else+ value.stripendendenddiff --git a/app/views/settings/_api.html.erb b/app/views/admin/settings/api_settings/show.html.erbsimilarity index 96%rename from app/views/settings/_api.html.erbrename to app/views/admin/settings/api_settings/show.html.erbindex d29c7e06dd6..49bcd49d59a 100644--- a/app/views/settings/_api.html.erb+++ b/app/views/admin/settings/api_settings/show.html.erb@@ -28,7 +28,7 @@ See docs/COPYRIGHT.rdoc for more details.++#%><%= toolbar title: t(:label_api_access_key_type) %>-<%= styled_form_tag(update_api_settings_path, method: :patch) do %>+<%= styled_form_tag(admin_settings_update_api_path, method: :patch) do %><section class="form--section"><fieldset class="form--fieldset"><legend class="form--fieldset-legend">Cross-Origin Resource Sharing (CORS)</legend>diff --git a/app/views/authentication/authentication_settings.html.erb b/app/views/admin/settings/authentication_settings/show.html.erbsimilarity index 98%rename from app/views/authentication/authentication_settings.html.erbrename to app/views/admin/settings/authentication_settings/show.html.erbindex 3eb6d659907..e7071d6a14e 100644--- a/app/views/authentication/authentication_settings.html.erb+++ b/app/views/admin/settings/authentication_settings/show.html.erb@@ -30,7 +30,7 @@ See docs/COPYRIGHT.rdoc for more details.<%= toolbar title: t(:label_authentication) %>-<%= styled_form_tag({ action: :edit }) do %>+<%= styled_form_tag(admin_settings_authentication_path, method: :patch) do %><section class="form--section"><fieldset class="form--fieldset"><legend class="form--fieldset-legend"><%= I18n.t(:general, scope: [:settings]) %></legend>diff --git a/app/views/settings/_display.html.erb b/app/views/admin/settings/display_settings/show.html.erbsimilarity index 97%rename from app/views/settings/_display.html.erbrename to app/views/admin/settings/display_settings/show.html.erbindex 819df704846..423d91e8d39 100644--- a/app/views/settings/_display.html.erb+++ b/app/views/admin/settings/display_settings/show.html.erb@@ -33,7 +33,7 @@ See docs/COPYRIGHT.rdoc for more details.<%= toolbar title: t(:label_display) %>-<%= styled_form_tag(update_display_settings_path, method: :patch) do %>+<%= styled_form_tag(admin_settings_update_display_path, method: :patch) do %><section class="form--section"><div class="form--field" id="setting_available_languages"><%= setting_multiselect :available_languages, all_lang_options_for_select(false) %></div>diff --git a/app/views/settings/_general.html.erb b/app/views/admin/settings/general_settings/show.html.erbsimilarity index 98%rename from app/views/settings/_general.html.erbrename to app/views/admin/settings/general_settings/show.html.erbindex 3e8dba66648..2f14fed50cb 100644--- a/app/views/settings/_general.html.erb+++ b/app/views/admin/settings/general_settings/show.html.erb@@ -28,7 +28,7 @@ See docs/COPYRIGHT.rdoc for more details.++#%><%= toolbar title: t(:label_general) %>-<%= styled_form_tag(update_general_settings_path, method: :patch) do %>+<%= styled_form_tag(admin_settings_update_general_path, method: :patch) do %><section class="form--section"><div class="form--field"><%= setting_text_field :app_title, size: 30, container_class: '-middle' %></div><div class="form--field">diff --git a/app/views/admin/incoming_mails/show.html.erb b/app/views/admin/settings/incoming_mails_settings/show.html.erbsimilarity index 96%rename from app/views/admin/incoming_mails/show.html.erbrename to app/views/admin/settings/incoming_mails_settings/show.html.erbindex d96c77814ad..a3c75fc0b9f 100644--- a/app/views/admin/incoming_mails/show.html.erb+++ b/app/views/admin/settings/incoming_mails_settings/show.html.erb@@ -31,7 +31,7 @@ See docs/COPYRIGHT.rdoc for more details.<%= toolbar title: t(:label_incoming_emails) %>-<%= styled_form_tag(admin_incoming_mails_path, method: :patch) do %>+<%= styled_form_tag(admin_settings_incoming_mails_path, method: :patch) do %><section class="form--section"><div class="form--field"><%= setting_text_area :mail_handler_body_delimiters, rows: 5, container_class: '-wide' %>diff --git a/app/views/admin/mail_notifications/show.html.erb b/app/views/admin/settings/mail_notifications_settings/show.html.erbsimilarity index 98%rename from app/views/admin/mail_notifications/show.html.erbrename to app/views/admin/settings/mail_notifications_settings/show.html.erbindex 9171711637d..2501f072ef0 100644--- a/app/views/admin/mail_notifications/show.html.erb+++ b/app/views/admin/settings/mail_notifications_settings/show.html.erb@@ -31,7 +31,7 @@ See docs/COPYRIGHT.rdoc for more details.<%= toolbar title: t(:'activerecord.attributes.user.mail_notification') %>-<%= styled_form_tag(admin_mail_notifications_path, method: :patch) do %>+<%= styled_form_tag(admin_settings_mail_notifications_path, method: :patch) do %><% if @deliveries %><section class="form--section"><div class="form--field"><%= setting_text_field :mail_from, size: 60, container_class: '-middle' %></div>diff --git a/app/views/settings/_projects.html.erb b/app/views/admin/settings/projects_settings/show.html.erbsimilarity index 97%rename from app/views/settings/_projects.html.erbrename to app/views/admin/settings/projects_settings/show.html.erbindex 5b851ae3e6b..0ce08f389e6 100644--- a/app/views/settings/_projects.html.erb+++ b/app/views/admin/settings/projects_settings/show.html.erb@@ -28,7 +28,7 @@ See docs/COPYRIGHT.rdoc for more details.++#%><%= toolbar title: t(:label_project_plural) %>-<%= styled_form_tag(update_projects_settings_path, method: :patch) do %>+<%= styled_form_tag(admin_settings_update_projects_path, method: :patch) do %><section class="form--section"><fieldset class="form--fieldset"><legend class="form--fieldset-legend"><%= t('settings.projects.section_new_projects') %></legend>diff --git a/app/views/settings/_repositories_checkout.html.erb b/app/views/admin/settings/repositories_settings/_repositories_checkout.html.erbsimilarity index 100%rename from app/views/settings/_repositories_checkout.html.erbrename to app/views/admin/settings/repositories_settings/_repositories_checkout.html.erbdiff --git a/app/views/settings/_repositories.html.erb b/app/views/admin/settings/repositories_settings/show.html.erbsimilarity index 98%rename from app/views/settings/_repositories.html.erbrename to app/views/admin/settings/repositories_settings/show.html.erbindex 9d9e1c82532..c80873304c5 100644--- a/app/views/settings/_repositories.html.erb+++ b/app/views/admin/settings/repositories_settings/show.html.erb@@ -28,7 +28,7 @@ See docs/COPYRIGHT.rdoc for more details.++#%><%= toolbar title: t(:label_repository_plural) %>-<%= styled_form_tag(update_repositories_settings_path, method: :patch) do %>+<%= styled_form_tag(admin_settings_update_repositories_path, method: :patch) do %><section class="form--section"><div class="form--field"><%= setting_check_box :autofetch_changesets %>diff --git a/app/views/settings/plugin.html.erb b/app/views/admin/settings/show_plugin.html.erbsimilarity index 94%rename from app/views/settings/plugin.html.erbrename to app/views/admin/settings/show_plugin.html.erbindex 4db81d21cca..2368464a86d 100644--- a/app/views/settings/plugin.html.erb+++ b/app/views/admin/settings/show_plugin.html.erb@@ -28,7 +28,7 @@ See docs/COPYRIGHT.rdoc for more details.++#%><%= toolbar title: @plugin.name %><div id="settings">- <%= styled_form_tag({action: 'plugin'}) do %>+ <%= styled_form_tag({controller: '/admin/settings', action: 'update_plugin' }) do %><%= render partial: @partial, locals: {settings: @settings}%><%= styled_submit_tag t(:button_apply), class: '-highlight' %><% end %>diff --git a/app/views/users/users_settings.html.erb b/app/views/admin/settings/users_settings/show.html.erbsimilarity index 97%rename from app/views/users/users_settings.html.erbrename to app/views/admin/settings/users_settings/show.html.erbindex 4a92a720116..395bfe7e60b 100644--- a/app/views/users/users_settings.html.erb+++ b/app/views/admin/settings/users_settings/show.html.erb@@ -30,7 +30,7 @@ See docs/COPYRIGHT.rdoc for more details.<%= toolbar title: t(:label_user_settings) %>-<%= styled_form_tag({ action: 'edit' }, class: 'admin-settings--form') do %>+<%= styled_form_tag(admin_settings_users_path, method: :patch, class: 'admin-settings--form') do %><fieldset class="form--fieldset"><legend class="form--fieldset-legend"><%= t(:'settings.user.default_preferences')%></legend>diff --git a/app/views/work_packages/settings/_enterprise_feature_hint.html.erb b/app/views/admin/settings/work_packages_settings/_enterprise_feature_hint.html.erbsimilarity index 100%rename from app/views/work_packages/settings/_enterprise_feature_hint.html.erbrename to app/views/admin/settings/work_packages_settings/_enterprise_feature_hint.html.erbdiff --git a/app/views/work_packages/settings/work_package_tracking.html.erb b/app/views/admin/settings/work_packages_settings/show.html.erbsimilarity index 97%rename from app/views/work_packages/settings/work_package_tracking.html.erbrename to app/views/admin/settings/work_packages_settings/show.html.erbindex eb1efa41648..bb7cc1e07bb 100644--- a/app/views/work_packages/settings/work_package_tracking.html.erb+++ b/app/views/admin/settings/work_packages_settings/show.html.erb@@ -31,7 +31,7 @@ See docs/COPYRIGHT.rdoc for more details.<%= toolbar title: t(:label_work_package_tracking) %>-<%= styled_form_tag({action: 'edit'}) do %>+<%= styled_form_tag({action: :update}) do %><section class="form--section"><div class="form--field"><%= setting_check_box :cross_project_work_package_relations %></div><div class="form--field"><%= setting_check_box :display_subprojects_work_packages %></div>@@ -48,7 +48,7 @@ See docs/COPYRIGHT.rdoc for more details.options[:disabled] = 'disabled' unless EnterpriseToken.allows_to?(:conditional_highlighting)}%>- <%= render partial: 'work_packages/settings/enterprise_feature_hint',+ <%= render partial: 'enterprise_feature_hint',locals: {ee_feature: :conditional_highlighting,explanation: t('js.work_packages.table_configuration.upsale.attribute_highlighting'),diff --git a/app/views/authentication/index.html.erb b/app/views/authentication/index.html.erbdeleted file mode 100644index 0d1d1f42420..00000000000--- a/app/views/authentication/index.html.erb+++ /dev/null@@ -1,30 +0,0 @@-<%#-- copyright-OpenProject is an open source project management software.-Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.--++#%>--authorizeddiff --git a/app/views/homescreen/blocks/_administration.html.erb b/app/views/homescreen/blocks/_administration.html.erbindex cbddd34cab5..85f7f824028 100644--- a/app/views/homescreen/blocks/_administration.html.erb+++ b/app/views/homescreen/blocks/_administration.html.erb@@ -37,7 +37,7 @@</li><li>- <%= link_to t(:label_system_settings), general_settings_path,+ <%= link_to t(:label_system_settings), admin_settings_general_path,title: t(:label_system_settings) %></li><li>diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erbindex d1429b1f32e..43e44181915 100644--- a/app/views/projects/index.html.erb+++ b/app/views/projects/index.html.erb@@ -71,7 +71,7 @@ See docs/COPYRIGHT.rdoc for more details.</a><ul style="display:none;" class="menu-drop-down-container"><li>- <%= link_to t('button_configure'), projects_settings_path, target: '_blank', class: 'icon-context icon-settings' %>+ <%= link_to t('button_configure'), admin_settings_projects_path, target: '_blank', class: 'icon-context icon-settings' %></li></ul></li>diff --git a/app/views/warning_bar/_host_and_protocol_mismatch.html.erb b/app/views/warning_bar/_host_and_protocol_mismatch.html.erbindex 3aca9cfa9e5..6566ba8e41d 100644--- a/app/views/warning_bar/_host_and_protocol_mismatch.html.erb+++ b/app/views/warning_bar/_host_and_protocol_mismatch.html.erb@@ -8,7 +8,7 @@<%= t 'warning_bar.protocol_mismatch.text_html',set_protocol: Setting.protocol,actual_protocol: request.ssl? ? 'https' : 'http',- setting_path: general_settings_path+ setting_path: admin_settings_general_path%></p><% end %>@@ -20,7 +20,7 @@<%= t 'warning_bar.hostname_mismatch.text_html',set_hostname: Setting.host_name,actual_hostname: request.host,- setting_path: general_settings_path+ setting_path: admin_settings_general_path%></p><% end %>diff --git a/config/initializers/menus.rb b/config/initializers/menus.rbindex 90df898f3d0..8e0f524312a 100644--- a/config/initializers/menus.rb+++ b/config/initializers/menus.rb@@ -149,7 +149,7 @@ Redmine::MenuManager.map :admin_menu do |menu|icon: 'icon2 icon-group'menu.push :user_settings,- { controller: '/users_settings' },+ { controller: '/admin/settings/users_settings', action: :show },if: Proc.new { User.current.admin? },caption: :label_setting_plural,parent: :users_and_permissions@@ -179,19 +179,19 @@ Redmine::MenuManager.map :admin_menu do |menu|parent: :users_and_permissionsmenu.push :user_avatars,- { controller: '/settings', action: 'plugin', id: :openproject_avatars },+ { controller: '/admin/settings', action: 'show_plugin', id: :openproject_avatars },if: Proc.new { User.current.admin? },caption: :label_avatar_plural,parent: :users_and_permissionsmenu.push :admin_work_packages,- { controller: '/work_packages/settings' },+ { controller: '/admin/settings/work_packages_settings', action: :show },if: Proc.new { User.current.admin? },caption: :label_work_package_plural,icon: 'icon2 icon-view-timeline'menu.push :work_packages_setting,- { controller: '/work_packages/settings' },+ { controller: '/admin/settings/work_packages_settings', action: :show },if: Proc.new { User.current.admin? },caption: :label_setting_plural,parent: :admin_work_packages@@ -242,45 +242,45 @@ Redmine::MenuManager.map :admin_menu do |menu|icon: 'icon2 icon-enumerations'menu.push :settings,- { controller: '/settings/general', action: 'show' },+ { controller: '/admin/settings/general_settings', action: :show },if: Proc.new { User.current.admin? },caption: :label_system_settings,icon: 'icon2 icon-settings2'SettingsHelper.system_settings_tabs.each do |node|menu.push :"settings_#{node[:name]}",- node[:action],+ { controller: node[:controller], action: :show },caption: node[:label],if: Proc.new { User.current.admin? },parent: :settingsendmenu.push :email,- { controller: '/admin/mail_notifications', action: 'show' },+ { controller: '/admin/settings/mail_notifications_settings', action: :show },if: Proc.new { User.current.admin? },caption: :'attributes.mail',icon: 'icon2 icon-mail1'menu.push :mail_notifications,- { controller: '/admin/mail_notifications', action: 'show' },+ { controller: '/admin/settings/mail_notifications_settings', action: :show },if: Proc.new { User.current.admin? },caption: :'activerecord.attributes.user.mail_notification',parent: :emailmenu.push :incoming_mails,- { controller: '/admin/incoming_mails', action: 'show' },+ { controller: '/admin/settings/incoming_mails_settings', action: :show },if: Proc.new { User.current.admin? },caption: :label_incoming_emails,parent: :emailmenu.push :authentication,- { controller: '/authentication', action: 'authentication_settings' },+ { controller: '/admin/settings/authentication_settings', action: :show },if: Proc.new { User.current.admin? },caption: :label_authentication,icon: 'icon2 icon-two-factor-authentication'menu.push :authentication_settings,- { controller: '/authentication', action: 'authentication_settings' },+ { controller: '/admin/settings/authentication_settings', action: :show },if: Proc.new { User.current.admin? },caption: :label_setting_plural,parent: :authentication@@ -320,7 +320,7 @@ Redmine::MenuManager.map :admin_menu do |menu|icon: 'icon2 icon-info1'menu.push :custom_style,- { controller: '/custom_styles', action: 'show' },+ { controller: '/custom_styles', action: :show },if: Proc.new { User.current.admin? },caption: :label_custom_style,icon: 'icon2 icon-design'@@ -332,19 +332,19 @@ Redmine::MenuManager.map :admin_menu do |menu|icon: 'icon2 icon-status'menu.push :enterprise,- { controller: '/enterprises', action: 'show' },+ { controller: '/enterprises', action: :show },caption: :label_enterprise_edition,icon: 'icon2 icon-headset',if: proc { User.current.admin? && OpenProject::Configuration.ee_manager_visible? }menu.push :admin_costs,- { controller: '/settings', action: 'plugin', id: :costs },+ { controller: '/admin/settings', action: 'show_plugin', id: :costs },if: Proc.new { User.current.admin? },caption: :project_module_costs,icon: 'icon2 icon-budget'menu.push :costs_setting,- { controller: '/settings', action: 'plugin', id: :costs },+ { controller: '/admin/settings', action: 'show_plugin', id: :costs },if: Proc.new { User.current.admin? },caption: :label_setting_plural,parent: :admin_costs@@ -412,7 +412,7 @@ Redmine::MenuManager.map :project_menu do |menu|icon: 'icon2 icon-ticket-note'menu.push :repository,- { controller: '/repositories', action: 'show' },+ { controller: '/repositories', action: :show },param: :project_id,if: Proc.new { |p| p.repository && !p.repository.new_record? },icon: 'icon2 icon-folder-open'@@ -427,7 +427,7 @@ Redmine::MenuManager.map :project_menu do |menu|icon: 'icon2 icon-group'menu.push :settings,- { controller: '/project_settings/generic', action: 'show' },+ { controller: '/project_settings/generic', action: :show },caption: :label_project_settings,last: true,icon: 'icon2 icon-settings2',diff --git a/config/routes.rb b/config/routes.rbindex 0d3e7caea5b..848eadc4854 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -388,19 +388,24 @@ OpenProject::Application.routes.draw doendnamespace :admin do- resource :incoming_mails, only: %i[show update]- resource :mail_notifications, only: %i[show update]- end+ namespace :settings do+ SettingsHelper.system_settings_tabs.each do |tab|+ get tab[:name], controller: tab[:controller], action: :show, as: tab[:name].to_s+ patch tab[:name], controller: tab[:controller], action: :update, as: "update_#{tab[:name]}"+ end- resource :settings, only: %i(update show) do- SettingsHelper.system_settings_tabs.each do |tab|- get tab[:name], controller: "settings/#{tab[:name]}", action: 'show', as: (tab[:name]).to_s- patch tab[:name], controller: "settings/#{tab[:name]}", action: 'update', as: "update_#{tab[:name]}"- end+ resource :authentication, controller: '/admin/settings/authentication_settings', only: %i[show update]+ resource :incoming_mails, controller: '/admin/settings/incoming_mails_settings', only: %i[show update]+ resource :mail_notifications, controller: '/admin/settings/mail_notifications_settings', only: %i[show update]+ resource :work_packages, controller: '/admin/settings/work_packages_settings', only: %i[show update]+ resource :users, controller: '/admin/settings/users_settings', only: %i[show update]- # We should fix this crappy routing (split up and rename controller methods)- collection do- match 'plugin/:id', action: 'plugin', via: %i[get post]+ # Redirect /settings to general settings+ get '/', to: redirect('/admin/settings/general')++ # Plugin settings+ get 'plugin/:id', action: :show_plugin+ post 'plugin/:id', action: :update_pluginendend@@ -420,11 +425,6 @@ OpenProject::Application.routes.draw doget '/bulk' => 'bulk#destroy'end- scope controller: 'work_packages/settings' do- get 'work_package_tracking' => 'work_packages/settings#index'- post 'work_package_tracking' => 'work_packages/settings#edit'- end-resources :work_packages, only: [:index] do# move bulk of wpsget 'move/new' => 'work_packages/moves#new', on: :collection, as: 'new_move'@@ -476,11 +476,6 @@ OpenProject::Application.routes.draw do# The show page of groups is public and thus moved out of the admin scoperesources :groups, only: %i[show], as: :show_group- scope controller: 'users_settings' do- get 'users_settings' => 'users_settings#index'- post 'users_settings' => 'users_settings#edit'- end-resources :forums, only: [] doresources :topics, controller: 'messages', except: [:index], shallow: true domember do@@ -555,12 +550,6 @@ OpenProject::Application.routes.draw dopatch 'user_settings', action: 'user_settings'end- scope controller: 'authentication' do- get 'authentication' => 'authentication#index'- get 'authentication_settings' => 'authentication#authentication_settings'- post 'authentication_settings' => 'authentication#edit'- end-resources :colors domember doget :confirm_destroydiff --git a/modules/avatars/lib/open_project/avatars/engine.rb b/modules/avatars/lib/open_project/avatars/engine.rbindex c1bbae08565..da7f956f05b 100644--- a/modules/avatars/lib/open_project/avatars/engine.rb+++ b/modules/avatars/lib/open_project/avatars/engine.rb@@ -32,6 +32,7 @@ module OpenProject::Avatarspartial: 'settings/openproject_avatars',menu_item: :user_avatars},+ name: :label_avatar_plural,bundled: true doadd_menu_item :my_menu, :avatar,{ controller: '/avatars/my_avatar', action: 'show' },diff --git a/spec/contracts/settings/update_contract_spec.rb b/spec/contracts/settings/update_contract_spec.rbnew file mode 100644index 00000000000..9d2cf6497c6--- /dev/null+++ b/spec/contracts/settings/update_contract_spec.rb@@ -0,0 +1,42 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++require 'spec_helper'+require 'contracts/shared/model_contract_shared_context'++describe Settings::UpdateContract do+ include_context 'ModelContract shared context'++ let(:contract) do+ described_class.new(nil, current_user)+ end++ it_behaves_like 'contract is valid for active admins and invalid for regular users'+enddiff --git a/spec/controllers/authentication_spec.rb b/spec/controllers/admin/settings/authentication_controller_spec.rbsimilarity index 87%rename from spec/controllers/authentication_spec.rbrename to spec/controllers/admin/settings/authentication_controller_spec.rbindex f4d43f4bac2..b6abd301cb9 100644--- a/spec/controllers/authentication_spec.rb+++ b/spec/controllers/admin/settings/authentication_controller_spec.rb@@ -28,12 +28,12 @@require 'spec_helper'-describe AuthenticationController, type: :controller do- describe 'index.html' do+describe Admin::Settings::AuthenticationSettingsController, type: :controller do+ describe 'show.html' dodef fetch- get 'index'+ get 'show'end- it_should_behave_like 'a controller action with require_admin'+ it_behaves_like 'a controller action with require_admin'endenddiff --git a/spec/controllers/settings_controller_spec.rb b/spec/controllers/admin/settings/projects_settings_controller_spec.rbsimilarity index 95%rename from spec/controllers/settings_controller_spec.rbrename to spec/controllers/admin/settings/projects_settings_controller_spec.rbindex bb0ac8d93f3..471443f587e 100644--- a/spec/controllers/settings_controller_spec.rb+++ b/spec/controllers/admin/settings/projects_settings_controller_spec.rb@@ -28,7 +28,8 @@require 'spec_helper'-describe Settings::ProjectsController, type: :controller do+describe Admin::Settings::ProjectsSettingsController, type: :controller do+before :each doallow(@controller).to receive(:set_localization)@params = {}@@ -53,7 +54,7 @@ describe Settings::ProjectsController, type: :controller doget 'show', params: { tab: 'projects' }expect(response).to be_successful- expect(response).to render_template 'settings/_projects'+ expect(response).to render_template 'admin/settings/projects_settings/show'expect(response.body).to have_selector "input[@name='settings[default_projects_modules][]'][@value='activity']"end@@ -61,7 +62,7 @@ describe Settings::ProjectsController, type: :controller doget 'show', params: { tab: 'projects' }expect(response).to be_successful- expect(response).to render_template 'settings/_projects'+ expect(response).to render_template 'admin/settings/projects_settings/show'expect(response.body).to have_selector "input[@name='settings[default_projects_modules][]'][@value='activity']"end@@ -74,7 +75,7 @@ describe Settings::ProjectsController, type: :controller doget 'show', params: { tab: 'projects' }expect(response).to be_successful- expect(response).to render_template 'settings/_projects'+ expect(response).to render_template 'admin/settings/projects_settings/show'expect(response.body).not_to have_selector "input[@name='settings[default_projects_modules][]'][@value='activity'][@checked='checked']"end@@ -89,7 +90,7 @@ describe Settings::ProjectsController, type: :controller doget 'show', params: { tab: 'projects' }expect(response).to be_successful- expect(response).to render_template 'settings/_projects'+ expect(response).to render_template 'admin/settings/projects_settings/show'expect(response.body).to have_selector "input[@name='settings[default_projects_modules][]'][@value='activity'][@checked='checked']"enddiff --git a/spec/controllers/admin_controller_spec.rb b/spec/controllers/admin_controller_spec.rbindex c859ba21b89..0cb03957cef 100644--- a/spec/controllers/admin_controller_spec.rb+++ b/spec/controllers/admin_controller_spec.rb@@ -56,7 +56,7 @@ describe AdminController, type: :controller doRedmine::Plugin.register name.to_sym domenu :admin_menu,:"#{name}_settings",- { controller: '/settings', action: :plugin, id: :"openproject_#{name}" },+ { controller: '/admin/settings', action: :show_plugin, id: :"openproject_#{name}" },caption: name.capitalize,icon: 'icon2 icon-arrow',if: ->(*) { show }diff --git a/spec/features/admin/menu_item_traversal_spec.rb b/spec/features/admin/menu_item_traversal_spec.rbindex dce167bb191..7bf19aeb351 100644--- a/spec/features/admin/menu_item_traversal_spec.rb+++ b/spec/features/admin/menu_item_traversal_spec.rb@@ -28,8 +28,8 @@require 'spec_helper'-describe 'Menu item traversal', type: :feature, js: true do- let(:admin) { FactoryBot.create(:admin) }+describe 'Menu item traversal', type: :feature do+ shared_let(:admin) { FactoryBot.create(:admin) }describe 'EnterpriseToken management' dobefore do@@ -48,4 +48,52 @@ describe 'Menu item traversal', type: :feature, js: true doexpect(page).to have_no_selector('.admin-overview-menu-item.selected')endend++ describe 'route authorization', with_settings: { login_required?: false } do+ let(:user) { FactoryBot.create :user }+ let(:anon) { User.anonymous }++ let(:check_link) do+ ->(link) {+ visit link++ if current_url.include? "/login?back_url="+ expect(page).to have_text('Sign in'), "#{link} should redirect to sign in"+ else+ expect(page).to have_text(I18n.t(:notice_not_authorized)), "#{link} should result in 403 response"+ end+ }+ end++ let(:check_authorized_link) do+ ->(link) {+ visit link++ expect(current_url).to include link+ expect(page).to have_http_status(200)+ expect(page).to have_no_text(I18n.t(:notice_not_authorized))+ expect(page).to have_selector '#menu-sidebar .selected'+ }+ end++ it 'checks for authorized status for all links' do+ login_as admin+ visit admin_index_path++ # Get all admin links from there+ links = all('#menu-sidebar a[href]', visible: :all)+ .map { |node| node['href'] }+ .reject { |link| link.end_with? '/#' }+ .compact+ .uniq++ links.each(&check_authorized_link)++ login_as anon+ links.each(&check_link)++ login_as user+ links.each(&check_link)+ end+ endenddiff --git a/spec/features/admin/settings_spec.rb b/spec/features/admin/settings_spec.rbindex ae1ce596afe..48a9c94a35f 100644--- a/spec/features/admin/settings_spec.rb+++ b/spec/features/admin/settings_spec.rb@@ -35,14 +35,14 @@ describe 'Settings', type: :feature dobefore dologin_as(admin)- visit '/settings/api'+ visit '/admin/settings/api'endshared_examples "it can be visited" dolet(:section) { raise "define me" }before do- visit "/settings/#{section}"+ visit "/admin/settings/#{section}"endit "can be visited" dodiff --git a/spec/features/admin/test_mail_notification_spec.rb b/spec/features/admin/test_mail_notification_spec.rbindex 0e82dee1a94..87e1b10d89f 100644--- a/spec/features/admin/test_mail_notification_spec.rb+++ b/spec/features/admin/test_mail_notification_spec.rb@@ -33,7 +33,7 @@ describe 'Test mail notification', type: :feature dobefore dologin_as(admin)- visit admin_mail_notifications_path(tab: :notifications)+ visit admin_settings_mail_notifications_path(tab: :notifications)endit 'shows the correct message on errors in test notification (Regression #28226)' dodiff --git a/spec/features/auth/consent_auth_stage_spec.rb b/spec/features/auth/consent_auth_stage_spec.rbindex 2b7cb2bbb84..cc2322fa7da 100644--- a/spec/features/auth/consent_auth_stage_spec.rb+++ b/spec/features/auth/consent_auth_stage_spec.rb@@ -152,7 +152,7 @@ describe 'Authentication Stages', type: :feature doexpect_logged_in# Update consent date- visit users_settings_path+ visit admin_settings_users_pathfind("#toggle_consent_time").set(true)click_on 'Save'diff --git a/spec/features/projects/projects_portfolio_spec.rb b/spec/features/projects/projects_portfolio_spec.rbindex f189470e012..8c366e82d00 100644--- a/spec/features/projects/projects_portfolio_spec.rb+++ b/spec/features/projects/projects_portfolio_spec.rb@@ -82,7 +82,7 @@ describe 'Projects index page',let!(:work_package_b) { FactoryBot.create :work_package, subject: 'WP B', type: type_milestone, project: project_b }it 'can manage and browse the project portfolio Gantt' do- visit projects_settings_path+ visit admin_settings_projects_path# It has checked all selected settingsSetting.enabled_projects_columns.each do |name|diff --git a/spec/features/repositories/repository_settings_page.rb b/spec/features/repositories/repository_settings_page.rbindex e961ce3b2eb..ba790e9cbff 100644--- a/spec/features/repositories/repository_settings_page.rb+++ b/spec/features/repositories/repository_settings_page.rb@@ -34,11 +34,7 @@ class RepositorySettingsPage@project = projectend- def repository_settings_path- settings_repository_project_path(@project.id)- end-def visit_repository_settings- visit repository_settings_path+ visit settings_repository_project_path(@project.id)endenddiff --git a/spec/features/users/delete_spec.rb b/spec/features/users/delete_spec.rbindex 0201f45aa91..5c061c67156 100644--- a/spec/features/users/delete_spec.rb+++ b/spec/features/users/delete_spec.rb@@ -126,7 +126,7 @@ describe 'user deletion: ', type: :feature, js: true doSetting.users_deletable_by_admins = 0Setting.users_deletable_by_self = 0- visit users_settings_path+ visit admin_settings_users_pathfind(:css, "#settings_users_deletable_by_admins").set(true)find(:css, "#settings_users_deletable_by_self").set(true)diff --git a/spec/features/users/password_change_spec.rb b/spec/features/users/password_change_spec.rbindex 8a8ffcc4122..75ede2a3ceb 100644--- a/spec/features/users/password_change_spec.rb+++ b/spec/features/users/password_change_spec.rb@@ -119,7 +119,7 @@ describe 'random password generation',endit 'can configure and enforce password rules', js: true do- visit authentication_settings_path+ visit admin_settings_authentication_pathexpect_angular_frontend_initialized# Enforce rulesdiff --git a/spec/routing/admin/incoming_mails_spec.rb b/spec/routing/admin/incoming_mails_spec.rbindex 4878a139a58..5611d9fec8f 100644--- a/spec/routing/admin/incoming_mails_spec.rb+++ b/spec/routing/admin/incoming_mails_spec.rb@@ -30,10 +30,12 @@ require 'spec_helper'describe 'admin incoming_mails routes', type: :routing doit do- expect(get('admin/incoming_mails')).to route_to('admin/incoming_mails#show')+ expect(get('admin/settings/incoming_mails'))+ .to route_to('admin/settings/incoming_mails_settings#show')endit do- expect(patch('admin/incoming_mails')).to route_to('admin/incoming_mails#update')+ expect(patch('admin/settings/incoming_mails'))+ .to route_to('admin/settings/incoming_mails_settings#update')endenddiff --git a/spec/routing/admin/mail_notifications_spec.rb b/spec/routing/admin/mail_notifications_spec.rbindex 19c1a55cb7b..ca6b1b5e912 100644--- a/spec/routing/admin/mail_notifications_spec.rb+++ b/spec/routing/admin/mail_notifications_spec.rb@@ -30,10 +30,12 @@ require 'spec_helper'describe 'admin mail_notifications routes', type: :routing doit do- expect(get('admin/mail_notifications')).to route_to('admin/mail_notifications#show')+ expect(get('admin/settings/mail_notifications'))+ .to route_to('admin/settings/mail_notifications_settings#show')endit do- expect(patch('admin/mail_notifications')).to route_to('admin/mail_notifications#update')+ expect(patch('admin/settings/mail_notifications'))+ .to route_to('admin/settings/mail_notifications_settings#update')endenddiff --git a/spec/routing/settings_spec.rb b/spec/routing/settings_spec.rbindex ababa9d17c8..b6c789f3ad2 100644--- a/spec/routing/settings_spec.rb+++ b/spec/routing/settings_spec.rb@@ -29,20 +29,17 @@require 'spec_helper'describe 'settings routes', type: :routing do- it { expect(get('/settings')).to route_to('settings#show') }-it do- expect(patch('/settings')).to route_to('settings#update')+ expect(get('/admin/settings/plugin/abc'))+ .to route_to(controller: 'admin/settings',+ action: 'show_plugin',+ id: 'abc')endit do- expect(get('/settings/plugin/abc')).to route_to(controller: 'settings',- action: 'plugin',- id: 'abc')- end- it do- expect(post('/settings/plugin/abc')).to route_to(controller: 'settings',- action: 'plugin',- id: 'abc')+ expect(post('/admin/settings/plugin/abc'))+ .to route_to(controller: 'admin/settings',+ action: 'update_plugin',+ id: 'abc')endenddiff --git a/spec/views/authentication/authentication_settings.html.erb_spec.rb b/spec/views/admin/settings/authentication/show.html.erb_spec.rbsimilarity index 97%rename from spec/views/authentication/authentication_settings.html.erb_spec.rbrename to spec/views/admin/settings/authentication/show.html.erb_spec.rbindex e2143c89604..037dc0e50eb 100644--- a/spec/views/authentication/authentication_settings.html.erb_spec.rb+++ b/spec/views/admin/settings/authentication/show.html.erb_spec.rb@@ -28,7 +28,7 @@require 'spec_helper'-describe 'authentication/authentication_settings', type: :view do+describe 'admin/settings/authentication_settings/show', type: :view docontext 'with password login enabled' dobefore doallow(OpenProject::Configuration).to receive(:disable_password_login?).and_return(false)