user name changes: remove unused reason, status fields.

Remove all infrastructure around approving or rejecting user name
changes. Name changes haven't been moderated for several years.

* Remove status, approver_id, change_reason, and rejection_reason fields.
* Remove approve and reject controller actions.
This commit is contained in:
evazion
2019-09-25 19:21:36 -05:00
parent 8d1874d309
commit 3b63f94968
10 changed files with 44 additions and 218 deletions

View File

@@ -1,47 +1,29 @@
class UserNameChangeRequestsController < ApplicationController
before_action :member_only, :only => [:index, :show]
before_action :gold_only, :only => [:new, :create]
before_action :admin_only, :only => [:approve, :reject]
respond_to :html, :json, :xml
def new
@change_request = UserNameChangeRequest.new(change_request_params)
respond_with(@change_request)
end
def create
@change_request = UserNameChangeRequest.create(change_request_params)
if @change_request.errors.any?
render :action => "new"
else
@change_request.approve!
redirect_to user_name_change_request_path(@change_request), :notice => "Your name has been changed"
end
@change_request = UserNameChangeRequest.create_with(user: CurrentUser.user, original_name: CurrentUser.name).create(change_request_params)
flash[:notice] = "Your name has been changed"
respond_with(@change_request, location: profile_path)
end
def show
@change_request = UserNameChangeRequest.find(params[:id])
check_privileges!(@change_request)
respond_with(@change_request)
end
def index
@change_requests = UserNameChangeRequest.visible.order("id desc").paginate(params[:page], :limit => params[:limit])
respond_with(@change_requests)
end
def approve
@change_request = UserNameChangeRequest.find(params[:id])
@change_request.approve!
redirect_to user_name_change_request_path(@change_request), :notice => "Name change request approved"
end
def reject
@change_request = UserNameChangeRequest.find(params[:id])
@change_request.reject!(params[:reason])
redirect_to user_name_change_request_path(@change_request), :notice => "Name change request rejected"
end
private
@@ -51,6 +33,6 @@ class UserNameChangeRequestsController < ApplicationController
end
def change_request_params
params.fetch(:user_name_change_request, {}).permit(%i[desired_name change_reason])
params.fetch(:user_name_change_request, {}).permit(%i[desired_name])
end
end

View File

@@ -1,75 +1,34 @@
class UserNameChangeRequest < ApplicationRecord
after_initialize :initialize_attributes, if: :new_record?
validates_presence_of :original_name, :desired_name
validates_inclusion_of :status, :in => %w(pending approved rejected)
belongs_to :user
belongs_to :approver, :class_name => "User", optional: true
validate :not_limited, :on => :create
belongs_to :approver, class_name: "User", optional: true
validate :not_limited, on: :create
validates :desired_name, user_name: true
validates_presence_of :original_name, :desired_name
def initialize_attributes
self.user_id ||= CurrentUser.user.id
self.original_name ||= CurrentUser.user.name
end
def self.pending
where(:status => "pending")
end
def self.approved
where(:status => "approved")
end
after_create :approve!
def self.visible(viewer = CurrentUser.user)
if viewer.is_admin?
all
elsif viewer.is_member?
joins(:user).merge(User.undeleted).where("user_name_change_requests.status = 'approved' OR user_name_change_requests.user_id = ?", viewer.id)
joins(:user).merge(User.undeleted).where("user_name_change_requests.user_id = ?", viewer.id)
else
none
end
end
def rejected?
status == "rejected"
end
def approved?
status == "approved"
end
def pending?
status == "pending"
end
def feedback
user.feedback.order("id desc")
end
def approve!
update(status: "approved", approver_id: CurrentUser.user.id)
user.update_attribute(:name, desired_name)
body = "Your name change request has been approved. Be sure to log in with your new user name."
Dmail.create_automated(:title => "Name change request approved", :body => body, :to_id => user_id)
UserFeedback.create(:user_id => user_id, :category => "neutral", :body => "Name changed from #{original_name} to #{desired_name}")
ModAction.log("Name changed from #{original_name} to #{desired_name}",:user_name_change)
end
def reject!(reason)
update(status: "rejected", rejection_reason: reason)
body = "Your name change request has been rejected for the following reason: #{rejection_reason}"
Dmail.create_automated(:title => "Name change request rejected", :body => body, :to_id => user_id)
end
def not_limited
if UserNameChangeRequest.where("user_id = ? and created_at >= ?", CurrentUser.user.id, 1.week.ago).exists?
errors.add(:base, "You can only submit one name change request per week")
if UserNameChangeRequest.unscoped.where(user: user).where("created_at >= ?", 1.week.ago).exists?
errors[:base] << "You can only submit one name change request per week"
end
end
def api_attributes
attributes = super
attributes -= [:change_reason, :rejection_reason] unless CurrentUser.is_admin? || user == CurrentUser.user
attributes
end
end

