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

Prevent posting toots with media attachments from someone else #9921

Merged
merged 1 commit into from
Jan 26, 2019
Merged
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
2 changes: 1 addition & 1 deletion app/services/post_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def validate_media!

raise Mastodon::ValidationError, I18n.t('media_attachments.validations.too_many') if @options[:media_ids].size > 4

@media = MediaAttachment.where(status_id: nil).where(id: @options[:media_ids].take(4).map(&:to_i))
@media = @account.media_attachments.where(status_id: nil).where(id: @options[:media_ids].take(4).map(&:to_i))

raise Mastodon::ValidationError, I18n.t('media_attachments.validations.images_and_video') if @media.size > 1 && @media.find(&:video?)
end
Expand Down
15 changes: 14 additions & 1 deletion spec/services/post_status_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@

it 'attaches the given media to the created status' do
account = Fabricate(:account)
media = Fabricate(:media_attachment)
media = Fabricate(:media_attachment, account: account)

status = subject.call(
account,
Expand All @@ -178,6 +178,19 @@
expect(media.reload.status).to eq status
end

it 'does not attach media from another account to the created status' do
account = Fabricate(:account)
media = Fabricate(:media_attachment, account: Fabricate(:account))

status = subject.call(
account,
text: "test status update",
media_ids: [media.id],
)

expect(media.reload.status).to eq nil
end

it 'does not allow attaching more than 4 files' do
account = Fabricate(:account)

Expand Down