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

Introduce item_type to MeetingAgendaItem to distinguish between simple and work_package items

Dombi Attila3ccde6f36bf8
diff --git a/db/migrate/20231012124745_add_type_for_meeting_agenda_items.rb b/db/migrate/20231012124745_add_type_for_meeting_agenda_items.rb
new file mode 100644
index 00000000000..f593df81f6a
--- /dev/null
+++ b/db/migrate/20231012124745_add_type_for_meeting_agenda_items.rb
@@ -0,0 +1,5 @@
+class AddTypeForMeetingAgendaItems < ActiveRecord::Migration[7.0]
+ def change
+ add_column :meeting_agenda_items, :item_type, :integer, limit: 1, default: 0
+ end
+end
diff --git a/modules/meeting/app/contracts/meeting_agenda_items/create_contract.rb b/modules/meeting/app/contracts/meeting_agenda_items/create_contract.rb
index dba83d59fba..08601da04d9 100644
--- a/modules/meeting/app/contracts/meeting_agenda_items/create_contract.rb
+++ b/modules/meeting/app/contracts/meeting_agenda_items/create_contract.rb
@@ -28,6 +28,8 @@
module MeetingAgendaItems
class CreateContract < BaseContract
+ attribute :item_type
+
validate :user_allowed_to_add, :validate_meeting_existence
def self.assignable_meetings(user)
diff --git a/modules/meeting/app/controllers/meeting_agenda_items_controller.rb b/modules/meeting/app/controllers/meeting_agenda_items_controller.rb
index 1dd463d09ad..d563726b7a5 100644
--- a/modules/meeting/app/controllers/meeting_agenda_items_controller.rb
+++ b/modules/meeting/app/controllers/meeting_agenda_items_controller.rb
@@ -60,7 +60,12 @@ class MeetingAgendaItemsController < ApplicationController
def create
call = ::MeetingAgendaItems::CreateService
.new(user: current_user)
- .call(meeting_agenda_item_params.merge(meeting_id: @meeting.id))
+ .call(
+ meeting_agenda_item_params.merge(
+ meeting_id: @meeting.id,
+ item_type: @agenda_item_type.presence || MeetingAgendaItem::ITEM_TYPES[:simple]
+ )
+ )
@meeting_agenda_item = call.result
diff --git a/modules/meeting/app/models/meeting_agenda_item.rb b/modules/meeting/app/models/meeting_agenda_item.rb
index c8cd0aa2385..c6667b99430 100644
--- a/modules/meeting/app/models/meeting_agenda_item.rb
+++ b/modules/meeting/app/models/meeting_agenda_item.rb
@@ -28,6 +28,13 @@
#
class MeetingAgendaItem < ApplicationRecord
+ ITEM_TYPES = {
+ simple: 0,
+ work_package: 1
+ }.freeze
+
+ enum item_type: ITEM_TYPES
+
belongs_to :meeting, foreign_key: 'meeting_id', class_name: 'StructuredMeeting'
belongs_to :work_package, class_name: '::WorkPackage'
has_one :project, through: :meeting
diff --git a/modules/meeting/spec/contracts/meeting_agenda_items/create_contract_spec.rb b/modules/meeting/spec/contracts/meeting_agenda_items/create_contract_spec.rb
index c57d29a8506..32c40667d38 100644
--- a/modules/meeting/spec/contracts/meeting_agenda_items/create_contract_spec.rb
+++ b/modules/meeting/spec/contracts/meeting_agenda_items/create_contract_spec.rb
@@ -61,6 +61,14 @@ RSpec.describe MeetingAgendaItems::CreateContract do
it_behaves_like 'contract is invalid', base: :error_unauthorized
end
+
+ context 'when an item_type is provided' do
+ before do
+ allow(item).to receive(:changed).and_return(['item_type'])
+ end
+
+ it_behaves_like 'contract is valid'
+ end
end
context 'without permission' do
diff --git a/modules/meeting/spec/contracts/meeting_agenda_items/update_contract_spec.rb b/modules/meeting/spec/contracts/meeting_agenda_items/update_contract_spec.rb
index 8206014ac45..eb5590f7b51 100644
--- a/modules/meeting/spec/contracts/meeting_agenda_items/update_contract_spec.rb
+++ b/modules/meeting/spec/contracts/meeting_agenda_items/update_contract_spec.rb
@@ -53,6 +53,14 @@ RSpec.describe MeetingAgendaItems::UpdateContract do
it_behaves_like 'contract is invalid', base: I18n.t(:text_meeting_not_editable_anymore)
end
+
+ context 'when an item_type is provided' do
+ before do
+ allow(item).to receive(:changed).and_return(['item_type'])
+ end
+
+ it_behaves_like 'contract is invalid', item_type: :error_readonly
+ end
end
context 'without permission' do
diff --git a/modules/meeting/spec/factories/meeting_agenda_item_factory.rb b/modules/meeting/spec/factories/meeting_agenda_item_factory.rb
index 6e30049ab64..5ffbb9ed416 100644
--- a/modules/meeting/spec/factories/meeting_agenda_item_factory.rb
+++ b/modules/meeting/spec/factories/meeting_agenda_item_factory.rb
@@ -32,6 +32,7 @@ FactoryBot.define do
work_package { nil }
author factory: :user
duration_in_minutes { 10 }
+ item_type { :simple }
m.sequence(:title) { |n| "Agenda item #{n}" }
end
end