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

Update contracts and error messages

Mir Bhatiaa5dc77f19df8
diff --git a/modules/meeting/app/contracts/meeting_outcomes/base_contract.rb b/modules/meeting/app/contracts/meeting_outcomes/base_contract.rb
index 6f776fb4dcd..1afe4119c83 100644
--- a/modules/meeting/app/contracts/meeting_outcomes/base_contract.rb
+++ b/modules/meeting/app/contracts/meeting_outcomes/base_contract.rb
@@ -30,7 +30,7 @@
module MeetingOutcomes
class BaseContract < ::ModelContract
- include ModifiableItem
+ include EditableItem
def self.model
MeetingOutcome
diff --git a/modules/meeting/app/contracts/meeting_outcomes/create_contract.rb b/modules/meeting/app/contracts/meeting_outcomes/create_contract.rb
index d275c5be6a7..170b17f0a9e 100644
--- a/modules/meeting/app/contracts/meeting_outcomes/create_contract.rb
+++ b/modules/meeting/app/contracts/meeting_outcomes/create_contract.rb
@@ -30,26 +30,5 @@
module MeetingOutcomes
class CreateContract < BaseContract
- validate :user_allowed_to_add, :validate_meeting_existence
-
- def user_allowed_to_add
- return unless visible?
-
- unless user.allowed_in_project?(:create_meeting_minutes, model.meeting_agenda_item.project)
- errors.add :base, :error_unauthorized
- end
- end
-
- def validate_meeting_existence
- return if model.meeting_agenda_item.meeting.nil?
-
- errors.add :base, :does_not_exist unless visible?
- end
-
- private
-
- def visible?
- @visible ||= model.meeting_agenda_item.meeting&.visible?(user)
- end
end
end
diff --git a/modules/meeting/app/contracts/meeting_outcomes/delete_contract.rb b/modules/meeting/app/contracts/meeting_outcomes/delete_contract.rb
index 2e57df6527c..10d8b0a80f6 100644
--- a/modules/meeting/app/contracts/meeting_outcomes/delete_contract.rb
+++ b/modules/meeting/app/contracts/meeting_outcomes/delete_contract.rb
@@ -30,7 +30,7 @@
module MeetingOutcomes
class DeleteContract < ::DeleteContract
- include ModifiableItem
+ include EditableItem
delete_permission -> {
user.allowed_in_project?(:create_meeting_minutes, model.meeting_agenda_item.project)
diff --git a/modules/meeting/app/contracts/meeting_outcomes/modifiable_item.rb b/modules/meeting/app/contracts/meeting_outcomes/editable_item.rb
similarity index 63%
rename from modules/meeting/app/contracts/meeting_outcomes/modifiable_item.rb
rename to modules/meeting/app/contracts/meeting_outcomes/editable_item.rb
index 0d0506368f8..abca63397dd 100644
--- a/modules/meeting/app/contracts/meeting_outcomes/modifiable_item.rb
+++ b/modules/meeting/app/contracts/meeting_outcomes/editable_item.rb
@@ -29,19 +29,39 @@
#++
module MeetingOutcomes
- module ModifiableItem
+ module EditableItem
extend ActiveSupport::Concern
- # included do
- # validate :validate_modifiable
- # end
- #
- # protected
- #
- # def validate_modifiable
- # unless model.modifiable?
- # errors.add :base, I18n.t(:text_agenda_item_not_editable_anymore)
- # end
- # end
+ included do
+ validate :validate_editable, :validate_meeting_existence, :user_allowed_to_add
+ end
+
+ protected
+
+ def validate_editable
+ unless model.editable?
+ errors.add :base, I18n.t(:text_outcome_not_editable_anymore)
+ end
+ end
+
+ def validate_meeting_existence
+ return if model.meeting_agenda_item.meeting.nil?
+
+ unless visible?
+ errors.add :base, :does_not_exist
+ end
+ end
+
+ def user_allowed_to_add
+ unless user.allowed_in_project?(:create_meeting_minutes, model.meeting_agenda_item.project)
+ errors.add :base, :error_unauthorized
+ end
+ end
+
+ private
+
+ def visible?
+ @visible ||= model.meeting_agenda_item.meeting&.visible?(user)
+ end
end
end
diff --git a/modules/meeting/app/contracts/meeting_outcomes/update_contract.rb b/modules/meeting/app/contracts/meeting_outcomes/update_contract.rb
index da3b5e5219c..2e38e3b014c 100644
--- a/modules/meeting/app/contracts/meeting_outcomes/update_contract.rb
+++ b/modules/meeting/app/contracts/meeting_outcomes/update_contract.rb
@@ -30,12 +30,5 @@
module MeetingOutcomes
class UpdateContract < BaseContract
- validate :user_allowed_to_edit
-
- def user_allowed_to_edit
- unless user.allowed_in_project?(:create_meeting_minutes, model.meeting_agenda_item.project)
- errors.add :base, :error_unauthorized
- end
- end
end
end
diff --git a/modules/meeting/app/controllers/meeting_outcomes_controller.rb b/modules/meeting/app/controllers/meeting_outcomes_controller.rb
index f416bbee9ee..1c5ee73a6ca 100644
--- a/modules/meeting/app/controllers/meeting_outcomes_controller.rb
+++ b/modules/meeting/app/controllers/meeting_outcomes_controller.rb
@@ -70,10 +70,8 @@ class MeetingOutcomesController < ApplicationController
render_base_outcome_component_via_turbo_stream(meeting: @meeting, meeting_agenda_item: @meeting_agenda_item,
meeting_outcome: @meeting_outcome, hide_notes: false, state: :show)
else
- # update_new_component_via_turbo_stream(
- # hidden: false, meeting_agenda_item: @meeting_agenda_item, type: @agenda_item_type
- # )
render_base_error_in_flash_message_via_turbo_stream(call.errors)
+ update_all_via_turbo_stream
end
respond_with_turbo_streams
@@ -82,12 +80,11 @@ class MeetingOutcomesController < ApplicationController
def edit
if @meeting_outcome.editable?
@meeting_agenda_item = @meeting_outcome.meeting_agenda_item
- # render_outcome_form_via_turbo_stream(meeting: @meeting, meeting_agenda_item: @meeting_agenda_item)
render_base_outcome_component_via_turbo_stream(meeting: @meeting, meeting_agenda_item: @meeting_agenda_item,
meeting_outcome: @meeting_outcome, hide_notes: false, state: :edit)
- # else
- # update_all_via_turbo_stream
- # render_error_flash_message_via_turbo_stream(message: t("text_meeting_not_editable_anymore"))
+ else
+ render_error_flash_message_via_turbo_stream(message: t("text_meeting_not_editable_anymore"))
+ update_all_via_turbo_stream
end
respond_with_turbo_streams
@@ -113,10 +110,12 @@ class MeetingOutcomesController < ApplicationController
if call.success?
render_base_outcome_component_via_turbo_stream(meeting: @meeting, meeting_agenda_item: @meeting_agenda_item,
meeting_outcome: call.result, hide_notes: false, state: :show)
- update_all_via_turbo_stream
- # else
+ else
+ render_base_error_in_flash_message_via_turbo_stream(call.errors)
end
+ update_all_via_turbo_stream
+
respond_with_turbo_streams
end
@@ -129,10 +128,12 @@ class MeetingOutcomesController < ApplicationController
if call.success?
render_base_outcome_component_via_turbo_stream(meeting: @meeting, meeting_agenda_item: @meeting_agenda_item,
hide_notes: true)
- update_all_via_turbo_stream
- # else
+ else
+ render_base_error_in_flash_message_via_turbo_stream(call.errors)
end
+ update_all_via_turbo_stream
+
respond_with_turbo_streams
end
diff --git a/modules/meeting/app/models/meeting.rb b/modules/meeting/app/models/meeting.rb
index 4039e12dd32..0e20324183f 100644
--- a/modules/meeting/app/models/meeting.rb
+++ b/modules/meeting/app/models/meeting.rb
@@ -129,8 +129,12 @@ class Meeting < ApplicationRecord
parts = Meeting
.unscoped
.where(id:)
- .left_joins(:agenda_items, :sections)
- .pick(MeetingAgendaItem.arel_table[:updated_at].maximum, MeetingSection.arel_table[:updated_at].maximum)
+ .left_joins(:agenda_items, :sections, agenda_items: :outcomes)
+ .pick(
+ MeetingAgendaItem.arel_table[:updated_at].maximum,
+ MeetingSection.arel_table[:updated_at].maximum,
+ MeetingOutcome.arel_table[:updated_at].maximum
+ )
parts << lock_version
diff --git a/modules/meeting/app/models/meeting_outcome.rb b/modules/meeting/app/models/meeting_outcome.rb
index 2ac1e084b2e..dfb7f24ceb0 100644
--- a/modules/meeting/app/models/meeting_outcome.rb
+++ b/modules/meeting/app/models/meeting_outcome.rb
@@ -41,14 +41,6 @@ class MeetingOutcome < ApplicationRecord
validates_presence_of :notes, if: -> { information_kind? }
validates_presence_of :work_package, if: -> { work_package_kind? }
- # validate :unique_kind
-
- # def unique_kind
- # if meeting_agenda_item.outcomes.exists?(kind: kind)
- # errors.add(:kind, "has already been taken for this MeetingAgenda")
- # end
- # end
-
def editable?
meeting_agenda_item.meeting&.in_progress?
end