Add ng words for post/update
This commit is contained in:
parent
d4602118fb
commit
c553275381
12 changed files with 110 additions and 2 deletions
|
@ -18,7 +18,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
|
|||
@request_id = request_id
|
||||
|
||||
# Only native types can be updated at the moment
|
||||
return @status if !expected_type? || already_updated_more_recently?
|
||||
return @status if !expected_type? || already_updated_more_recently? || !valid_status?
|
||||
|
||||
if @status_parser.edited_at.present? && (@status.edited_at.nil? || @status_parser.edited_at > @status.edited_at)
|
||||
handle_explicit_update!
|
||||
|
@ -152,6 +152,10 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
|
|||
end
|
||||
end
|
||||
|
||||
def valid_status?
|
||||
!Admin::NgWord.reject?("#{@status_parser.spoiler_text}\n#{@status_parser.text}")
|
||||
end
|
||||
|
||||
def update_immediate_attributes!
|
||||
@status.text = @status_parser.text || ''
|
||||
@status.spoiler_text = @status_parser.spoiler_text || ''
|
||||
|
|
|
@ -44,6 +44,7 @@ class PostStatusService < BaseService
|
|||
|
||||
return idempotency_duplicate if idempotency_given? && idempotency_duplicate?
|
||||
|
||||
validate_status!
|
||||
validate_media!
|
||||
preprocess_attributes!
|
||||
|
||||
|
@ -158,6 +159,10 @@ class PostStatusService < BaseService
|
|||
GroupReblogService.new.call(@status)
|
||||
end
|
||||
|
||||
def validate_status!
|
||||
raise Mastodon::ValidationError, I18n.t('statuses.contains_ng_words') if Admin::NgWord.reject?("#{@options[:spoiler_text]}\n#{@options[:text]}")
|
||||
end
|
||||
|
||||
def validate_media!
|
||||
if @options[:media_ids].blank? || !@options[:media_ids].is_a?(Enumerable)
|
||||
@media = []
|
||||
|
|
|
@ -27,6 +27,8 @@ class UpdateStatusService < BaseService
|
|||
|
||||
clear_histories! if @options[:no_history]
|
||||
|
||||
validate_status!
|
||||
|
||||
Status.transaction do
|
||||
create_previous_edit! unless @options[:no_history]
|
||||
update_media_attachments! if @options.key?(:media_ids)
|
||||
|
@ -71,6 +73,10 @@ class UpdateStatusService < BaseService
|
|||
@status.media_attachments.reload
|
||||
end
|
||||
|
||||
def validate_status!
|
||||
raise Mastodon::ValidationError, I18n.t('statuses.contains_ng_words') if Admin::NgWord.reject?("#{@options[:spoiler_text]}\n#{@options[:text]}")
|
||||
end
|
||||
|
||||
def validate_media!
|
||||
return [] if @options[:media_ids].blank? || !@options[:media_ids].is_a?(Enumerable)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue