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.
This commit is contained in:
evazion
2022-10-01 23:13:21 -05:00
parent 775326dc37
commit 99846b7e3d
16 changed files with 107 additions and 30 deletions

View File

@@ -160,7 +160,7 @@
<% if !CurrentUser.user.is_anonymous? && CurrentUser.user.name_invalid? %>
<div class="notice notice-error notice-large" id="invalid-name-notice">
<h2>Action required </h2>
<div>You must <%= link_to "change your username", new_user_name_change_request_path %> to continue using <%= Danbooru.config.canonical_app_name %>.</div>
<div>You must <%= link_to "change your username", change_name_user_path(CurrentUser.user) %> to continue using <%= Danbooru.config.canonical_app_name %>.</div>
</div>
<% end %>

View File

@@ -131,9 +131,6 @@
<% else %>
<li><%= link_to "Profile", profile_path %></li>
<li><%= link_to "Settings", settings_path %></li>
<% if policy(UserNameChangeRequest).create? %>
<li><%= link_to "Change name", new_user_name_change_request_path %></li>
<% end %>
<li><%= link_to "Uploads", user_uploads_path(CurrentUser.user) %></li>
<li><%= link_to "Dmails", dmails_path(search: { folder: "received" }) %></li>
<li><%= link_to "Favorites", favorites_path %></li>

View File

@@ -1,5 +1,5 @@
<% content_for(:secondary_links) do %>
<%= subnav_link_to "Listing", user_name_change_requests_path %>
<%= subnav_link_to "New", new_user_name_change_request_path %>
<%= subnav_link_to "New", change_name_user_path(CurrentUser.user) unless CurrentUser.user.is_anonymous? %>
<%= subnav_link_to "Help", wiki_page_path("help:user_name_change_requests") %>
<% end %>

View File

@@ -1,6 +1,10 @@
<div id="c-user-name-change-requests">
<div id="a-new" class="fixed-width-container">
<h1>Change Name</h1>
<% if CurrentUser.user != @change_request.user %>
<h1>Change Name: <%= link_to_user @change_request.user %></h1>
<% else %>
<h1>Change Name</h1>
<% end %>
<% if CurrentUser.user.name_invalid? %>
<p> Your current username is invalid. You must change your username to continue
@@ -26,6 +30,7 @@
</div>
<%= edit_form_for(@change_request) do |f| %>
<%= f.input :user_id, as: :hidden, input_html: { value: @change_request.user_id } %>
<%= f.input :desired_name, label: "New name" %>
<%= f.submit "Submit" %>
<% end %>

View File

@@ -8,7 +8,6 @@
<th>Date</th>
<td>
<%= compact_time @change_request.created_at %>
<%= render "application/update_notice", record: @change_request %>
</td>
</tr>
<tr>

View File

@@ -27,6 +27,10 @@
<%= subnav_link_to "Promote", edit_admin_user_path(@user) %>
<% end %>
<% if policy(UserNameChangeRequest.new(user: @user)).can_rename_user? %>
<%= subnav_link_to "Rename", change_name_user_path(@user) %>
<% end %>
<% if policy(Ban.new(user: @user)).create? %>
<% if @user.is_banned? && @user.active_ban.present? %>
<%= subnav_link_to "Unban", ban_path(@user.active_ban) %>

View File

@@ -14,7 +14,7 @@
<fieldset id="basic-settings-section">
<div class="input">
<label>Name</label>
<p><%= link_to "Change your name", new_user_name_change_request_path %></p>
<p><%= link_to "Change your name", change_name_user_path(@user) %></p>
</div>
<div class="input">

View File

@@ -83,6 +83,14 @@
<% end %>
<% end %>
<% end %>
<% if policy(UserNameChangeRequest.new(user: @user)).can_rename_user? %>
<% menu.item do %>
<%= link_to change_name_user_path(@user) do %>
<%= feedback_icon %> Rename User
<% end %>
<% end %>
<% end %>
<% end %>
</div>