diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 09407ebce..b0c9cfa0b 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -42,6 +42,8 @@ def set_commentable @commentable = Organization.find(params[:organization_id]) elsif params[:event_registration_id] @commentable = EventRegistration.find(params[:event_registration_id]) + elsif params[:workshop_id] + @commentable = Workshop.find(params[:workshop_id]) else redirect_to root_path, alert: "Invalid commentable resource" end diff --git a/app/controllers/event_registrations_controller.rb b/app/controllers/event_registrations_controller.rb index 144178bd7..28bce31eb 100644 --- a/app/controllers/event_registrations_controller.rb +++ b/app/controllers/event_registrations_controller.rb @@ -75,7 +75,7 @@ def update authorize! @event_registration @event_registration.assign_attributes(event_registration_update_params) @event_registration.comments.select(&:new_record?).each { |c| c.created_by = current_user; c.updated_by = current_user } - @event_registration.comments.select(&:changed?).each { |c| c.updated_by = current_user } + @event_registration.comments.select { |c| c.persisted? && c.body_changed? }.each { |c| c.updated_by = current_user } if @event_registration.save respond_to do |format| diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 7ed3c28b8..8b4af466c 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -100,7 +100,7 @@ def update authorize! @organization @organization.assign_attributes(organization_params) @organization.comments.select(&:new_record?).each { |c| c.created_by = current_user; c.updated_by = current_user } - @organization.comments.select(&:changed?).each { |c| c.updated_by = current_user } + @organization.comments.select { |c| c.persisted? && c.body_changed? }.each { |c| c.updated_by = current_user } if @organization.save assign_associations(@organization) if params.dig(:organization, :category_ids) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index b8d7128bd..629f36773 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -134,7 +134,7 @@ def update @person.assign_attributes(person_params) @person.comments.select(&:new_record?).each { |c| c.created_by = current_user; c.updated_by = current_user } - @person.comments.select(&:changed?).each { |c| c.updated_by = current_user } + @person.comments.select { |c| c.persisted? && c.body_changed? }.each { |c| c.updated_by = current_user } if @person.save assign_associations(@person) if params.dig(:person, :category_ids) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 966402b7f..d5b1093e1 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -126,7 +126,7 @@ def update @user.assign_attributes(user_params.except(:password, :password_confirmation)) @user.updated_by = current_user @user.comments.select(&:new_record?).each { |c| c.created_by = current_user; c.updated_by = current_user } - @user.comments.select(&:changed?).each { |c| c.updated_by = current_user } + @user.comments.select { |c| c.persisted? && c.body_changed? }.each { |c| c.updated_by = current_user } # Suppress Devise's automatic reconfirmation email so the interstitial can control it @user.skip_confirmation_notification! diff --git a/app/controllers/workshops_controller.rb b/app/controllers/workshops_controller.rb index 03ac9f226..13c86bde0 100644 --- a/app/controllers/workshops_controller.rb +++ b/app/controllers/workshops_controller.rb @@ -153,8 +153,12 @@ def update authorize! @workshop success = false + @workshop.assign_attributes(workshop_params) + @workshop.comments.select(&:new_record?).each { |c| c.created_by = current_user; c.updated_by = current_user } + @workshop.comments.select { |c| c.persisted? && c.body_changed? }.each { |c| c.updated_by = current_user } + Workshop.transaction do - if @workshop.update(workshop_params) + if @workshop.save assign_associations(@workshop) success = true end @@ -288,7 +292,8 @@ def workshop_params gallery_assets_attributes: [ :id, :file, :_destroy ], workshop_series_children_attributes: [ :id, :workshop_child_id, :workshop_parent_id, :theme_name, :series_description, :series_description_spanish, - :position, :_destroy ] + :position, :_destroy ], + comments_attributes: [ :id, :body ] ) end end diff --git a/app/models/workshop.rb b/app/models/workshop.rb index 86a2f645d..7f86b1cba 100644 --- a/app/models/workshop.rb +++ b/app/models/workshop.rb @@ -28,6 +28,7 @@ def self.mentionable_rich_text_fields belongs_to :workshop_idea, optional: true has_many :bookmarks, as: :bookmarkable, dependent: :destroy + has_many :comments, -> { newest_first }, as: :commentable, dependent: :destroy has_many :categorizable_items, dependent: :destroy, inverse_of: :categorizable, as: :categorizable has_many :quotable_item_quotes, as: :quotable, dependent: :destroy has_many :associated_resources, class_name: "Resource", foreign_key: "workshop_id", dependent: :restrict_with_error @@ -135,6 +136,7 @@ def self.mentionable_rich_text_fields reject_if: proc { |attributes| attributes["workshop_child_id"].blank? }, allow_destroy: true accepts_nested_attributes_for :workshop_variations, reject_if: proc { |object| object.nil? } + accepts_nested_attributes_for :comments, reject_if: proc { |attrs| attrs["body"].blank? } # Scopes diff --git a/app/views/comments/_comment_fields.html.erb b/app/views/comments/_comment_fields.html.erb index fbf81b8b3..423bf07b5 100644 --- a/app/views/comments/_comment_fields.html.erb +++ b/app/views/comments/_comment_fields.html.erb @@ -30,6 +30,7 @@ <% updated_color = show_updated ? label_colors[(updated_user.id || 0) % label_colors.length] : nil %> <% current_color = label_colors[(current_user&.id || 0) % label_colors.length] %>