mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-13 07:49:29 +00:00
Add ability to block words in usernames (#35407)
This commit is contained in:
23
db/migrate/20250717003848_create_username_blocks.rb
Normal file
23
db/migrate/20250717003848_create_username_blocks.rb
Normal 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
|
||||
13
db/schema.rb
13
db/schema.rb
@@ -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
|
||||
|
||||
34
db/seeds/05_blocked_usernames.rb
Normal file
34
db/seeds/05_blocked_usernames.rb
Normal 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
|
||||
Reference in New Issue
Block a user