Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[35157] Fix backlogs settings validations to disallow task = story (#9009)

Oliver Günther5f8a9a186881
diff --git a/app/helpers/project_settings_helper.rb b/app/helpers/project_settings_helper.rb
index d7f94c686ec..adc6124bf15 100644
--- a/app/helpers/project_settings_helper.rb
+++ b/app/helpers/project_settings_helper.rb
@@ -73,6 +73,12 @@ module ProjectSettingsHelper
name: 'activities',
action: { controller: '/project_settings/activities', action: 'show' },
label: :enumeration_activities
+ },
+ {
+ name: :backlogs,
+ action: { controller: '/backlogs_project_settings', action: 'show' },
+ label: :label_backlogs,
+ if: ->(project) { project.module_enabled?('backlogs') }
}
]
end
diff --git a/config/initializers/menus.rb b/config/initializers/menus.rb
index ff93364f98f..14308cada47 100644
--- a/config/initializers/menus.rb
+++ b/config/initializers/menus.rb
@@ -344,13 +344,13 @@ Redmine::MenuManager.map :admin_menu do |menu|
parent: :admin_costs
menu.push :admin_backlogs,
- { controller: '/settings', action: 'plugin', id: :openproject_backlogs },
+ { controller: '/backlogs_settings', action: :show },
if: Proc.new { User.current.admin? },
caption: :label_backlogs,
icon: 'icon2 icon-backlogs'
menu.push :backlogs_settings,
- { controller: '/settings', action: 'plugin', id: :openproject_backlogs },
+ { controller: '/backlogs_settings', action: :show },
if: Proc.new { User.current.admin? },
caption: :label_setting_plural,
parent: :admin_backlogs
diff --git a/modules/backlogs/lib/open_project/backlogs/patches/project_settings_helper_patch.rb b/modules/backlogs/app/controllers/backlogs_project_settings_controller.rb
similarity index 63%
rename from modules/backlogs/lib/open_project/backlogs/patches/project_settings_helper_patch.rb
rename to modules/backlogs/app/controllers/backlogs_project_settings_controller.rb
index 9acebacba67..495a68aab56 100644
--- a/modules/backlogs/lib/open_project/backlogs/patches/project_settings_helper_patch.rb
+++ b/modules/backlogs/app/controllers/backlogs_project_settings_controller.rb
@@ -1,3 +1,5 @@
+#-- encoding: UTF-8
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2021 the OpenProject GmbH
@@ -26,25 +28,11 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-require_dependency 'project_settings_helper'
-
-module OpenProject::Backlogs::Patches::ProjectSettingsHelperPatch
- def self.included(base)
- base.module_eval do
- alias_method :project_settings_tabs_without_backlogs, :project_settings_tabs
+class BacklogsProjectSettingsController < ProjectSettingsController
+ menu_item :settings_backlogs
- def project_settings_tabs
- project_settings_tabs_without_backlogs.tap do |settings|
- settings << {
- name: :backlogs,
- action: { controller: '/backlogs_settings', action: 'show' },
- label: :label_backlogs,
- if: ->(p) { p.module_enabled?('backlogs') }
- }
- end
- end
- end
+ def show
+ @statuses_done_for_project = @project.done_statuses.select(:id).map(&:id)
+ render template: '/project_settings/backlogs_settings'
end
end
-
-ProjectSettingsHelper.include OpenProject::Backlogs::Patches::ProjectSettingsHelperPatch
diff --git a/modules/backlogs/app/controllers/backlogs_settings_controller.rb b/modules/backlogs/app/controllers/backlogs_settings_controller.rb
index 3fc9854c9bd..6e00b3acfc6 100644
--- a/modules/backlogs/app/controllers/backlogs_settings_controller.rb
+++ b/modules/backlogs/app/controllers/backlogs_settings_controller.rb
@@ -28,11 +28,43 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class BacklogsSettingsController < ProjectSettingsController
- menu_item :settings_backlogs
+class BacklogsSettingsController < ApplicationController
+ layout 'admin'
+ menu_item :backlogs_settings
- def show
- @statuses_done_for_project = @project.done_statuses.select(:id).map(&:id)
- render template: '/project_settings/backlogs_settings'
+ before_action :require_admin
+ before_action :check_valid_settings, only: :update
+
+ def show; end
+
+ def update
+ Setting["plugin_openproject_backlogs"] = update_settings
+ flash[:notice] = I18n.t(:notice_successful_update)
+
+ redirect_to action: :show
+ end
+
+ def show_local_breadcrumb
+ true
+ end
+
+ def default_breadcrumb
+ I18n.t(:label_backlogs)
+ end
+
+ private
+
+ def check_valid_settings
+ story_types = update_settings[:story_types]
+ task_type = update_settings[:task_type]
+
+ if story_types.include?(task_type)
+ flash[:error] = I18n.t(:error_backlogs_task_cannot_be_story)
+ redirect_to action: :show
+ end
+ end
+
+ def update_settings
+ @update_settings ||= permitted_params.backlogs_admin_settings.to_h
end
end
diff --git a/modules/backlogs/app/views/backlogs_settings/show.html.erb b/modules/backlogs/app/views/backlogs_settings/show.html.erb
new file mode 100644
index 00000000000..c959f1b0e9f
--- /dev/null
+++ b/modules/backlogs/app/views/backlogs_settings/show.html.erb
@@ -0,0 +1,69 @@
+<%#-- 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.
+
+++#%>
+
+<% html_title t(:label_administration), t(:label_backlogs) %>
+
+<%= form_tag(:admin_backlogs_settings, method: :put, name: 'admin_backlogs_form') do %>
+ <div class="form--field">
+ <%= styled_label_tag("settings[story_types]", t(:backlogs_story_type)) %>
+ <div class="form--field-container">
+ <%= styled_select_tag("settings[story_types]",
+ options_from_collection_for_select(Type.all, :id, :name, Story.types),
+ :multiple => true,
+ container_class: '-slim') %>
+ </div>
+ </div>
+ <div class="form--field">
+ <%= styled_label_tag("settings[task_type]", t(:backlogs_task_type)) %>
+ <div class="form--field-container">
+ <%= styled_select_tag("settings[task_type]",
+ options_from_collection_for_select(Type.all, :id, :name, Task.type),
+ container_class: '-slim') %>
+ </div>
+ </div>
+ <div class="form--field">
+ <%= styled_label_tag("settings[points_burn_direction]", t(:backlogs_points_burn_direction)) %>
+ <div class="form--field-container">
+ <%= styled_select_tag("settings[points_burn_direction]",
+ options_for_select([[t(:label_points_burn_up), 'up'], [t(:label_points_burn_down), 'down']],
+ Setting.plugin_openproject_backlogs["points_burn_direction"]),
+ container_class: '-slim') %>
+ </div>
+ </div>
+ <div class="form--field">
+ <%= styled_label_tag("settings[wiki_template]", t(:backlogs_wiki_template)) %>
+ <div class="form--field-container">
+ <%= styled_text_field_tag("settings[wiki_template]",
+ Setting.plugin_openproject_backlogs["wiki_template"],
+ container_class: '-slim') %>
+ </div>
+ </div>
+
+ <%= styled_submit_tag t(:button_apply), class: '-highlight' %>
+<% end %>
diff --git a/modules/backlogs/app/views/shared/_settings.html.erb b/modules/backlogs/app/views/shared/_settings.html.erb
deleted file mode 100644
index bda29b8d801..00000000000
--- a/modules/backlogs/app/views/shared/_settings.html.erb
+++ /dev/null
@@ -1,97 +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.
-
-++#%>
-
-<% content_for :header_tags do %>
- <script type="text/javascript">
- jQuery(function($) {
- var enable_apply = function () {
- var tasktype,
- submit,
- disable;
-
- tasktype = $("#settings_task_type").val();
- submit = $('input[type=submit]');
-
- disable = false;
-
- $("#settings_story_types :selected").each(function(i, selected) {
- disable = disable || ($(selected).attr('value') === tasktype);
- });
-
- if (disable) {
- submit.attr('disabled', 'disabled');
- }
- else {
- submit.removeAttr('disabled');
- }
- };
-
- $("#settings_task_type").change(enable_apply);
- $("#settings_story_types").changes(enable_apply);
-
- enable_apply();
- });
- </script>
-<% end %>
-<% html_title t(:label_administration), t(:label_backlogs) %>
-
-<div class="form--field">
- <%= styled_label_tag("settings[story_types]", t(:backlogs_story_type)) %>
- <div class="form--field-container">
- <%= styled_select_tag("settings[story_types]",
- options_from_collection_for_select(Type.all, :id, :name, Story.types),
- :multiple => true,
- container_class: '-slim') %>
- </div>
-</div>
-<div class="form--field">
- <%= styled_label_tag("settings[task_type]", t(:backlogs_task_type)) %>
- <div class="form--field-container">
- <%= styled_select_tag("settings[task_type]",
- options_from_collection_for_select(Type.all, :id, :name, Task.type),
- container_class: '-slim') %>
- </div>
-</div>
-<div class="form--field">
- <%= styled_label_tag("settings[points_burn_direction]", t(:backlogs_points_burn_direction)) %>
- <div class="form--field-container">
- <%= styled_select_tag("settings[points_burn_direction]",
- options_for_select([[t(:label_points_burn_up), 'up'], [t(:label_points_burn_down), 'down']],
- Setting.plugin_openproject_backlogs["points_burn_direction"]),
- container_class: '-slim') %>
- </div>
-</div>
-<div class="form--field">
- <%= styled_label_tag("settings[wiki_template]", t(:backlogs_wiki_template)) %>
- <div class="form--field-container">
- <%= styled_text_field_tag("settings[wiki_template]",
- Setting.plugin_openproject_backlogs["wiki_template"],
- container_class: '-slim') %>
- </div>
-</div>
diff --git a/modules/backlogs/config/locales/en.yml b/modules/backlogs/config/locales/en.yml
index 9b771c280ea..967215b1c6b 100644
--- a/modules/backlogs/config/locales/en.yml
+++ b/modules/backlogs/config/locales/en.yml
@@ -113,6 +113,7 @@ en:
button_edit_wiki: "Edit wiki page"
+ error_backlogs_task_cannot_be_story: "The settings are invalid. The selected task type can not also be a story type."
error_intro_plural: "The following errors were encountered:"
error_intro_singular: "The following error was encountered:"
error_outro: "Please correct the above errors before submitting again."
diff --git a/modules/backlogs/config/routes.rb b/modules/backlogs/config/routes.rb
index a4e0e7140af..a2c7432a16e 100644
--- a/modules/backlogs/config/routes.rb
+++ b/modules/backlogs/config/routes.rb
@@ -58,5 +58,12 @@ OpenProject::Application.routes.draw do
get 'projects/:project_id/versions/:id/edit' => 'version_settings#edit'
post 'projects/:id/project_done_statuses' => 'projects#project_done_statuses'
post 'projects/:id/rebuild_positions' => 'projects#rebuild_positions'
- get 'projects/:id/settings/backlogs', controller: 'backlogs_settings', action: 'show', as: 'settings_backlogs'
+ get 'projects/:id/settings/backlogs', controller: 'backlogs_project_settings', action: 'show', as: 'settings_backlogs'
+
+ scope 'admin' do
+ resource :backlogs,
+ only: %i[show update],
+ controller: :backlogs_settings,
+ as: 'admin_backlogs_settings'
+ end
end
diff --git a/modules/backlogs/lib/open_project/backlogs/engine.rb b/modules/backlogs/lib/open_project/backlogs/engine.rb
index b7833a768f9..4ef4446e1fa 100644
--- a/modules/backlogs/lib/open_project/backlogs/engine.rb
+++ b/modules/backlogs/lib/open_project/backlogs/engine.rb
@@ -35,11 +35,14 @@ module OpenProject::Backlogs
engine_name :openproject_backlogs
def self.settings
- { default: { 'story_types' => nil,
- 'task_type' => nil,
- 'card_spec' => nil },
- partial: 'shared/settings',
- menu_item: :backlogs_settings }
+ {
+ default: {
+ 'story_types' => nil,
+ 'task_type' => nil,
+ 'card_spec' => nil
+ },
+ menu_item: :backlogs_settings
+ }
end
include OpenProject::Plugins::ActsAsOpEngine
@@ -51,7 +54,7 @@ module OpenProject::Backlogs
OpenProject::AccessControl.permission(:edit_project).tap do |add|
add.actions << 'projects/project_done_statuses'
add.actions << 'projects/rebuild_positions'
- add.actions << 'backlogs_settings/show'
+ add.actions << 'backlogs_project_settings/show'
end
OpenProject::AccessControl.permission(:add_work_packages).tap do |add|
@@ -70,27 +73,27 @@ module OpenProject::Backlogs
# SYNTAX: permission :name_of_permission, { :controller_name => [:action1, :action2] }
# Master backlog permissions
- permission :view_master_backlog, rb_master_backlogs: :index,
- rb_sprints: %i[index show],
- rb_wikis: :show,
- rb_stories: %i[index show],
- rb_queries: :show,
- rb_burndown_charts: :show,
- rb_export_card_configurations: %i[index show]
-
- permission :view_taskboards, rb_taskboards: :show,
- rb_sprints: :show,
- rb_stories: :show,
- rb_tasks: %i[index show],
- rb_impediments: %i[index show],
- rb_wikis: :show,
- rb_burndown_charts: :show,
- rb_export_card_configurations: %i[index show]
+ permission :view_master_backlog, rb_master_backlogs: :index,
+ rb_sprints: %i[index show],
+ rb_wikis: :show,
+ rb_stories: %i[index show],
+ rb_queries: :show,
+ rb_burndown_charts: :show,
+ rb_export_card_configurations: %i[index show]
+
+ permission :view_taskboards, rb_taskboards: :show,
+ rb_sprints: :show,
+ rb_stories: :show,
+ rb_tasks: %i[index show],
+ rb_impediments: %i[index show],
+ rb_wikis: :show,
+ rb_burndown_charts: :show,
+ rb_export_card_configurations: %i[index show]
# Sprint permissions
# :show_sprints and :list_sprints are implicit in :view_master_backlog permission
- permission :update_sprints, rb_sprints: %i[edit update],
- rb_wikis: %i[edit update]
+ permission :update_sprints, rb_sprints: %i[edit update],
+ rb_wikis: %i[edit update]
end
menu :project_menu,
@@ -111,7 +114,6 @@ module OpenProject::Backlogs
Type
Project
ProjectsController
- ProjectSettingsHelper
User
VersionsController
Version]
diff --git a/modules/backlogs/lib/open_project/backlogs/patches/permitted_params_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/permitted_params_patch.rb
index a1bc2a1fdf3..7896906b22f 100644
--- a/modules/backlogs/lib/open_project/backlogs/patches/permitted_params_patch.rb
+++ b/modules/backlogs/lib/open_project/backlogs/patches/permitted_params_patch.rb
@@ -47,6 +47,12 @@ module OpenProject::Backlogs::Patches::PermittedParamsPatch
backlogs_params = params.fetch(:backlogs, {}).permit(:task_color, :versions_default_fold_state)
super.merge(backlogs: backlogs_params)
end
+
+ def backlogs_admin_settings
+ params
+ .require(:settings)
+ .permit(:task_type, :points_burn_direction, :wiki_template, story_types: [])
+ end
end
end
PermittedParams.include OpenProject::Backlogs::Patches::PermittedParamsPatch
diff --git a/modules/backlogs/lib/open_project/backlogs/patches/projects_controller_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/projects_controller_patch.rb
index 07269737c62..c0c6ba5d28e 100644
--- a/modules/backlogs/lib/open_project/backlogs/patches/projects_controller_patch.rb
+++ b/modules/backlogs/lib/open_project/backlogs/patches/projects_controller_patch.rb
@@ -65,7 +65,7 @@ module OpenProject::Backlogs::Patches::ProjectsControllerPatch
end
def redirect_to_backlogs_settings
- redirect_to controller: 'backlogs_settings', action: 'show', id: @project
+ redirect_to controller: 'backlogs_project_settings', action: 'show', id: @project
end
end
end
diff --git a/modules/backlogs/spec/controllers/backlogs_settings_controller_spec.rb b/modules/backlogs/spec/controllers/backlogs_settings_controller_spec.rb
new file mode 100644
index 00000000000..b0373789e0e
--- /dev/null
+++ b/modules/backlogs/spec/controllers/backlogs_settings_controller_spec.rb
@@ -0,0 +1,110 @@
+#-- 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'
+
+describe BacklogsSettingsController, type: :controller do
+ current_user { FactoryBot.build_stubbed :admin }
+
+ describe 'GET show' do
+ it 'performs that request' do
+ get :show
+ expect(response).to be_successful
+ expect(response).to render_template :show
+ end
+
+ context 'as regular user' do
+ current_user { FactoryBot.build_stubbed :user }
+
+ it 'fails' do
+ get :show
+ expect(response.status).to eq 403
+ end
+ end
+ end
+
+ describe 'PUT update' do
+ subject do
+ put :update,
+ params: {
+ settings: {
+ task_type: task_type,
+ story_types: story_types
+ }
+ }
+ end
+
+ context 'with invalid settings (Regression test #35157)' do
+ let(:task_type) { '1234' }
+ let(:story_types) { ['1234'] }
+
+ it 'does not update the settings' do
+ expect(Setting)
+ .not_to(receive(:[]=))
+ .with('plugin_openproject_backlogs')
+
+ subject
+
+ expect(response).to redirect_to action: :show
+ expect(flash[:error]).to include I18n.t(:error_backlogs_task_cannot_be_story)
+ end
+ end
+
+ context 'with valid settings' do
+ let(:task_type) { '1234' }
+ let(:story_types) { ['5555'] }
+
+ it 'does update the settings' do
+ expect(Setting)
+ .to(receive(:[]=))
+ .with('plugin_openproject_backlogs', { story_types: ['5555'], task_type: '1234' })
+
+ subject
+
+ expect(response).to redirect_to action: :show
+ expect(flash[:notice]).to include I18n.t(:notice_successful_update)
+ expect(flash[:error]).to be_nil
+ end
+
+ context 'with a non-admin' do
+ current_user { FactoryBot.build_stubbed :user }
+
+ it 'does not update the settings' do
+ expect(Setting)
+ .not_to(receive(:[]=))
+ .with('plugin_openproject_backlogs')
+
+ subject
+
+ expect(response).not_to be_successful
+ expect(response.status).to eq 403
+ end
+ end
+ end
+ end
+end