View File

@@ -6,9 +6,8 @@
<thead>
<tr>
<th>User</th>
<th>Request</th>
<th>Reason</th>
<th>Status</th>
<th>Old Name</th>
<th>New Name</th>
<th>Date</th>
<th></th>
</tr>
@@ -17,23 +16,8 @@
<% @change_requests.each do |change_request| %>
<tr>
<td><%= link_to_user change_request.user %></td>
<td>
<strong><%= change_request.original_name %></strong> ->
<strong><%= change_request.desired_name %></strong>
</td>
<td>
<% if CurrentUser.is_admin? || CurrentUser.user == change_request.user %>
<%= change_request.change_reason %>
<% end %>
</td>
<td>
<%= change_request.status %>
<% if change_request.approved? %>
by <%= link_to_user change_request.approver %>
<% elsif change_request.rejected? %>
for reason: <%= link_to change_request.rejection_reason %>
<% end %>
</td>
<td><%= change_request.original_name %></td>
<td><%= change_request.desired_name %></td>
<td><%= compact_time change_request.created_at %></td>
<td><%= link_to "view", user_name_change_request_path(change_request) %></td>
</tr>

View File

@@ -22,66 +22,8 @@
<strong><%= @change_request.desired_name %></strong>
</td>
</tr>
<tr>
<th>Reason</th>
<td><%= @change_request.change_reason %></td>
</tr>
<tr>
<th>Status</th>
<td>
<%= @change_request.status %>
<% if @change_request.approved? %>
by <%= link_to_user @change_request.approver %>
<% elsif @change_request.rejected? %>
for reason: <%= link_to @change_request.rejection_reason %>
<% end %>
</td>
</tr>
</tbody>
</table>
<% if @change_request.pending? && CurrentUser.user.is_admin? %>
<section>
<h2>Feedback</h2>
<ul>
<% @change_request.feedback.each do |feedback| %>
<li class="feedback-category-<%= feedback.category %>">
<p><%= feedback.body %></p>
<p class="fineprint">Submitted by <%= link_to_user feedback.creator.name %> <%= time_ago_in_words_tagged feedback.created_at %></p>
</li>
<% end %>
</ul>
</section>
<section>
<h2>Statistics</h2>
<ul>
<li>Level: <%= @change_request.user.level_string %></li>
<li>Uploads: <%= link_to @change_request.user.post_upload_count, posts_path("user:#{@change_request.user.name}") %></li>
<li>Updates: <%= link_to @change_request.user.post_update_count, post_versions_path(:search => {:updater_id => @change_request.user.id}) %></li>
<li>Notes: <%= link_to @change_request.user.note_update_count, note_versions_path(:search => {:updater_id => @change_request.user.id}) %></li>
<li>Favorites: <%= @change_request.user.favorite_count %></li>
</ul>
</section>
<section>
<h2>Options</h2>
<%= form_tag(approve_user_name_change_request_path(@change_request)) do %>
<%= submit_tag "Approve" %>
<% end %>
<%= form_tag(reject_user_name_change_request_path(@change_request), :class => "simple_form") do %>
<div class="input">
<label>Reason</label>
<%= text_field_tag "reason" %>
</div>
<div class="input">
<%= submit_tag "Reject" %>
</div>
<% end %>
</section>
<% end %>
</div>
</div>