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

Fix admins being able to suspend their instance actor #14567

Merged
merged 4 commits into from
Dec 15, 2020
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
3 changes: 2 additions & 1 deletion app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class Account < ApplicationRecord
scope :sensitized, -> { where.not(sensitized_at: nil) }
scope :without_suspended, -> { where(suspended_at: nil) }
scope :without_silenced, -> { where(silenced_at: nil) }
scope :without_instance_actor, -> { where.not(id: -99) }
scope :recent, -> { reorder(id: :desc) }
scope :bots, -> { where(actor_type: %w(Application Service)) }
scope :groups, -> { where(actor_type: 'Group') }
Expand Down Expand Up @@ -222,7 +223,7 @@ def unsilence!
end

def suspended?
suspended_at.present?
suspended_at.present? && !instance_actor?
end

def suspended_permanently?
Expand Down
2 changes: 1 addition & 1 deletion app/models/account_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def set_defaults!
def scope_for(key, value)
case key.to_s
when 'local'
Account.local
Account.local.without_instance_actor
when 'remote'
Account.remote
when 'by_domain'
Expand Down
4 changes: 2 additions & 2 deletions app/policies/account_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def warn?
end

def suspend?
staff? && !record.user&.staff?
staff? && !record.user&.staff? && !record.instance_actor?
end

def destroy?
Expand Down Expand Up @@ -62,6 +62,6 @@ def unsubscribe?
end

def memorialize?
admin? && !record.user&.admin?
admin? && !record.user&.admin? && !record.instance_actor?
end
end
4 changes: 4 additions & 0 deletions app/views/admin/accounts/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
- content_for :page_title do
= @account.acct

- if @account.instance_actor?
.flash-message.notice
%strong= t('accounts.instance_actor_flash')

= render 'application/card', account: @account

- account = @account
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ en:
one: Follower
other: Followers
following: Following
instance_actor_flash: This account is a virtual actor used to represent the server itself and not any individual user. It is used for federation purposes and should not be suspended.
ClearlyClaire marked this conversation as resolved.
Show resolved Hide resolved
joined: Joined %{date}
last_active: last active
link_verified_on: Ownership of this link was checked on %{date}
Expand Down
2 changes: 1 addition & 1 deletion spec/models/account_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
it 'defaults to recent local not-suspended account list' do
filter = described_class.new({})

expect(filter.results).to eq Account.local.recent.without_suspended
expect(filter.results).to eq Account.local.without_instance_actor.recent.without_suspended
end
end

Expand Down