This commit is contained in:
r888888888 2013-04-21 11:36:43 -07:00
parent 53c8babe3e
commit e2a38ebc17
11 changed files with 46 additions and 6 deletions

View File

@ -8,7 +8,7 @@ div#page {
overflow: visible;
margin: 0 30px;
div#upgrade-account-notice, div#sign-up-notice, div#tos-notice {
div#upgrade-account-notice, div#sign-up-notice, div#tos-notice, div#ban-notice {
margin: 1em 0;
padding: 1em;
text-align: center;

View File

@ -88,7 +88,7 @@ protected
%w(member banned builder privileged platinum contributor janitor moderator admin).each do |level|
define_method("#{level}_only") do
if CurrentUser.user.__send__("is_#{level}?")
if !CurrentUser.user.is_banned? && CurrentUser.user.__send__("is_#{level}?")
true
else
access_denied()

View File

@ -2,7 +2,7 @@ class BansController < ApplicationController
before_filter :moderator_only, :except => [:show, :index]
def new
@ban = Ban.new
@ban = Ban.new(params[:ban])
end
def edit

View File

@ -32,6 +32,10 @@ class AnonymousUser
true
end
def is_banned?
false
end
def has_mail?
false
end

View File

@ -1,5 +1,7 @@
class Ban < ActiveRecord::Base
after_create :update_feedback
after_create :update_user_on_create
after_destroy :update_user_on_destroy
belongs_to :user
belongs_to :banner, :class_name => "User"
attr_accessible :reason, :duration, :user_id, :user_name
@ -67,6 +69,14 @@ class Ban < ActiveRecord::Base
end
end
def update_user_on_create
user.update_attribute(:is_banned, true)
end
def update_user_on_destroy
user.update_attribute(:is_banned, false)
end
def user_name
user ? user.name : nil
end

View File

@ -1,11 +1,15 @@
<div class="bans">
<div class="show">
<h1>Show Ban</h1>
<ul>
<ul style="margin-bottom: 1em;">
<li><strong>User</strong>: <%= link_to_user(@ban.user) %></li>
<li><strong>Expires</strong>: <%= compact_time @ban.expires_at %></li>
<li><strong>Reason</strong>: <%= @ban.reason %></li>
</ul>
<%= form_tag(ban_path(@ban), :method => :delete) do %>
<%= submit_tag "Unban" %>
<% end %>
</div>
</div>

View File

@ -44,6 +44,10 @@
<%= render "users/upgrade_notice" %>
<% end %>
<% if CurrentUser.user.is_banned? %>
<%= render "users/ban_notice" %>
<% end %>
<% if cookies["accepted_tos"].blank? && !CurrentUser.is_privileged? %>
<%= render "users/tos" %>
<% end %>

View File

@ -0,0 +1,5 @@
<div class="ui-corner-all ui-state-error" id="ban-notice">
<h1>Your account has been temporarily banned</h1>
<p>Reason: <%= CurrentUser.user.ban.reason %></p>
<p>Your ban will expire in <%= time_ago_in_words(CurrentUser.user.ban.expires_at) %></p>
</div>

View File

@ -27,6 +27,11 @@
<% if CurrentUser.is_moderator? %>
<li><%= link_to "Promote", edit_admin_user_path(@user) %></li>
<% if @user.is_banned? %>
<li><%= link_to "Unban", ban_path(@user.ban) %></li>
<% else %>
<li><%= link_to "Ban", new_ban_path(:ban => {:user_id => @user.id}) %></li>
<% end %>
<% end %>
<li>|</li>

View File

@ -47,8 +47,8 @@ if User.count == 0
0.upto(10) do |i|
User.create(
:name => rand_string(8, true),
:password => i.to_s * 5,
:password_confirmation => i.to_s * 5
:password => "password1",
:password_confirmation => "password1"
)
end
$used_names = Set.new([""])

View File

@ -15,6 +15,14 @@ class BanTest < ActiveSupport::TestCase
CurrentUser.ip_addr = nil
end
should "set the is_banned flag on the user" do
user = FactoryGirl.create(:user)
ban = FactoryGirl.build(:ban, :user => user, :banner => @banner)
ban.save
user.reload
assert(user.is_banned?)
end
should "not be valid against another admin" do
user = FactoryGirl.create(:admin_user)
ban = FactoryGirl.build(:ban, :user => user, :banner => @banner)