Skip to content

Commit

Permalink
Add Account#unavailable? and Account#permanently_unavailable? ali…
Browse files Browse the repository at this point in the history
…ases (mastodon#28053)
  • Loading branch information
ClearlyClaire authored Nov 30, 2023
1 parent 35deaaf commit 9633549
Show file tree
Hide file tree
Showing 25 changed files with 57 additions and 58 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def require_authenticated_user!
end

def require_not_suspended!
render json: { error: 'Your login is currently disabled' }, status: 403 if current_user&.account&.suspended?
render json: { error: 'Your login is currently disabled' }, status: 403 if current_user&.account&.unavailable?
end

def require_user!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def load_accounts
end

def hide_results?
@account.suspended? || (@account.hides_followers? && current_account&.id != @account.id) || (current_account && @account.blocking?(current_account))
@account.unavailable? || (@account.hides_followers? && current_account&.id != @account.id) || (current_account && @account.blocking?(current_account))
end

def default_accounts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def load_accounts
end

def hide_results?
@account.suspended? || (@account.hides_following? && current_account&.id != @account.id) || (current_account && @account.blocking?(current_account))
@account.unavailable? || (@account.hides_following? && current_account&.id != @account.id) || (current_account && @account.blocking?(current_account))
end

def default_accounts
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/accounts/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def set_account
end

def load_statuses
@account.suspended? ? [] : cached_account_statuses
@account.unavailable? ? [] : cached_account_statuses
end

def cached_account_statuses
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/auth/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def set_strikes
end

def require_not_suspended!
forbidden if current_account.suspended?
forbidden if current_account.unavailable?
end

def set_rules
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/concerns/account_owned_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def check_account_confirmation
end

def check_account_suspension
if @account.suspended_permanently?
permanent_suspension_response
if @account.permanently_unavailable?
permanent_unavailability_response
elsif @account.suspended? && !skip_temporary_suspension_response?
temporary_suspension_response
end
Expand All @@ -45,7 +45,7 @@ def skip_temporary_suspension_response?
false
end

def permanent_suspension_response
def permanent_unavailability_response
expires_in(3.minutes, public: true)
gone
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def store_current_location
end

def require_not_suspended!
forbidden if current_account.suspended?
forbidden if current_account.unavailable?
end

def set_cache_headers
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/settings/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ def set_cache_headers
end

def require_not_suspended!
forbidden if current_account.suspended?
forbidden if current_account.unavailable?
end
end
2 changes: 1 addition & 1 deletion app/controllers/settings/deletes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def resource_params
end

def require_not_suspended!
forbidden if current_account.suspended?
forbidden if current_account.unavailable?
end

def challenge_passed?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/well_known/webfinger_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def resource_param
end

def check_account_suspension
gone if @account.suspended_permanently?
gone if @account.permanently_unavailable?
end

def gone
Expand Down
6 changes: 1 addition & 5 deletions app/lib/account_statuses_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def results
private

def initial_scope
return Status.none if suspended?
return Status.none if account.unavailable?

if anonymous?
account.statuses.where(visibility: %i(public unlisted))
Expand Down Expand Up @@ -95,10 +95,6 @@ def hashtag_scope
end
end

def suspended?
account.suspended?
end

def anonymous?
current_account.nil?
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/activitypub/activity/move.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def perform

target_account = ActivityPub::FetchRemoteAccountService.new.call(target_uri)

if target_account.nil? || target_account.suspended? || !target_account.also_known_as.include?(origin_account.uri)
if target_account.nil? || target_account.unavailable? || !target_account.also_known_as.include?(origin_account.uri)
unmark_as_processing!
return
end
Expand Down
3 changes: 3 additions & 0 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ def suspended_temporarily?
suspended? && deletion_request.present?
end

alias unavailable? suspended?
alias permanently_unavailable? suspended_permanently?

def suspend!(date: Time.now.utc, origin: :local, block_email: true)
transaction do
create_deletion_request!
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def functional?
end

def functional_or_moved?
confirmed? && approved? && !disabled? && !account.suspended? && !account.memorial?
confirmed? && approved? && !disabled? && !account.unavailable? && !account.memorial?
end

def unconfirmed?
Expand Down
2 changes: 1 addition & 1 deletion app/policies/status_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(current_account, record, preloaded_relations = {})
end

def show?
return false if author.suspended?
return false if author.unavailable?

if requires_mention?
owned? || mention_exists?
Expand Down
22 changes: 11 additions & 11 deletions app/serializers/activitypub/actor_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,19 @@ def preferred_username
end

def discoverable
object.suspended? ? false : (object.discoverable || false)
object.unavailable? ? false : (object.discoverable || false)
end

def indexable
object.suspended? ? false : (object.indexable || false)
object.unavailable? ? false : (object.indexable || false)
end

def name
object.suspended? ? object.username : (object.display_name.presence || object.username)
object.unavailable? ? object.username : (object.display_name.presence || object.username)
end

def summary
object.suspended? ? '' : account_bio_format(object)
object.unavailable? ? '' : account_bio_format(object)
end

def icon
Expand All @@ -132,35 +132,35 @@ def url
end

def avatar_exists?
!object.suspended? && object.avatar?
!object.unavailable? && object.avatar?
end

def header_exists?
!object.suspended? && object.header?
!object.unavailable? && object.header?
end

def manually_approves_followers
object.suspended? ? false : object.locked
object.unavailable? ? false : object.locked
end

def virtual_tags
object.suspended? ? [] : (object.emojis + object.tags)
object.unavailable? ? [] : (object.emojis + object.tags)
end

def virtual_attachments
object.suspended? ? [] : object.fields
object.unavailable? ? [] : object.fields
end

def moved_to
ActivityPub::TagManager.instance.uri_for(object.moved_to_account)
end

def moved?
!object.suspended? && object.moved?
!object.unavailable? && object.moved?
end

def also_known_as?
!object.suspended? && !object.also_known_as.empty?
!object.unavailable? && !object.also_known_as.empty?
end

def published
Expand Down
30 changes: 15 additions & 15 deletions app/serializers/rest/account_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def acct
end

def note
object.suspended? ? '' : account_bio_format(object)
object.unavailable? ? '' : account_bio_format(object)
end

def url
Expand All @@ -73,19 +73,19 @@ def uri
end

def avatar
full_asset_url(object.suspended? ? object.avatar.default_url : object.avatar_original_url)
full_asset_url(object.unavailable? ? object.avatar.default_url : object.avatar_original_url)
end

def avatar_static
full_asset_url(object.suspended? ? object.avatar.default_url : object.avatar_static_url)
full_asset_url(object.unavailable? ? object.avatar.default_url : object.avatar_static_url)
end

def header
full_asset_url(object.suspended? ? object.header.default_url : object.header_original_url)
full_asset_url(object.unavailable? ? object.header.default_url : object.header_original_url)
end

def header_static
full_asset_url(object.suspended? ? object.header.default_url : object.header_static_url)
full_asset_url(object.unavailable? ? object.header.default_url : object.header_static_url)
end

def created_at
Expand All @@ -97,39 +97,39 @@ def last_status_at
end

def display_name
object.suspended? ? '' : object.display_name
object.unavailable? ? '' : object.display_name
end

def locked
object.suspended? ? false : object.locked
object.unavailable? ? false : object.locked
end

def bot
object.suspended? ? false : object.bot
object.unavailable? ? false : object.bot
end

def discoverable
object.suspended? ? false : object.discoverable
object.unavailable? ? false : object.discoverable
end

def indexable
object.suspended? ? false : object.indexable
object.unavailable? ? false : object.indexable
end

def moved_to_account
object.suspended? ? nil : AccountDecorator.new(object.moved_to_account)
object.unavailable? ? nil : AccountDecorator.new(object.moved_to_account)
end

def emojis
object.suspended? ? [] : object.emojis
object.unavailable? ? [] : object.emojis
end

def fields
object.suspended? ? [] : object.fields
object.unavailable? ? [] : object.fields
end

def suspended
object.suspended?
object.unavailable?
end

def silenced
Expand All @@ -141,7 +141,7 @@ def memorial
end

def roles
if object.suspended? || object.user.nil?
if object.unavailable? || object.user.nil?
[]
else
[object.user.role].compact.filter(&:highlighted?)
Expand Down
2 changes: 1 addition & 1 deletion app/services/follow_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def mark_home_feed_as_partial!
end

def following_not_possible?
@target_account.nil? || @target_account.id == @source_account.id || @target_account.suspended?
@target_account.nil? || @target_account.id == @source_account.id || @target_account.unavailable?
end

def following_not_allowed?
Expand Down
2 changes: 1 addition & 1 deletion app/services/notify_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def domain_blocking?
end

def blocked?
blocked = @recipient.suspended?
blocked = @recipient.unavailable?
blocked ||= from_self? && @notification.type != :poll

return blocked if message? && from_staff?
Expand Down
2 changes: 1 addition & 1 deletion app/services/process_mentions_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def scan_text!

# If after resolving it still isn't found or isn't the right
# protocol, then give up
next match if mention_undeliverable?(mentioned_account) || mentioned_account&.suspended?
next match if mention_undeliverable?(mentioned_account) || mentioned_account&.unavailable?

mention = @previous_mentions.find { |x| x.account_id == mentioned_account.id }
mention ||= @current_mentions.find { |x| x.account_id == mentioned_account.id }
Expand Down
2 changes: 1 addition & 1 deletion app/services/report_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def call(source_account, target_account, options = {})
@rule_ids = options.delete(:rule_ids).presence
@options = options

raise ActiveRecord::RecordNotFound if @target_account.suspended?
raise ActiveRecord::RecordNotFound if @target_account.unavailable?

create_report!
notify_staff!
Expand Down
8 changes: 4 additions & 4 deletions app/views/admin/accounts/_account.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.batch-table__row{ class: [!account.suspended? && account.user_pending? && 'batch-table__row--attention', (account.suspended? || account.user_unconfirmed?) && 'batch-table__row--muted'] }
.batch-table__row{ class: [!account.unavailable? && account.user_pending? && 'batch-table__row--attention', (account.unavailable? || account.user_unconfirmed?) && 'batch-table__row--muted'] }
%label.batch-table__row__select.batch-table__row__select--aligned.batch-checkbox
= f.check_box :account_ids, { multiple: true, include_hidden: false }, account.id
.batch-table__row__content.batch-table__row__content--unpadded
Expand All @@ -8,13 +8,13 @@
%td
= account_link_to account, path: admin_account_path(account.id)
%td.accounts-table__count.optional
- if account.suspended? || account.user_pending?
- if account.unavailable? || account.user_pending?
\-
- else
= friendly_number_to_human account.statuses_count
%small= t('accounts.posts', count: account.statuses_count).downcase
%td.accounts-table__count.optional
- if account.suspended? || account.user_pending?
- if account.unavailable? || account.user_pending?
\-
- else
= friendly_number_to_human account.followers_count
Expand All @@ -30,6 +30,6 @@
\-
%br/
%samp.ellipsized-ip= relevant_account_ip(account, params[:ip])
- if !account.suspended? && account.user_pending? && account.user&.invite_request&.text.present?
- if !account.unavailable? && account.user_pending? && account.user&.invite_request&.text.present?
.batch-table__row__content__quote
%p= account.user&.invite_request&.text
2 changes: 1 addition & 1 deletion app/views/oauth/authorized_applications/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

= t('doorkeeper.authorized_applications.index.authorized_at', date: l(application.created_at.to_date))

- unless application.superapp? || current_account.suspended?
- unless application.superapp? || current_account.unavailable?
%div
= table_link_to 'times', t('doorkeeper.authorized_applications.buttons.revoke'), oauth_authorized_application_path(application), method: :delete, data: { confirm: t('doorkeeper.authorized_applications.confirmations.revoke') }

Expand Down
2 changes: 1 addition & 1 deletion app/workers/account_deletion_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AccountDeletionWorker

def perform(account_id, options = {})
account = Account.find(account_id)
return unless account.suspended?
return unless account.unavailable?

reserve_username = options.with_indifferent_access.fetch(:reserve_username, true)
skip_activitypub = options.with_indifferent_access.fetch(:skip_activitypub, false)
Expand Down
Loading

0 comments on commit 9633549

Please sign in to comment.