Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify model to take multiple attachements #7100

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/controllers/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create
def download_attachment
raise 'No attachment present on this message' unless message.attachment.attached?

redirect_to message.attachment.blob.url(disposition: 'attachment'), allow_other_host: true
redirect_to message.attachment.first.blob.url(disposition: 'attachment'), allow_other_host: true
end

private
Expand All @@ -59,10 +59,10 @@ def message_params
params.require(:message).permit(
:sender_id,
:claim_id,
:attachment,
:body,
:claim_action,
:written_reasons_submitted
:written_reasons_submitted,
attachment: []
)
end
end
8 changes: 4 additions & 4 deletions app/interfaces/api/entities/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ class Document < BaseEntity
private

def attachment
object.is_a?(ActiveStorage::Attachment) ? object : object.attachment
object.is_a?(ActiveStorage::Attachment) ? object : object.attachment.first
end

def url
attachment.blob.url(disposition: 'attachment') if attachment.attached?
attachment.first.blob.url(disposition: 'attachment') if attachment.first.attached?
end

def file_name
attachment.filename if attachment.attached?
attachment.first.filename if attachment.first.attached?
end

def size
attachment.byte_size if attachment.attached?
attachment.first.byte_size if attachment.first.attached?
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Message < ApplicationRecord

attr_accessor :claim_action, :written_reasons_submitted

has_one_attached :attachment
has_many_attached :attachment

validates :attachment,
size: { less_than: 20.megabytes },
Expand Down Expand Up @@ -51,7 +51,7 @@ class Message < ApplicationRecord
scope :most_recent_last, -> { includes(:user_message_statuses).order(created_at: :asc) }

after_create :generate_statuses, :process_claim_action, :process_written_reasons, :send_email_if_required
before_destroy -> { attachment.purge }
before_destroy -> { attachment.each(&:purge) }

class << self
def for(object)
Expand Down
6 changes: 3 additions & 3 deletions app/presenters/message_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def sender_is_a?(klass)
def body
h.tag.div do
h.concat(simple_format(message.body))
attachment_field if message.attachment.present?
attachment_field if message.attachment.first.present?
end
end

Expand Down Expand Up @@ -39,11 +39,11 @@ def download_file_link
end

def attachment_file_name
message.attachment.filename.to_s
message.attachment.first.filename.to_s
end

def attachment_file_size
h.number_to_human_size(message.attachment.byte_size)
h.number_to_human_size(message.attachment.first.byte_size)
end

def hide_author?
Expand Down
Loading