add user banning/unbanning from user view page
This commit is contained in:
parent
38ac6a4c3f
commit
cbc1c50cd2
|
@ -89,6 +89,19 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
def require_logged_in_moderator
|
||||
require_logged_in_user
|
||||
|
||||
if @user
|
||||
if @user.is_moderator?
|
||||
true
|
||||
else
|
||||
flash[:error] = "You are not authorized to access that resource."
|
||||
return redirect_to "/"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def require_logged_in_user_or_400
|
||||
if @user
|
||||
true
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class UsersController < ApplicationController
|
||||
before_filter :require_logged_in_moderator, :only => [ :ban, :unban ]
|
||||
|
||||
def show
|
||||
@showing_user = User.where(:username => params[:username]).first!
|
||||
@title = "User #{@showing_user.username}"
|
||||
|
@ -34,4 +36,35 @@ class UsersController < ApplicationController
|
|||
def invite
|
||||
@title = "Pass Along an Invitation"
|
||||
end
|
||||
|
||||
def ban
|
||||
buser = User.where(:username => params[:username]).first
|
||||
if !buser
|
||||
flash[:error] = "Invalid user."
|
||||
return redirect_to "/"
|
||||
end
|
||||
|
||||
if !params[:reason].present?
|
||||
flash[:error] = "You must give a reason for the ban."
|
||||
return redirect_to user_path(:user => buser.username)
|
||||
end
|
||||
|
||||
buser.ban_by_user_for_reason!(@user, params[:reason])
|
||||
|
||||
flash[:success] = "User has been banned."
|
||||
return redirect_to user_path(:user => buser.username)
|
||||
end
|
||||
|
||||
def unban
|
||||
buser = User.where(:username => params[:username]).first
|
||||
if !buser
|
||||
flash[:error] = "Invalid user."
|
||||
return redirect_to "/"
|
||||
end
|
||||
|
||||
buser.unban_by_user!(@user)
|
||||
|
||||
flash[:success] = "User has been unbanned."
|
||||
return redirect_to user_path(:user => buser.username)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,8 @@ class BanNotification < ActionMailer::Base
|
|||
@reason = reason
|
||||
|
||||
mail(
|
||||
:from => "#{@banner.username} <#{@banner.email}>",
|
||||
:from => "#{@banner.username} <nobody@#{Rails.application.domain}>",
|
||||
:replyto => "#{@banner.username} <#{@banner.email}>",
|
||||
:to => user.email,
|
||||
:subject => "[#{Rails.application.name}] You have been banned"
|
||||
)
|
||||
|
|
|
@ -241,11 +241,19 @@ class User < ActiveRecord::Base
|
|||
username
|
||||
end
|
||||
|
||||
def unban!
|
||||
def unban_by_user!(unbanner)
|
||||
self.banned_at = nil
|
||||
self.banned_by_user_id = nil
|
||||
self.banned_reason = nil
|
||||
self.save!
|
||||
|
||||
m = Moderation.new
|
||||
m.moderator_user_id = unbanner.id
|
||||
m.user_id = self.id
|
||||
m.action = "Unbanned"
|
||||
m.save!
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def undeleted_received_messages
|
||||
|
|
|
@ -166,5 +166,39 @@
|
|||
<% end %>
|
||||
</div>
|
||||
<br>
|
||||
|
||||
<div style="clear: both;"></div>
|
||||
<br>
|
||||
|
||||
<p>
|
||||
<div class="legend">
|
||||
Administrative Actions
|
||||
</div>
|
||||
</p>
|
||||
|
||||
<% if @user.is_banned? %>
|
||||
<%= form_tag user_unban_path, :method => :post do %>
|
||||
<p>
|
||||
<%= submit_tag "Unban User" %>
|
||||
</p>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= form_tag user_ban_path, :method => :post do %>
|
||||
<p>
|
||||
Banning a user will send an e-mail to the user with the reason below,
|
||||
with your e-mail address as the Reply-To so the user can respond.
|
||||
</p>
|
||||
<p>
|
||||
|
||||
<div class="boxline">
|
||||
<%= label_tag :reason, "Reason:", :class => "required" %>
|
||||
<%= text_field_tag :reason, "", :size => 40 %>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<%= submit_tag "Ban User" %>
|
||||
</p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
@ -90,6 +90,9 @@ Lobsters::Application.routes.draw do
|
|||
get "/u" => "users#tree"
|
||||
get "/u/:username" => "users#show", :as => "user", :format => /html|json/
|
||||
|
||||
post "/users/:username/ban" => "users#ban", :as => "user_ban"
|
||||
post "/users/:username/unban" => "users#unban", :as => "user_unban"
|
||||
|
||||
get "/settings" => "settings#index"
|
||||
post "/settings" => "settings#update"
|
||||
post "/settings/pushover" => "settings#pushover"
|
||||
|
|
Loading…
Reference in a new issue