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
Use DELETE method to unset project status
Alexander Brandon Coles3550aade4926
diff --git a/app/components/projects/status_button_component.rb b/app/components/projects/status_button_component.rbindex 7f7fb40b9d7..dd7a9cc4d88 100644--- a/app/components/projects/status_button_component.rb+++ b/app/components/projects/status_button_component.rb@@ -87,7 +87,7 @@ class Projects::StatusButtonComponent < ApplicationComponenttag: :a,href: project_status_path(project, status_code: status.value),content_arguments: {- data: { turbo_method: :put },+ data: { turbo_method: status.value ? :put : :delete },aria: { current: (true if status == @status) }})diff --git a/app/constants/projects/statuses.rb b/app/constants/projects/statuses.rbindex 672796499d0..93dff7bc10d 100644--- a/app/constants/projects/statuses.rb+++ b/app/constants/projects/statuses.rb@@ -32,7 +32,7 @@ module Projectsmodule StatusesStatus = Data.define(:code, :color, :icon) dodef id = code&.to_s || :none- def value = code.to_s+ def value = code&.to_sendNOT_SET = Status.new(code: nil, color: Color.new(hexcode: "#24292F"), icon: "issue-draft")diff --git a/app/controllers/projects/status_controller.rb b/app/controllers/projects/status_controller.rbindex f48e14125fb..8942b9316fd 100644--- a/app/controllers/projects/status_controller.rb+++ b/app/controllers/projects/status_controller.rb@@ -36,9 +36,19 @@ class Projects::StatusController < ApplicationControllerbefore_action :authorizedef update+ change_status_action(params.fetch(:status_code).presence)+ end++ def destroy+ change_status_action(nil)+ end++ private++ def change_status_action(status_code)call = Projects::UpdateService.new(model: @project, user: current_user)- .call(status_code: params.fetch(:status_code).presence)+ .call(status_code:)if call.success?@project = call.result@@ -51,8 +61,6 @@ class Projects::StatusController < ApplicationControllerendend- private-def respond_with_update_status_buttonmessage = t(:notice_successful_update)update_via_turbo_stream(component: Projects::StatusButtonComponent.new(project: @project, user: current_user))diff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rbindex 4a674231a00..2e7d7512812 100644--- a/config/initializers/permissions.rb+++ b/config/initializers/permissions.rb@@ -104,7 +104,7 @@ Rails.application.reloader.to_prepare do"projects/settings/work_packages/internal_comments": %i[show update],"projects/templated": %i[create destroy],"projects/identifier": %i[show update],- "projects/status": %i[update]+ "projects/status": %i[update destroy]},permissible_on: :project,require: :member,diff --git a/config/routes.rb b/config/routes.rbindex 3d386c70016..1d8d02521ce 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -293,7 +293,7 @@ Rails.application.routes.draw doresource :templated, only: %i[create destroy], controller: "templated"resource :archive, only: %i[create destroy], controller: "archive"resource :identifier, only: %i[show update], controller: "identifier"- resource :status, only: %i[update], controller: "status"+ resource :status, only: %i[update destroy], controller: "status"endmember dodiff --git a/spec/components/projects/status_button_component_spec.rb b/spec/components/projects/status_button_component_spec.rbindex e56f97047fb..c583a651b89 100644--- a/spec/components/projects/status_button_component_spec.rb+++ b/spec/components/projects/status_button_component_spec.rb@@ -89,7 +89,9 @@ RSpec.describe Projects::StatusButtonComponent, type: :component doexpect(page).to have_menu doexpect(page).to have_selector :menuitem, count: 7- expect(page).to have_selector :menuitem, text: "Not set", aria: { current: true }+ expect(page).to (have_selector :menuitem, text: "Not set", aria: { current: true } do |link|+ expect(link[:"data-turbo-method"]).to eq "delete"+ end)expect(page).to have_selector :menuitem, text: "On track"expect(page).to have_selector :menuitem, text: "At risk"expect(page).to have_selector :menuitem, text: "Not started"@@ -118,7 +120,9 @@ RSpec.describe Projects::StatusButtonComponent, type: :component doexpect(page).to have_menu doexpect(page).to have_selector :menuitem, count: 7expect(page).to have_selector :menuitem, text: "Not set"- expect(page).to have_selector :menuitem, text: "On track", aria: { current: true }+ expect(page).to (have_selector :menuitem, text: "On track", aria: { current: true } do |link|+ expect(link[:"data-turbo-method"]).to eq "put"+ end)expect(page).to have_selector :menuitem, text: "At risk"expect(page).to have_selector :menuitem, text: "Not started"expect(page).to have_selector :menuitem, text: "Finished"diff --git a/spec/controllers/projects/status_controller_spec.rb b/spec/controllers/projects/status_controller_spec.rbindex cee7f1d8998..125f142dad8 100644--- a/spec/controllers/projects/status_controller_spec.rb+++ b/spec/controllers/projects/status_controller_spec.rb@@ -34,24 +34,24 @@ RSpec.describe Projects::StatusController doshared_let(:user) { create(:admin) }current_user { user }- describe "PUT #update" do- let(:project) { build_stubbed(:project) }- let(:service_result) { ServiceResult.success(result: project) }+ let(:project) { build_stubbed(:project) }+ let(:service_result) { ServiceResult.success(result: project) }- before do- allow(Project)- .to receive(:find)- .with(project.identifier)- .and_return(project)+ before do+ allow(Project)+ .to receive(:find)+ .with(project.identifier)+ .and_return(project)- update_service = instance_double(Projects::UpdateService, call: service_result)+ update_service = instance_double(Projects::UpdateService, call: service_result)- allow(Projects::UpdateService)- .to receive(:new)- .with(user:, model: project)- .and_return(update_service)- end+ allow(Projects::UpdateService)+ .to receive(:new)+ .with(user:, model: project)+ .and_return(update_service)+ end+ describe "PUT #update" docontext "when service call succeeds" docontext "with valid status_code param" docontext "with a text/html request" do@@ -133,4 +133,52 @@ RSpec.describe Projects::StatusController doendendend++ describe "DELETE #destroy" do+ context "when service call succeeds" do+ context "with a text/html request" do+ it "redirects back or to project show" do+ delete :destroy, params: { project_id: project }++ expect(response).to redirect_to project_path(project)+ expect(flash[:notice]).to eq I18n.t(:notice_successful_update)+ end+ end++ context "with a turbo stream request" do+ it "renders turbo streams updating Projects::StatusButtonComponent and flash action" do+ delete :destroy, params: { project_id: project }, format: :turbo_stream++ expect(response).to be_successful+ expect(assigns(:project)).to eq project+ expect(response).to have_turbo_stream action: "update", target: "projects-status-button-component"+ expect(response).to have_turbo_stream action: "flash", target: "op-primer-flash-component"+ end+ end+ end++ context "when service call fails" do+ let(:service_result) { ServiceResult.failure(result: project, message: "Custom Field 1 must not be blank") }++ context "with a text/html request" do+ it "redirects back or to project show" do+ delete :destroy, params: { project_id: project }++ expect(response).to redirect_to project_path(project)+ expect(flash[:error]).to start_with I18n.t(:notice_unsuccessful_update_with_reason, reason: "")+ end+ end++ context "with a turbo stream request" do+ it "renders turbo stream flash action" do+ delete :destroy, params: { project_id: project }, format: :turbo_stream++ expect(response).not_to be_successful+ expect(response).to have_http_status :unprocessable_entity+ expect(assigns(:project)).to eq project+ expect(response).to have_turbo_stream action: "flash", target: "op-primer-flash-component"+ end+ end+ end+ endenddiff --git a/spec/routing/project_status_routing_spec.rb b/spec/routing/project_status_routing_spec.rbindex 15987860851..6e374a27628 100644--- a/spec/routing/project_status_routing_spec.rb+++ b/spec/routing/project_status_routing_spec.rb@@ -38,4 +38,12 @@ RSpec.describe Projects::StatusController do)endend++ describe "destroy" do+ it do+ expect(delete("/projects/123/status")).to route_to(+ controller: "projects/status", action: "destroy", project_id: "123"+ )+ end+ endend