Files
danbooru/app/controllers/user_name_change_requests_controller.rb
evazion 99846b7e3d users: allow mods to change the names of other users.
Allow moderators to forcibly change the username of other users. This is
so mods can change abusive or invalid usernames.

* A mod can only change the username of Builder-level users and below.
* The user can't change their own name again until one week has passed.
* A modaction is logged when a mod changes a user's name.
* A dmail is sent to the user notifying them of the change.
* The dmail does not send the user an email notification. This is so we
  don't spam users if their name is changed after they're banned, or if
  they haven't visited the site in a long time.

The rename button is on the user's profile page, and when you hover over
the user's name and open the "..." menu.
2022-10-02 01:32:10 -05:00

32 lines
1.1 KiB
Ruby

# frozen_string_literal: true
class UserNameChangeRequestsController < ApplicationController
respond_to :html, :json, :xml
skip_before_action :redirect_if_name_invalid?
def new
user = User.find_by_name(params[:id]) || CurrentUser.user
@change_request = authorize UserNameChangeRequest.new(user: user, **permitted_attributes(UserNameChangeRequest))
respond_with(@change_request)
end
def create
user = User.find(params.dig(:user_name_change_request, :user_id))
@change_request = authorize UserNameChangeRequest.new(updater: CurrentUser.user, original_name: user.name, **permitted_attributes(UserNameChangeRequest))
@change_request.save
flash[:notice] = "Name changed" if @change_request.valid?
respond_with(@change_request, location: @change_request.user)
end
def show
@change_request = authorize UserNameChangeRequest.find(params[:id])
respond_with(@change_request)
end
def index
@change_requests = authorize UserNameChangeRequest.visible(CurrentUser.user).paginated_search(params)
respond_with(@change_requests)
end
end