mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-08 15:50:08 +09:00
ce4c05da81
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
48 lines
940 B
Ruby
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
|