Browse Source

Limit maximum visibility of local silenced users to unlisted (#9583)

Fixes #9580
closed-social-v3
ThibG 5 years ago
committed by Eugen Rochko
parent
commit
5f387995d9
2 changed files with 11 additions and 1 deletions
  1. +4
    -1
      app/services/post_status_service.rb
  2. +7
    -0
      spec/services/post_status_service_spec.rb

+ 4
- 1
app/services/post_status_service.rb View File

@ -23,13 +23,16 @@ class PostStatusService < BaseService
status = nil
text = options.delete(:spoiler_text) if text.blank? && options[:spoiler_text].present?
visibility = options[:visibility] || account.user&.setting_default_privacy
visibility = :unlisted if visibility == :public && account.silenced
ApplicationRecord.transaction do
status = account.statuses.create!(text: text,
media_attachments: media || [],
thread: in_reply_to,
sensitive: (options[:sensitive].nil? ? account.user&.setting_default_sensitive : options[:sensitive]) || options[:spoiler_text].present?,
spoiler_text: options[:spoiler_text] || '',
visibility: options[:visibility] || account.user&.setting_default_privacy,
visibility: visibility,
language: language_from_option(options[:language]) || account.user&.setting_default_language&.presence || LanguageDetector.instance.detect(text, account),
application: options[:application])
end

+ 7
- 0
spec/services/post_status_service_spec.rb View File

@ -68,6 +68,13 @@ RSpec.describe PostStatusService, type: :service do
expect(status.visibility).to eq "private"
end
it 'creates a status with limited visibility for silenced users' do
status = subject.call(Fabricate(:account, silenced: true), 'test', nil, visibility: :public)
expect(status).to be_persisted
expect(status.visibility).to eq "unlisted"
end
it 'creates a status for the given application' do
application = Fabricate(:application)

Loading…
Cancel
Save