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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
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.rbindex 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 MeetingOutcomesclass BaseContract < ::ModelContract- include ModifiableItem+ include EditableItemdef self.modelMeetingOutcomediff --git a/modules/meeting/app/contracts/meeting_outcomes/create_contract.rb b/modules/meeting/app/contracts/meeting_outcomes/create_contract.rbindex 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 MeetingOutcomesclass 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)- endendenddiff --git a/modules/meeting/app/contracts/meeting_outcomes/delete_contract.rb b/modules/meeting/app/contracts/meeting_outcomes/delete_contract.rbindex 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 MeetingOutcomesclass DeleteContract < ::DeleteContract- include ModifiableItem+ include EditableItemdelete_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.rbsimilarity index 63%rename from modules/meeting/app/contracts/meeting_outcomes/modifiable_item.rbrename to modules/meeting/app/contracts/meeting_outcomes/editable_item.rbindex 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 EditableItemextend 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)+ endendenddiff --git a/modules/meeting/app/contracts/meeting_outcomes/update_contract.rb b/modules/meeting/app/contracts/meeting_outcomes/update_contract.rbindex 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 MeetingOutcomesclass 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- endendenddiff --git a/modules/meeting/app/controllers/meeting_outcomes_controller.rb b/modules/meeting/app/controllers/meeting_outcomes_controller.rbindex 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 < ApplicationControllerrender_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_streamendrespond_with_turbo_streams@@ -82,12 +80,11 @@ class MeetingOutcomesController < ApplicationControllerdef editif @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_streamendrespond_with_turbo_streams@@ -113,10 +110,12 @@ class MeetingOutcomesController < ApplicationControllerif 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_streamsend@@ -129,10 +128,12 @@ class MeetingOutcomesController < ApplicationControllerif 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_streamsenddiff --git a/modules/meeting/app/models/meeting.rb b/modules/meeting/app/models/meeting.rbindex 4039e12dd32..0e20324183f 100644--- a/modules/meeting/app/models/meeting.rb+++ b/modules/meeting/app/models/meeting.rb@@ -129,8 +129,12 @@ class Meeting < ApplicationRecordparts = 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_versiondiff --git a/modules/meeting/app/models/meeting_outcome.rb b/modules/meeting/app/models/meeting_outcome.rbindex 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 < ApplicationRecordvalidates_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