Files
danbooru/app/models/user_name_change_request.rb
evazion 94e125709c users: add Restricted user level.
Add a Restricted user level. Restricted users are level 10, below
Members. New users start out as Restricted if they sign up from a proxy
or an IP recently used by another user.

Restricted users can't update or edit any public content on the site
until they verify their email address, at which point they're promoted
to Member. Restricted users are only allowed to do personal actions
like keep favorites, keep favgroups and saved searches, mark dmails as
read or deleted, or mark forum posts as read.

The restricted state already existed before, the only change here is
that now it's an actual user level instead of a hidden state. Before it
was based on two hidden flags on the user, the `requires_verification`
flag (set when a user signs up from a proxy, etc), and the `is_verified`
flag (set after the user verifies their email). Making it a user level
means that now the Restricted status will be shown publicly.

Introducing a new level below Member means that we have to change every
`is_member?` check to `!is_anonymous` for every place where we used
`is_member?` to check that the current user is logged in.
2021-01-07 17:10:29 -06:00

36 lines
934 B
Ruby

class UserNameChangeRequest < ApplicationRecord
belongs_to :user
belongs_to :approver, class_name: "User", optional: true
validate :not_limited, on: :create
validates :desired_name, user_name: true, confirmation: true, on: :create
validates_presence_of :original_name, :desired_name
after_create :update_name!
def self.visible(user)
if user.is_moderator?
all
elsif user.is_anonymous?
none
else
where(user: User.undeleted)
end
end
def self.search(params)
q = search_attributes(params, :id, :created_at, :updated_at, :user, :original_name, :desired_name)
q.apply_default_order(params)
end
def update_name!
user.update!(name: desired_name)
end
def not_limited
if UserNameChangeRequest.unscoped.where(user: user).where("created_at >= ?", 1.week.ago).exists?
errors.add(:base, "You can only submit one name change request per week")
end
end
end