forked from lobsters/lobsters
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement admin action for reparenting a user lobsters#1370
- Loading branch information
Showing
8 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Mod::ModeratorController < ApplicationController | ||
before_action :require_logged_in_moderator | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class Mod::ReparentsController < Mod::ModeratorController | ||
before_action :require_logged_in_admin | ||
before_action :load_user | ||
|
||
def new | ||
end | ||
|
||
def create | ||
if params[:reason].blank? | ||
return redirect_to new_mod_reparent_path({}, id: @reparent_user), flash: {error: "Reason can't be blank."} | ||
end | ||
|
||
User.transaction do | ||
ModNote.record_reparent!(@reparent_user, @user, params[:reason]) | ||
@reparent_user.invited_by_user = @user | ||
@reparent_user.save! | ||
Moderation.create!({ | ||
moderator: @user, | ||
user: @reparent_user, | ||
action: "Reparented user to be invited by #{@user.username}", | ||
reason: params[:reason] | ||
}) | ||
end | ||
Rails.cache.delete("users_tree_#{User.last.id}") # UsersController#tree | ||
|
||
redirect_to user_path(@reparent_user), flash: {success: "User been has reparented to you."} | ||
end | ||
|
||
private | ||
|
||
def load_user | ||
params.require(:id) | ||
@reparent_user = User.find_by! username: params[:id] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<h1>Reparent <%= @reparent_user.username %></h1> | ||
|
||
<%= form_with url: mod_reparents_path({}, id: @reparent_user), method: :post do |f| %> | ||
<p> | ||
This will reparent <%= @reparent_user.username %> to you in the invite tree, create a mod note on the user with their old inviter, and put an entry in the moderation log with the given reason. | ||
</p> | ||
|
||
<p> | ||
This should be used rarely because it makes it harder to investigate sockpuppets and voting rings. | ||
Currently the only known purpose is if this user was abused off-site by their inviter and we can't really do anything about it here except try to disassociate them. | ||
Write a good reason here, it's going to get attention by virtue of being rare. | ||
</p> | ||
|
||
<div class="boxline"> | ||
<%= f.label :reason, "Reason:", :class => "required" %> | ||
<%= f.text_field :reason, :size => 80 %> | ||
</div> | ||
<%= f.submit "Reparent" %> | ||
<% end %> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# typed: false | ||
|
||
require "rails_helper" | ||
|
||
describe "Mod::ReparentsController", type: :request do | ||
context "/new form" do | ||
it "loads" do | ||
sign_in create(:user, :admin) | ||
reparent_user = create(:user) | ||
get "/mod/reparents/new", params: {id: reparent_user.username} | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
context "reparenting" do | ||
it "reparents the user and logs it" do | ||
sign_in create(:user, :admin) | ||
inviter = create(:user) | ||
reparent_user = create(:user, invited_by_user: inviter) | ||
post "/mod/reparents", params: {id: reparent_user.username, reason: "Abuse"} | ||
expect(response).to redirect_to user_path(reparent_user) | ||
reparent_user.reload | ||
expect(reparent_user.invited_by_user).to_not be(inviter) | ||
expect(Moderation.last.reason).to include("Abuse") | ||
end | ||
end | ||
end |