Skip to content

Commit

Permalink
rename recipients_ids to maybe fix the problem
Browse files Browse the repository at this point in the history
  • Loading branch information
mortbauer committed Dec 23, 2024
1 parent fc95ffa commit a3c0324
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions plugins/messages/app/controllers/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def create
ActiveRecord::Base.transaction do
@current_user.with_lock do
@message = @current_user.send_messages.new(params[:message])
Rails.logger.info "Message column names: #{@message.class.column_names.inspect}"
if @message.save
DeliverMessageJob.perform_later(@message)
redirect_to messages_url, notice: I18n.t('messages.create.notice')
Expand Down
22 changes: 11 additions & 11 deletions plugins/messages/app/models/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Message < ApplicationRecord
has_many :message_recipients, dependent: :destroy
has_many :recipients, through: :message_recipients, source: :user

attr_accessor :send_method, :recipient_tokens, :order_id, :recipients_ids
attr_accessor :send_method, :recipient_tokens, :order_id, :mrecipients_ids

scope :threads, -> { where(reply_to: nil) }
scope :thread, ->(id) { where('id = ? OR reply_to = ?', id, id) }
Expand All @@ -30,7 +30,7 @@ class Message < ApplicationRecord
validates_length_of :subject, in: 1..255

after_initialize do
@recipients_ids ||= []
@mrecipients_ids ||= []
@send_method ||= 'recipients'
end

Expand All @@ -39,7 +39,7 @@ class Message < ApplicationRecord

has_rich_text :body

# Override the `attributes=` method to exclude `recipients_ids`
# Override the `attributes=` method to exclude `mrecipients_ids`
def attributes=(new_attributes)
if new_attributes.respond_to?(:with_indifferent_access)
new_attributes = new_attributes.with_indifferent_access
Expand All @@ -48,21 +48,21 @@ def attributes=(new_attributes)
# Log the attributes for debugging purposes
Rails.logger.debug "Original attributes: #{new_attributes.inspect}"

# Remove `recipients_ids` from the attributes hash
new_attributes = new_attributes.except(:recipients_ids, 'recipients_ids')
# Remove `mrecipients_ids` from the attributes hash
new_attributes = new_attributes.except(:mrecipients_ids, 'mrecipients_ids')

# Log the sanitized attributes for debugging purposes
Rails.logger.debug "Sanitized attributes: #{new_attributes.inspect}"

super(new_attributes)
end

def recipients_ids=(value)
@recipients_ids = value
def mrecipients_ids=(value)
@mrecipients_ids = value
end

def add_recipients(users)
@recipients_ids += users
@mrecipients_ids += users
end

def group_id=(group_id)
Expand Down Expand Up @@ -106,11 +106,11 @@ def order_id=(order_id)

def recipient_tokens=(ids)
@recipient_tokens = ids
@recipients_ids = ids.split(',').map(&:to_i)
@mrecipients_ids = ids.split(',').map(&:to_i)
end

def mail_to=(user_id)
@recipients_ids = [user_id]
@mrecipients_ids = [user_id]
end

def mail_hash_for_user(user)
Expand Down Expand Up @@ -152,7 +152,7 @@ def can_toggle_private?(user)
private

def create_message_recipients
user_ids = @recipients_ids
user_ids = @mrecipients_ids
user_ids += User.undeleted.pluck(:id) if send_method == 'all'
user_ids += Group.find(group_id).users.pluck(:id) if group_id.present?
user_ids += Order.find(order_id).users_ordered.pluck(:id) if send_method == 'order'
Expand Down
2 changes: 1 addition & 1 deletion plugins/messages/app/views/messages/new.haml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
= f.input :order_id, :as => :select, include_blank: false, :collection => Order.finished_not_closed.order('pickup DESC').includes(:supplier).limit(25),
:label_method => ->(obj){ t('.order_item', supplier_name: obj.name, pickup: format_date(obj.pickup)) }, :input_html => {class: 'input-xxlarge'}
#recipients
= f.input :recipient_tokens, :input_html => { 'data-pre' => User.where(id: @message.recipients_ids).map(&:token_attributes).to_json }
= f.input :recipient_tokens, :input_html => { 'data-pre' => User.where(id: @message.mrecipients_ids).map(&:token_attributes).to_json }
= f.input :private, inline_label: t('.hint_private')
= f.input :subject, input_html: {class: 'input-xxlarge'}
= f.rich_text_area :body, input_html: {class: 'input-xxlarge', rows: 13}
Expand Down

0 comments on commit a3c0324

Please sign in to comment.