Skip to content

Commit 2176534

Browse files
committed
get reordering via menu to work
1 parent 226af7e commit 2176534

File tree

5 files changed

+25
-26
lines changed

5 files changed

+25
-26
lines changed

modules/backlogs/app/components/backlogs/story_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ See COPYRIGHT and LICENSE files for more details.
5151
<% end %>
5252

5353
<% grid.with_area(:menu) do %>
54-
<%= render(Backlogs::StoryMenuComponent.new(story:, sprint:, max_position:)) %>
54+
<%= render(Backlogs::StoryMenuComponent.new(story:, sprint:, project:, max_position:)) %>
5555
<% end %>
5656

5757
<% grid.with_area(:subject) do %>

modules/backlogs/app/components/backlogs/story_menu_component.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ module Backlogs
3232
class StoryMenuComponent < ApplicationComponent
3333
attr_reader :story, :sprint, :project, :max_position, :current_user
3434

35-
def initialize(story:, sprint:, max_position:, current_user: User.current, **system_arguments)
35+
def initialize(story:, sprint:, project:, max_position:, current_user: User.current, **system_arguments)
3636
super()
3737

3838
@story = story
3939
@sprint = sprint
40-
@project = sprint.project
40+
@project = project
4141
@max_position = max_position
4242
@current_user = current_user
4343

modules/backlogs/app/controllers/rb_application_controller.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,24 @@ class RbApplicationController < ApplicationController
4343
def load_sprint_and_project
4444
load_project
4545

46-
# because of strong params, we want to pluck this variable out right now,
47-
# otherwise it causes issues where we are doing `attributes=`.
48-
if (@sprint_id = params.delete(:sprint_id))
49-
@sprint = Sprint.visible.apply_to(@project).find(@sprint_id)
50-
end
46+
load_sprint
5147
end
5248

5349
def load_project
5450
@project = Project.visible.find(params[:project_id])
5551
end
5652

53+
def load_sprint
54+
@sprint_id = params.delete(:sprint_id)
55+
return unless @sprint_id
56+
57+
@sprint = if OpenProject::FeatureDecisions.scrum_projects_active?
58+
Agile::Sprint.for_project(@project).visible.find(@sprint_id)
59+
else
60+
Sprint.visible.apply_to(@project).find(@sprint_id)
61+
end
62+
end
63+
5764
def check_if_plugin_is_configured
5865
return if OpenProject::FeatureDecisions.scrum_projects_active?
5966

modules/backlogs/app/controllers/rb_stories_controller.rb

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@
3131
class RbStoriesController < RbApplicationController
3232
include OpTurbo::ComponentStream
3333

34-
NEW_SPRINT_ACTIONS = %i[move].freeze
35-
36-
skip_before_action :load_sprint_and_project, :authorize, only: NEW_SPRINT_ACTIONS
37-
38-
before_action :legacy_load_story, except: NEW_SPRINT_ACTIONS
39-
before_action :load_project, :authorize, :load_sprint, :load_story, only: NEW_SPRINT_ACTIONS
34+
before_action :load_story
4035

4136
# Move a story from a Sprint to another Sprint or an Agile::Sprint.
4237
def move_legacy
@@ -90,7 +85,7 @@ def reorder
9085
return respond_with_turbo_streams(status: :unprocessable_entity)
9186
end
9287

93-
replace_backlog_component_via_turbo_stream(sprint: @sprint)
88+
replace_typed_component_via_turbo_stream(sprint: @sprint)
9489

9590
respond_with_turbo_streams
9691
end
@@ -184,19 +179,16 @@ def replace_backlog_component_via_turbo_stream(sprint:)
184179
end
185180

186181
def replace_sprint_component_via_turbo_stream(sprint:)
187-
replace_via_turbo_stream(component: Backlogs::SprintComponent.new(sprint: sprint, project: @project))
188-
end
189-
190-
def legacy_load_story
191-
@story = Story.visible.find(params[:id])
182+
replace_via_turbo_stream(component: Backlogs::SprintComponent.new(sprint: sprint, project: @project),
183+
method: :morph)
192184
end
193185

194186
def load_story
195-
@story = WorkPackage.visible.find(params[:id])
196-
end
197-
198-
def load_sprint
199-
@sprint = Agile::Sprint.for_project(@project).visible.find(params[:sprint_id])
187+
@story = if OpenProject::FeatureDecisions.scrum_projects_active?
188+
WorkPackage.visible.find(params[:id])
189+
else
190+
Story.visible.find(params[:id])
191+
end
200192
end
201193

202194
def move_params

modules/backlogs/spec/controllers/rb_stories_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@
221221
end
222222
end
223223

224-
describe "PUT #move" do
224+
describe "PUT #move", with_flag: { scrum_projects: true } do
225225
let(:agile_sprint) { create(:agile_sprint, name: "Agile Sprint 1", project:) }
226226
let(:story_in_agile_sprint) { create(:work_package, status:, sprint: agile_sprint, project:) }
227227

0 commit comments

Comments
 (0)