Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def move_to_sprint_dialog
)
end

def move
def move # rubocop:disable Metrics/AbcSize
# Capture the source before the call; the service reloads @work_package internally via #move_after.
source = @work_package.sprint

Expand All @@ -71,6 +71,13 @@ def move

if call.success?
move_work_package_to_target_component_via_turbo_stream(source:, target: call.result.sprint)

if work_package_invisible_after_move?(call.result, move_params[:target_id])
backlog_name = call.result.backlog_bucket&.name || I18n.t(:label_inbox)
render_flash_message_via_turbo_stream(
message: I18n.t(:notice_work_package_invisible_after_move, backlog: backlog_name)
)
end
else
render_error_flash_message_via_turbo_stream(
message: I18n.t(:notice_unsuccessful_update_with_reason, reason: call.message)
Expand Down Expand Up @@ -129,5 +136,14 @@ def displayed_work_packages
@work_packages.merge(WorkPackage.backlogs_inbox_for(project: @project))
end
end

# After a work package is moved to the backlog, it might no longer be visible due to
# the project settings for excluded types and statuses.
def work_package_invisible_after_move?(work_package, move_target_id)
return false unless move_target_id&.start_with?("backlog_bucket", "inbox")

@project.backlog_excluded_type_ids.include?(work_package.type_id) ||
@project.done_status_ids.include?(work_package.status_id)
end
end
end
3 changes: 2 additions & 1 deletion modules/backlogs/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@
notice_unsuccessful_start_with_reason: "The sprint could not be started: %{reason}"
notice_unsuccessful_finish: "The sprint could not be completed."
notice_unsuccessful_finish_with_reason: "The sprint could not be completed: %{reason}"

notice_work_package_invisible_after_move: >

Check failure on line 245 in modules/backlogs/config/locales/en.yml

View workflow job for this annotation

GitHub Actions / yamllint

[yamllint] reported by reviewdog 🐶 [error] wrong ordering of key "notice_work_package_invisible_after_move" in mapping (key-ordering) Raw Output: modules/backlogs/config/locales/en.yml:245:3: [error] wrong ordering of key "notice_work_package_invisible_after_move" in mapping (key-ordering)
The work package was moved to %{backlog} but is not visible because its type or status is excluded from the backlog.
permission_create_sprints: "Create sprints"
permission_manage_sprint_items: "Manage sprint items"
permission_select_backlog_types_and_statuses: "Select backlog types and statuses"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,23 @@
require "rails_helper"

RSpec.describe Backlogs::WorkPackagesController do
# Gets the html content of the template of the first turbo-stream with the
# given action.
def turbo_stream_template(action:)
Nokogiri("<response>#{response.body}</response>").css("turbo-stream[action=#{action}] template").first.inner_html
end

shared_let(:type_feature) { create(:type_feature) }
shared_let(:type_task) { create(:type_task) }

current_user { user }

shared_let(:user) { create(:admin) }
shared_let(:project) { create(:project) }
shared_let(:project) { create(:project, types: [type_feature, type_task]) }
shared_let(:status) { create(:status, name: "status 1", is_default: true) }

let(:sprint) { create(:sprint, name: "Agile Sprint 1", project:) }
let(:work_package) { create(:work_package, status:, sprint:, project:) }
let(:work_package) { create(:work_package, status:, sprint:, project:, type: type_feature) }

shared_examples "respecting the all param for inbox pagination" do
context "with an inbox over the pagination threshold" do
Expand Down Expand Up @@ -110,6 +116,18 @@
end

context "with a Sprint as source" do
shared_examples "shows a flash message after moving a work package that turns invisible" do |target_name|
it "shows a flash message after moving the work package" do
subject

message = "The work package was moved to #{target_name} but is not visible"
expect(response).to be_successful
expect(response).to have_http_status :ok
expect(response).to have_turbo_stream action: "flash", target: "op-primer-flash-component"
expect(turbo_stream_template(action: "flash")).to include(message)
end
end

context "with the same Sprint as target" do
let(:target_id) { "sprint:#{sprint.id}" }

Expand Down Expand Up @@ -172,6 +190,22 @@
expect(assigns(:work_package)).to eq(work_package_in_sprint)
end

context "when the project is configured to exclude the work packages status from backlogs" do
before do
project.done_statuses << status
end

include_examples "shows a flash message after moving a work package that turns invisible", "Inbox"
end

context "when the project is configured to exclude the work packages type from backlogs" do
before do
project.backlog_excluded_types << type_feature
end

include_examples "shows a flash message after moving a work package that turns invisible", "Inbox"
end

it "moves the work_package to the inbox at the given position" do
subject

Expand All @@ -182,7 +216,7 @@
end

context "with a Backlog Bucket as target" do
let(:bucket) { create(:backlog_bucket, project:) }
let(:bucket) { create(:backlog_bucket, name: "My Bucket", project:) }
let!(:bucket_items) { create_list(:work_package, 2, project:, status:, backlog_bucket: bucket) }
let(:target_id) { "backlog_bucket:#{bucket.id}" }
let(:prev_id) { bucket_items.first.id }
Expand All @@ -198,6 +232,22 @@
target: "backlogs-backlog-component-#{project.id}"
end

context "when the project is configured to exclude the work packages status from backlogs" do
before do
project.done_statuses << status
end

include_examples "shows a flash message after moving a work package that turns invisible", "My Bucket"
end

context "when the project is configured to exclude the work packages type from backlogs" do
before do
project.backlog_excluded_types << type_feature
end

include_examples "shows a flash message after moving a work package that turns invisible", "My Bucket"
end

it "moves the work_package into the bucket at the given position" do
subject

Expand Down
23 changes: 23 additions & 0 deletions modules/backlogs/spec/features/inbox_column_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,29 @@
planning_page.expect_inbox_item(sprint_wp1)
planning_page.expect_inbox_item(sprint_wp2)
end

context "when the sprint item is configured to be excluded from backlogs" do
let!(:status) { create(:status) }
let!(:sprint_wp1) { create(:work_package, project:, sprint:, status:) }

before do
project.done_statuses << status
planning_page.visit!
end

it "hides the work package after move and shows an explanation" do
planning_page.drag_sprint_item_to_inbox(sprint_wp1)
wait_for_network_idle

message =
"The work package was moved to Inbox but is not visible because " \
"its type or status is excluded from the backlog."

planning_page.expect_and_dismiss_flash(message:, type: :default)
planning_page.expect_story_not_in_sprint(sprint_wp1, sprint)
planning_page.expect_no_inbox_item(sprint_wp1)
end
end
end
end

Expand Down
Loading