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
Add edit permission specs
Dombi Attilabfe6a7fef734
diff --git a/modules/overviews/app/components/project_life_cycles/sections/show_component.html.erb b/modules/overviews/app/components/project_life_cycles/sections/show_component.html.erbindex f26a88cef74..05fe5aa93fc 100644--- a/modules/overviews/app/components/project_life_cycles/sections/show_component.html.erb+++ b/modules/overviews/app/components/project_life_cycles/sections/show_component.html.erb@@ -6,6 +6,19 @@)) do |section|section.with_title { t('label_life_cycle_plural') }+ if allowed_to_edit?+ section.with_action_icon(+ icon: :pencil,+ tag: :a,+ href: project_life_cycles_dialog_path(project_id: @project.id),+ data: {+ controller: 'async-dialog'+ },+ test_selector: "project-life-cycles-edit-button",+ aria: { label: I18n.t(:label_edit) }+ )+ end+flex_layout do |details_container|@life_cycle_steps.each_with_index do |life_cycle_step, i|margin = i == @life_cycle_steps.size - 1 ? 0 : 3diff --git a/modules/overviews/app/components/project_life_cycles/sections/show_component.rb b/modules/overviews/app/components/project_life_cycles/sections/show_component.rbindex 25c27bb2945..f7af8e54be1 100644--- a/modules/overviews/app/components/project_life_cycles/sections/show_component.rb+++ b/modules/overviews/app/components/project_life_cycles/sections/show_component.rb@@ -44,7 +44,7 @@ module ProjectLifeCyclesprivatedef allowed_to_edit?- User.current.allowed_in_project?(:edit_project_attributes, @project)+ User.current.allowed_in_project?(:edit_project_stages_and_gates, @project)endendenddiff --git a/modules/overviews/app/controllers/overviews/overviews_controller.rb b/modules/overviews/app/controllers/overviews/overviews_controller.rbindex 368a388eb9f..62cb78ce110 100644--- a/modules/overviews/app/controllers/overviews/overviews_controller.rb+++ b/modules/overviews/app/controllers/overviews/overviews_controller.rb@@ -44,10 +44,6 @@ module ::Overviewsrender :project_custom_fields_sidebar, layout: falseend- def project_life_cycles_sidebar- render :project_life_cycles_sidebar, layout: false- end-def project_custom_field_section_dialogrespond_with_dialog(ProjectCustomFields::Sections::EditDialogComponent.new(@@ -81,6 +77,21 @@ module ::Overviewsrespond_to_with_turbo_streams(status: service_call.success? ? :ok : :unprocessable_entity)end+ def project_life_cycles_sidebar+ render :project_life_cycles_sidebar, layout: false+ end++ def project_life_cycles_dialog+ respond_with_dialog(+ ProjectCustomFields::Sections::EditDialogComponent.new(+ project: @project,+ project_custom_field_section: ProjectCustomFieldSection.first+ )+ )+ end++ def update_project_life_cycles; end+def jump_to_project_menu_itemif params[:jump]# try to redirect to the requested menu itemdiff --git a/modules/overviews/config/routes.rb b/modules/overviews/config/routes.rbindex 8acce99b77c..dcdfc288979 100644--- a/modules/overviews/config/routes.rb+++ b/modules/overviews/config/routes.rb@@ -12,5 +12,9 @@ Rails.application.routes.draw doget "projects/:project_id/project_life_cycles_sidebar", to: "overviews/overviews#project_life_cycles_sidebar",as: :project_life_cycles_sidebar+ get "projects/:project_id/project_life_cycles_dialog", to: "overviews/overviews#project_life_cycles_dialog",+ as: :project_life_cycles_dialog+ put "projects/:project_id/update_project_life_cycles", to: "overviews/overviews#update_project_life_cycles",+ as: :update_project_life_cyclesendenddiff --git a/modules/overviews/lib/overviews/engine.rb b/modules/overviews/lib/overviews/engine.rbindex df4464731f7..761a8f01509 100644--- a/modules/overviews/lib/overviews/engine.rb+++ b/modules/overviews/lib/overviews/engine.rb@@ -64,6 +64,19 @@ module Overviews"overviews/overviews/update_project_custom_values")+ OpenProject::AccessControl.permission(:view_project_stages_and_gates)+ .controller_actions+ .push(+ "overviews/overviews/project_life_cycles_sidebar"+ )++ OpenProject::AccessControl.permission(:edit_project_stages_and_gates)+ .controller_actions+ .push(+ "overviews/overviews/project_life_cycles_dialog",+ "overviews/overviews/update_project_life_cycles"+ )+OpenProject::AccessControl.permission(:view_work_packages).controller_actions.push(diff --git a/spec/features/projects/life_cycle/overview_page/dialog/permission_spec.rb b/spec/features/projects/life_cycle/overview_page/dialog/permission_spec.rbindex a049bb751ec..1623d8ae85d 100644--- a/spec/features/projects/life_cycle/overview_page/dialog/permission_spec.rb+++ b/spec/features/projects/life_cycle/overview_page/dialog/permission_spec.rb@@ -60,5 +60,24 @@ RSpec.describe "Edit project stages and gates on project overview page", :js, :wexpect(page).to have_text("Project lifecycle")endend++ describe "with Edit project permissions" do+ let(:permissions) { [:view_project, :view_project_stages_and_gates, :edit_project] }++ it "does not show the edit buttons" do+ overview_page.within_life_cycles_sidebar do+ expect(page).to have_no_css("[data-test-selector='project-life-cycles-edit-button']")+ end+ end+ end++ describe "with sufficient Edit Stages and Gates permissions" do+ let(:permissions) { [:view_project, :view_project_stages_and_gates, :edit_project, :edit_project_stages_and_gates] }++ it "shows the edit buttons" do+ overview_page.within_life_cycles_sidebar do+ expect(page).to have_css("[data-test-selector='project-life-cycles-edit-button']")+ end+ endendenddiff --git a/spec/permissions/edit_project_life_cycles_spec.rb b/spec/permissions/edit_project_life_cycles_spec.rbnew file mode 100644index 00000000000..50840e76efb--- /dev/null+++ b/spec/permissions/edit_project_life_cycles_spec.rb@@ -0,0 +1,41 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++require "spec_helper"+require File.expand_path("../support/permission_specs", __dir__)++RSpec.describe Overviews::OverviewsController, "edit_project_life_cycles permission", # rubocop:disable RSpec/EmptyExampleGroup,RSpec/SpecFilePathFormat+ type: :controller do+ include PermissionSpecs++ # render dialog with inputs for editing project attributes with edit_project permission+ check_permission_required_for("overviews/overviews#project_life_cycles_dialog", :edit_project_stages_and_gates)++ # update project attributes with edit_project permission, deeper permission check via contract in place+ check_permission_required_for("overviews/overviews#update_project_life_cycles", :edit_project_stages_and_gates)+enddiff --git a/spec/permissions/view_project_life_cycles_spec.rb b/spec/permissions/view_project_life_cycles_spec.rbnew file mode 100644index 00000000000..294c55fa8a6--- /dev/null+++ b/spec/permissions/view_project_life_cycles_spec.rb@@ -0,0 +1,38 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++require "spec_helper"+require File.expand_path("../support/permission_specs", __dir__)++RSpec.describe Overviews::OverviewsController, "view_project_life_cycles permission", # rubocop:disable RSpec/EmptyExampleGroup,RSpec/SpecFilePathFormat+ type: :controller do+ include PermissionSpecs++ # render sidebar on project overview page with view_project permission+ check_permission_required_for("overviews/overviews#project_life_cycles_sidebar", :view_project_stages_and_gates)+end