mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-22 11:48:06 +01:00
Reject status creation with invalid media_ids
parameter (#31681)
This commit is contained in:
parent
40f993b3a0
commit
491033c86c
4 changed files with 16 additions and 6 deletions
|
@ -134,6 +134,9 @@ class PostStatusService < BaseService
|
|||
|
||||
@media = @account.media_attachments.where(status_id: nil).where(id: @options[:media_ids].take(Status::MEDIA_ATTACHMENTS_LIMIT).map(&:to_i))
|
||||
|
||||
not_found_ids = @options[:media_ids] - @media.map(&:id)
|
||||
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.not_found', ids: not_found_ids.join(', ')) if not_found_ids.any?
|
||||
|
||||
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.images_and_video') if @media.size > 1 && @media.find(&:audio_or_video?)
|
||||
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.not_ready') if @media.any?(&:not_processed?)
|
||||
end
|
||||
|
|
|
@ -73,6 +73,9 @@ class UpdateStatusService < BaseService
|
|||
|
||||
media_attachments = @status.account.media_attachments.where(status_id: [nil, @status.id]).where(scheduled_status_id: nil).where(id: @options[:media_ids].take(Status::MEDIA_ATTACHMENTS_LIMIT).map(&:to_i)).to_a
|
||||
|
||||
not_found_ids = @options[:media_ids] - media_attachments.map(&:id)
|
||||
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.not_found', ids: not_found_ids.join(', ')) if not_found_ids.any?
|
||||
|
||||
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.images_and_video') if media_attachments.size > 1 && media_attachments.find(&:audio_or_video?)
|
||||
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.not_ready') if media_attachments.any?(&:not_processed?)
|
||||
|
||||
|
|
|
@ -1454,6 +1454,7 @@ en:
|
|||
media_attachments:
|
||||
validations:
|
||||
images_and_video: Cannot attach a video to a post that already contains images
|
||||
not_found: Media %{ids} not found or already attached to another post
|
||||
not_ready: Cannot attach files that have not finished processing. Try again in a moment!
|
||||
too_many: Cannot attach more than 4 files
|
||||
migrations:
|
||||
|
|
|
@ -229,13 +229,16 @@ RSpec.describe PostStatusService do
|
|||
account = Fabricate(:account)
|
||||
media = Fabricate(:media_attachment, account: Fabricate(:account))
|
||||
|
||||
subject.call(
|
||||
account,
|
||||
text: 'test status update',
|
||||
media_ids: [media.id]
|
||||
expect do
|
||||
subject.call(
|
||||
account,
|
||||
text: 'test status update',
|
||||
media_ids: [media.id]
|
||||
)
|
||||
end.to raise_error(
|
||||
Mastodon::ValidationError,
|
||||
I18n.t('media_attachments.validations.not_found', ids: media.id)
|
||||
)
|
||||
|
||||
expect(media.reload.status).to be_nil
|
||||
end
|
||||
|
||||
it 'does not allow attaching more files than configured limit' do
|
||||
|
|
Loading…
Reference in a new issue