Files
once-campfire/app/models/user/bannable.rb
T
Marcello CostagliolaandClaude Opus 5.5 ce4c05da81 Apply the same user filter to every page of account members
Administrators see banned users in the account settings, but only the
first page counted them: the next pages listed active users alone. A
banned member before the page boundary shifted the offset, so one active
member was never listed. Both pages now share User.visible_to.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0142qgjggdJ2KDdGk7RF9Xm9
2026-10-05 15:19:21 +02:00

48 lines
940 B
Ruby

module User::Bannable
extend ActiveSupport::Concern
included do
# Administrators still see banned users, so they can lift the ban.
scope :visible_to, ->(user) { user.can_administer? ? where(status: %i[ active banned ]) : active }
end
def ban
transaction do
create_bans_from_sessions
apply_ban
banned!
end
end
def unban
transaction do
bans.delete_all
active!
end
end
def remove_banned_content_later
RemoveBannedContentJob.perform_later(self)
end
def remove_banned_content
messages.each do |message|
message.destroy
message.broadcast_remove
end
end
private
def create_bans_from_sessions
sessions.pluck(:ip_address).compact_blank.uniq.each do |ip|
bans.create!(ip_address: ip)
end
end
def apply_ban
close_remote_connections
sessions.delete_all
remove_banned_content_later
end
end