Add ability to block words in usernames (#35407)

This commit is contained in:
Eugen Rochko
2025-07-29 12:19:15 +02:00
committed by GitHub
parent 8cf7a77808
commit 20bbd20ef1
28 changed files with 560 additions and 34 deletions

View File

@@ -0,0 +1,23 @@
# frozen_string_literal: true
class CreateUsernameBlocks < ActiveRecord::Migration[8.0]
def change
create_table :username_blocks do |t|
t.string :username, null: false
t.string :normalized_username, null: false
t.boolean :exact, null: false, default: false
t.boolean :allow_with_approval, null: false, default: false
t.timestamps
end
add_index :username_blocks, 'lower(username)', unique: true, name: 'index_username_blocks_on_username_lower_btree'
add_index :username_blocks, :normalized_username
reversible do |dir|
dir.up do
load Rails.root.join('db', 'seeds', '05_blocked_usernames.rb')
end
end
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2025_06_27_132728) do
ActiveRecord::Schema[8.0].define(version: 2025_07_17_003848) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
@@ -1238,6 +1238,17 @@ ActiveRecord::Schema[8.0].define(version: 2025_06_27_132728) do
t.datetime "updated_at", null: false
end
create_table "username_blocks", force: :cascade do |t|
t.string "username", null: false
t.string "normalized_username", null: false
t.boolean "exact", default: false, null: false
t.boolean "allow_with_approval", default: false, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index "lower((username)::text)", name: "index_username_blocks_on_username_lower_btree", unique: true
t.index ["normalized_username"], name: "index_username_blocks_on_normalized_username"
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.datetime "created_at", precision: nil, null: false

View File

@@ -0,0 +1,34 @@
# frozen_string_literal: true
%w(
abuse
account
accounts
admin
administration
administrator
admins
help
helpdesk
instance
mod
moderator
moderators
mods
owner
root
security
server
staff
support
webmaster
).each do |str|
UsernameBlock.create_with(username: str, exact: true).find_or_create_by(username: str)
end
%w(
mastodon
mastadon
).each do |str|
UsernameBlock.create_with(username: str, exact: false).find_or_create_by(username: str)
end