* Rename banned and comment_banned roles * Add data update script to rename roles containing 'ban' * Add named error for Suspended users * Update unidiomatic method names * Rename misc banned to suspended * Apply suggestions from code review Co-authored-by: Michael Kohl <me@citizen428.net> * Add unit tests for suspended methods This commit also adds TODO comments for removing banned and comment_banned from the codebase after data update scripts have successfully run on all of our Forems. Co-authored-by: Michael Kohl <me@citizen428.net>
20 lines
533 B
Ruby
20 lines
533 B
Ruby
module Users
|
|
class SuspendedUsername < ApplicationRecord
|
|
self.table_name_prefix = "users_"
|
|
|
|
validates :username_hash, presence: true, uniqueness: true
|
|
|
|
def self.hash_username(username)
|
|
Digest::SHA256.hexdigest(username)
|
|
end
|
|
|
|
def self.previously_suspended?(username)
|
|
where(username_hash: hash_username(username)).any?
|
|
end
|
|
|
|
# Convenience method for easily adding a suspended user
|
|
def self.create_from_user(user)
|
|
create!(username_hash: hash_username(user.username))
|
|
end
|
|
end
|
|
end
|