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

Display deleted title for MeetingAgendaItems with a deleted work package

Dombi Attila56c2635c32db
diff --git a/.rubocop.yml b/.rubocop.yml
index 366374bd155..2e049139c5d 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -203,6 +203,11 @@ Rails/DynamicFindBy:
- 'spec/support/**/*.rb'
- 'modules/*/spec/features/**/*.rb'
+# We have config.active_record.belongs_to_required_by_default = false ,
+# which means, we do have to declare presence validators on belongs_to relations.
+Rails/RedundantPresenceValidationOnBelongsTo:
+ Enabled: false
+
# See RSpec/ExampleLength for why feature specs are excluded
RSpec/MultipleExpectations:
Max: 15
diff --git a/db/migrate/20231012124745_add_item_type_to_meeting_agenda_items.rb b/db/migrate/20231012124745_add_item_type_to_meeting_agenda_items.rb
index dac26a0ad63..7ccdbdd6e8a 100644
--- a/db/migrate/20231012124745_add_item_type_to_meeting_agenda_items.rb
+++ b/db/migrate/20231012124745_add_item_type_to_meeting_agenda_items.rb
@@ -1,5 +1,10 @@
class AddItemTypeToMeetingAgendaItems < ActiveRecord::Migration[7.0]
def change
add_column :meeting_agenda_items, :item_type, :integer, limit: 1, default: 0
+
+ MeetingAgendaItem
+ .where.not(work_package_id: nil)
+ .or(MeetingAgendaItem.where(title: nil))
+ .update_all(item_type: :work_package)
end
end
diff --git a/db/migrate/20231013114720_add_item_type_to_meeting_agenda_item_journal.rb b/db/migrate/20231013114720_add_item_type_to_meeting_agenda_item_journal.rb
index 27a6338e23d..a55d1517a5f 100644
--- a/db/migrate/20231013114720_add_item_type_to_meeting_agenda_item_journal.rb
+++ b/db/migrate/20231013114720_add_item_type_to_meeting_agenda_item_journal.rb
@@ -1,5 +1,14 @@
class AddItemTypeToMeetingAgendaItemJournal < ActiveRecord::Migration[7.0]
def change
add_column :meeting_agenda_item_journals, :item_type, :integer, limit: 1
+
+ Journal::MeetingAgendaItemJournal
+ .where.not(work_package_id: nil)
+ .or(Journal::MeetingAgendaItemJournal.where(title: nil))
+ .update_all(item_type: :work_package)
+
+ Journal::MeetingAgendaItemJournal
+ .where(item_type: nil)
+ .update_all(item_type: :simple)
end
end
diff --git a/modules/meeting/app/components/meeting_agenda_items/item_component/show_component.html.erb b/modules/meeting/app/components/meeting_agenda_items/item_component/show_component.html.erb
index a77948d5fc7..a8d99a5baa6 100644
--- a/modules/meeting/app/components/meeting_agenda_items/item_component/show_component.html.erb
+++ b/modules/meeting/app/components/meeting_agenda_items/item_component/show_component.html.erb
@@ -32,6 +32,10 @@
render(Primer::Beta::Text.new(font_size: :small, mr: 2, color: :subtle)) do
I18n.t(:label_agenda_item_undisclosed_wp, id: @meeting_agenda_item.work_package_id)
end
+ elsif @meeting_agenda_item.deleted_work_package?
+ render(Primer::Beta::Text.new(tag: :s, font_size: :small, mr: 2, color: :danger)) do
+ I18n.t(:label_agenda_item_deleted_wp)
+ end
else
render(Primer::Beta::Text.new(font_size: :normal, mr: 2, font_weight: :bold, test_selector: 'op-meeting-agenda-title')) do
@meeting_agenda_item.title
@@ -63,7 +67,7 @@
grid.with_area(:actions, tag: :div, justify_self: :end) do
render(Primer::Alpha::ActionMenu.new) do |menu|
menu.with_show_button(icon: "kebab-horizontal", 'aria-label': t("label_agenda_item_actions"), scheme: :invisible, test_selector: 'op-meeting-agenda-actions')
- edit_action_item(menu)
+ edit_action_item(menu) unless @meeting_agenda_item.deleted_work_package?
move_actions(menu)
delete_action_item(menu)
end if edit_enabled?
diff --git a/modules/meeting/app/models/meeting_agenda_item.rb b/modules/meeting/app/models/meeting_agenda_item.rb
index c6667b99430..6bb1c353d92 100644
--- a/modules/meeting/app/models/meeting_agenda_item.rb
+++ b/modules/meeting/app/models/meeting_agenda_item.rb
@@ -44,8 +44,8 @@ class MeetingAgendaItem < ApplicationRecord
default_scope { order(:position) }
validates :meeting_id, presence: true
- validates :title, presence: true, if: Proc.new { |item| item.work_package_id.blank? }
- validates :work_package_id, presence: true, if: Proc.new { |item| item.title.blank? }
+ validates :title, presence: true, if: Proc.new { |item| item.simple? }
+ validates :work_package_id, presence: true, if: Proc.new { |item| item.work_package? }, on: :create
validates :duration_in_minutes,
numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1440 },
@@ -62,13 +62,17 @@ class MeetingAgendaItem < ApplicationRecord
end
def linked_work_package?
- work_package.present?
+ item_type == "work_package" && work_package.present?
end
def visible_work_package?
linked_work_package? && work_package.visible?(User.current)
end
+ def deleted_work_package?
+ item_type == "work_package" && work_package_id.nil?
+ end
+
def editable?
!meeting&.closed?
end
diff --git a/modules/meeting/config/locales/en.yml b/modules/meeting/config/locales/en.yml
index f7b906dc438..833f6815980 100644
--- a/modules/meeting/config/locales/en.yml
+++ b/modules/meeting/config/locales/en.yml
@@ -156,6 +156,7 @@ en:
label_meeting_last_updated: "Last updated"
label_agenda_item_undisclosed_wp: "Undisclosed work package reference #%{id}"
+ label_agenda_item_deleted_wp: "Deleted work package reference"
label_agenda_item_actions: "Agenda items actions"
label_agenda_item_move_to_top: "Move to top"
label_agenda_item_move_to_bottom: "Move to bottom"
diff --git a/modules/meeting/spec/models/meeting_agenda_item_spec.rb b/modules/meeting/spec/models/meeting_agenda_item_spec.rb
index 9141564078a..db022b8926d 100644
--- a/modules/meeting/spec/models/meeting_agenda_item_spec.rb
+++ b/modules/meeting/spec/models/meeting_agenda_item_spec.rb
@@ -30,6 +30,7 @@ require_relative "../spec_helper"
RSpec.describe MeetingAgendaItem do
let(:meeting) { build_stubbed(:structured_meeting) }
+ let(:attributes) { {} }
subject { described_class.new(meeting:, **attributes) }
@@ -100,4 +101,110 @@ RSpec.describe MeetingAgendaItem do
end
end
end
+
+ describe '#title' do
+ let(:attributes) { { title:, item_type:, author: build_stubbed(:user), work_package_id: 1 } }
+
+ context 'when item_type is simple' do
+ let(:item_type) { :simple }
+
+ context 'and title is missing' do
+ let(:title) { nil }
+
+ it { is_expected.not_to be_valid }
+ end
+
+ context 'and title is present' do
+ let(:title) { 'title' }
+
+ it { is_expected.to be_valid }
+ end
+ end
+
+ context 'when item_type is work_package and title is missing' do
+ let(:item_type) { :work_package }
+ let(:title) { nil }
+
+ it { is_expected.to be_valid }
+ end
+ end
+
+ describe '#work_package_id' do
+ let(:attributes) { { work_package_id:, item_type:, author: build_stubbed(:user), title: 'title' } }
+
+ context 'on create' do
+ context 'when item_type is simple' do
+ let(:item_type) { :simple }
+
+ context 'and work_package_id is missing' do
+ let(:work_package_id) { nil }
+
+ it { is_expected.to be_valid }
+ end
+
+ context 'and work_package_id is present' do
+ let(:work_package_id) { 1 }
+
+ it { is_expected.to be_valid }
+ end
+ end
+
+ context 'when item_type is work_package' do
+ let(:item_type) { :work_package }
+
+ context 'and work_package_id is missing' do
+ let(:work_package_id) { nil }
+
+ it { is_expected.not_to be_valid }
+ end
+
+ context 'and work_package_id is present' do
+ let(:work_package_id) { 1 }
+
+ it { is_expected.to be_valid }
+ end
+ end
+ end
+
+ context 'on update' do
+ let(:meeting_agenda_item) { create(:meeting_agenda_item) }
+
+ subject do
+ meeting_agenda_item.assign_attributes(attributes)
+ meeting_agenda_item
+ end
+
+ context 'when item_type is simple' do
+ let(:item_type) { :simple }
+
+ context 'and work_package_id is missing' do
+ let(:work_package_id) { nil }
+
+ it { is_expected.to be_valid }
+ end
+
+ context 'and work_package_id is present' do
+ let(:work_package_id) { 1 }
+
+ it { is_expected.to be_valid }
+ end
+ end
+
+ context 'when item_type is work_package' do
+ let(:item_type) { :work_package }
+
+ context 'and work_package_id is missing' do
+ let(:work_package_id) { nil }
+
+ it { is_expected.to be_valid }
+ end
+
+ context 'and work_package_id is present' do
+ let(:work_package_id) { 1 }
+
+ it { is_expected.to be_valid }
+ end
+ end
+ end
+ end
end