Skip to content

Commit b12fd3b

Browse files
committed
[#73389] Align sprint menu permissions
Align sprint menu permissions with controller mutability rules. This hides sprint mutation actions when a sprint is only visible through work package references so the UI no longer advertises operations the controllers will reject. https://community.openproject.org/wp/73389
1 parent 852206c commit b12fd3b

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ See COPYRIGHT and LICENSE files for more details.
6666
end
6767
end
6868

69-
if user_allowed?(:create_sprints)
69+
if show_edit_sprint_action?
7070
menu.with_item(
7171
id: dom_target(sprint, :menu, :edit_sprint),
7272
label: t(".action_menu.edit_sprint"),

modules/backlogs/app/components/backlogs/sprint_menu_component.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,19 @@ def show_task_board_link?
6262
end
6363

6464
def show_start_sprint_action?
65-
sprint.in_planning? && ::Sprints::StartContract.can_start?(user: current_user, sprint:, project:)
65+
mutable_sprint_in_project? &&
66+
sprint.in_planning? &&
67+
::Sprints::StartContract.can_start?(user: current_user, sprint:, project:)
6668
end
6769

6870
def show_finish_sprint_action?
69-
sprint.active? && ::Sprints::StartContract.can_start_or_finish?(user: current_user, sprint:)
71+
mutable_sprint_in_project? &&
72+
sprint.active? &&
73+
::Sprints::StartContract.can_start_or_finish?(user: current_user, sprint:)
74+
end
75+
76+
def show_edit_sprint_action?
77+
mutable_sprint_in_project? && user_allowed?(:create_sprints)
7078
end
7179

7280
def disable_start_sprint_action?
@@ -94,5 +102,9 @@ def project_has_another_active_sprint?
94102
def resolved_active_sprint_ids
95103
active_sprint_ids || Agile::Sprint.for_project(sprint.project).active.pluck(:id)
96104
end
105+
106+
def mutable_sprint_in_project?
107+
project.sprint_source.exists?(id: sprint.project_id)
108+
end
97109
end
98110
end

modules/backlogs/spec/components/backlogs/sprint_menu_component_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,5 +275,37 @@ def menu_items
275275
end
276276
end
277277
end
278+
279+
context "when the sprint is only visible through work package references" do
280+
let(:source_project) { create(:project, types: [type_feature, type_task]) }
281+
let(:project) { create(:project, types: [type_feature, type_task]) }
282+
let(:sprint) do
283+
create(:agile_sprint,
284+
project: source_project,
285+
name: "Referenced Sprint",
286+
start_date: Date.yesterday,
287+
finish_date: Date.tomorrow,
288+
status: "active")
289+
end
290+
let(:permissions) do
291+
%i[view_sprints view_work_packages show_board_views create_sprints manage_sprint_items start_complete_sprint]
292+
end
293+
294+
before do
295+
create(:member,
296+
project: source_project,
297+
principal: user,
298+
roles: [create(:project_role, permissions: %i[view_sprints create_sprints start_complete_sprint])])
299+
create(:work_package, project:, type: type_feature, sprint:)
300+
end
301+
302+
it "hides mutation actions" do
303+
render_component
304+
305+
expect(page).to have_no_selector(:menuitem, text: "Start sprint")
306+
expect(page).to have_no_selector(:menuitem, text: "Finish sprint")
307+
expect(page).to have_no_selector(:menuitem, text: "Edit sprint")
308+
end
309+
end
278310
end
279311
end

0 commit comments

Comments
 (0)