# Pull Request Template ## Description This PR adds an endpoint to fetch all attachments shared with or by a contact across all of their conversations. Results are scoped based on the access: * Admins can access all attachments * Agents can access attachments only from inboxes they belong to * Custom role agents are further filtered based on their conversation permissions Each attachment payload includes `conversation_id`, allowing the UI to deep-link back to the source conversation. Added `GET /api/v1/accounts/:account_id/contacts/:contact_id/attachments` under the existing contacts scope. Fixes https://linear.app/chatwoot/issue/CW-7021/add-media-view-to-the-contact-details-page ## Type of change - [x] New feature (non-breaking change which adds functionality) ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Sojan Jose <sojan@pepalo.com>
19 lines
797 B
Ruby
19 lines
797 B
Ruby
class Api::V1::Accounts::Contacts::AttachmentsController < Api::V1::Accounts::Contacts::BaseController
|
|
RESULTS_PER_PAGE = 100
|
|
|
|
def index
|
|
conversations = Conversations::PermissionFilterService.new(
|
|
Current.account.conversations.where(contact_id: @contact.id),
|
|
Current.user,
|
|
Current.account
|
|
).perform
|
|
|
|
@attachments = Attachment.where(message_id: Message.where(conversation_id: conversations).select(:id))
|
|
.includes({ file_attachment: :blob }, message: [:conversation, :inbox, { sender: { avatar_attachment: :blob } }])
|
|
.order(created_at: :desc)
|
|
.page(params[:page])
|
|
.per(RESULTS_PER_PAGE)
|
|
@attachments_count = @attachments.total_count
|
|
end
|
|
end
|