Skip to content

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

Remove agenda items when deleting section

Oliver Günther0fa0dd0900bf
diff --git a/modules/meeting/app/components/meeting_sections/header_component.html.erb b/modules/meeting/app/components/meeting_sections/header_component.html.erb
index d421dc95986..075d01a99b4 100644
--- a/modules/meeting/app/components/meeting_sections/header_component.html.erb
+++ b/modules/meeting/app/components/meeting_sections/header_component.html.erb
@@ -25,18 +25,14 @@
menu.with_show_button(icon: "kebab-horizontal", 'aria-label': t("settings.project_attributes.label_section_actions"), scheme: :invisible)
edit_action_item(menu)
unless first? && last?
- menu.with_divider
+ menu.with_divider
move_actions(menu)
end
menu.with_divider
add_agenda_item_action(menu)
add_work_package_action(menu)
menu.with_divider
- if @meeting_agenda_items.empty?
- delete_action_item(menu)
- else
- disabled_delete_action_item(menu)
- end
+ delete_action_item(menu)
end
end
end
diff --git a/modules/meeting/app/components/meeting_sections/header_component.rb b/modules/meeting/app/components/meeting_sections/header_component.rb
index 151c9a24d01..18f2e1f5336 100644
--- a/modules/meeting/app/components/meeting_sections/header_component.rb
+++ b/modules/meeting/app/components/meeting_sections/header_component.rb
@@ -109,13 +109,6 @@ module MeetingSections
end
end
- def disabled_delete_action_item(menu)
- menu.with_item(label: t("text_destroy"),
- disabled: true) do |item|
- item.with_leading_visual_icon(icon: :trash)
- end
- end
-
def edit_action_item(menu)
menu.with_item(label: t("label_edit"),
href: edit_meeting_section_path(@meeting_section.meeting, @meeting_section),
@@ -156,7 +149,7 @@ module MeetingSections
scheme: :danger,
href: meeting_section_path(@meeting_section.meeting, @meeting_section),
form_arguments: {
- method: :delete, data: { confirm: t("text_are_you_sure"), "turbo-stream": true,
+ method: :delete, data: { confirm: t("meeting_section.delete_confirmation"), "turbo-stream": true,
test_selector: "meeting-section-delete" }
}) do |item|
item.with_leading_visual_icon(icon: :trash)
diff --git a/modules/meeting/app/contracts/meeting_sections/delete_contract.rb b/modules/meeting/app/contracts/meeting_sections/delete_contract.rb
index 02dbb1d4a6e..1cb41b06f24 100644
--- a/modules/meeting/app/contracts/meeting_sections/delete_contract.rb
+++ b/modules/meeting/app/contracts/meeting_sections/delete_contract.rb
@@ -31,13 +31,5 @@ module MeetingSections
include ModifiableItem
delete_permission :manage_agendas
-
- validate :empty_section
-
- def empty_section
- unless model.agenda_items.empty?
- errors.add :base, "Section is not empty and cannot be deleted."
- end
- end
end
end
diff --git a/modules/meeting/config/locales/en.yml b/modules/meeting/config/locales/en.yml
index f5971fb325f..1c16909fa8c 100644
--- a/modules/meeting/config/locales/en.yml
+++ b/modules/meeting/config/locales/en.yml
@@ -143,6 +143,7 @@ en:
copied: "Copied from Meeting #%{id}"
meeting_section:
+ delete_confirmation: "Deleting the section will also delete all of its agenda items. Are you sure you want to do this?"
default_title: "New section"
untitled_title: "Untitled"
empty_text: "Drag items here or create a new one"
diff --git a/modules/meeting/spec/contracts/meeting_sections/delete_contract_spec.rb b/modules/meeting/spec/contracts/meeting_sections/delete_contract_spec.rb
index a589f91c4fb..19f6aea0c1e 100644
--- a/modules/meeting/spec/contracts/meeting_sections/delete_contract_spec.rb
+++ b/modules/meeting/spec/contracts/meeting_sections/delete_contract_spec.rb
@@ -59,7 +59,7 @@ RSpec.describe MeetingSections::DeleteContract do
create(:meeting_agenda_item, meeting_section: section)
end
- it_behaves_like "contract is invalid", base: "Section is not empty and cannot be deleted."
+ it_behaves_like "contract is valid"
end
end
diff --git a/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rb b/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rb
index 71b194955a8..4c47376042b 100644
--- a/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rb
+++ b/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rb
@@ -420,21 +420,17 @@ RSpec.describe "Structured meetings CRUD",
show_page.expect_section_duration(section: second_section, duration_text: "15 min")
# deleting a section with agenda items is not possible
- show_page.select_section_action(second_section, "Delete") # delete is disabled
- ## -> no effect
- show_page.expect_section(title: "Untitled")
- show_page.expect_section(title: "Second section")
-
- show_page.click_on_section_menu(second_section) # close the menu again
+ accept_confirm do
+ show_page.select_section_action(second_section, "Delete") # delete is disabled
+ end
- # deleting a section without agenda items is possible
- show_page.remove_agenda_item(item_in_second_section)
- show_page.remove_section(second_section) # empty secion gets deleted
- # only untitle secion is left -> will not be rendered explicitly as secion
+ # only untitled secion is left -> will not be rendered explicitly as secion
show_page.expect_no_section(title: "Untitled")
show_page.expect_no_section(title: "Second section")
+ expect { item_in_second_section.reload }.to raise_error(ActiveRecord::RecordNotFound)
+
# the agenda items of the "untitled" section are still visible in "no-section mode"
show_page.expect_agenda_item(title: item_in_first_section.title)
end