aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/user_controller.rb12
-rw-r--r--app/models/user.rb12
-rw-r--r--app/views/user/set_draft_profile_photo.html.erb4
-rw-r--r--app/views/user/set_profile_about_me.html.erb8
-rw-r--r--app/views/user/show.html.erb2
-rw-r--r--spec/controllers/user_controller_spec.rb57
-rw-r--r--spec/models/about_me_validator_spec.rb53
-rw-r--r--spec/models/user_spec.rb18
8 files changed, 160 insertions, 6 deletions
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index 56f42891d..d66b4aa8e 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -460,6 +460,12 @@ class UserController < ApplicationController
return
end
if !params[:submitted_draft_profile_photo].nil?
+ if @user.banned?
+ flash[:error]= _('Banned users cannot edit their profile')
+ redirect_to set_profile_photo_path
+ return
+ end
+
# check for uploaded image
file_name = nil
file_content = nil
@@ -569,6 +575,12 @@ class UserController < ApplicationController
return
end
+ if @user.banned?
+ flash[:error] = _('Banned users cannot edit their profile')
+ redirect_to set_profile_about_me_path
+ return
+ end
+
@about_me = AboutMeValidator.new(params[:about_me])
if !@about_me.valid?
render :action => 'set_profile_about_me'
diff --git a/app/models/user.rb b/app/models/user.rb
index c953e52f2..920c0da46 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -207,7 +207,7 @@ class User < ActiveRecord::Base
if not name.nil?
name.strip!
end
- if public_banned?
+ if banned?
# Use interpolation to return a string rather than a SafeBuffer so that
# gsub can be called on it until we upgrade to Rails 3.2. The name returned
# is not marked as HTML safe so will be escaped automatically in views. We
@@ -294,10 +294,18 @@ class User < ActiveRecord::Base
def admin_page_links?
super?
end
+
# Is it public that they are banned?
+ def banned?
+ !ban_text.empty?
+ end
+
def public_banned?
- !ban_text.empty?
+ warn %q([DEPRECATION] User#public_banned? will be replaced with
+ User#banned? as of 0.22).squish
+ banned?
end
+
# Various ways the user can be banned, and text to describe it if failed
def can_file_requests?
ban_text.empty? && !exceeded_limit?
diff --git a/app/views/user/set_draft_profile_photo.html.erb b/app/views/user/set_draft_profile_photo.html.erb
index b4bdd80f3..ba44f54f4 100644
--- a/app/views/user/set_draft_profile_photo.html.erb
+++ b/app/views/user/set_draft_profile_photo.html.erb
@@ -11,7 +11,9 @@
<%= form_tag 'set_photo', :id => 'set_draft_profile_photo_form', :multipart => true do %>
<p>
<label class="form_label" for="file_1"><%= _('Photo of you:')%></label>
- <%= file_field_tag :file, :size => 35, :id => 'file_1' %>
+ <% file_opts = { :size => 35, :id => 'file_1' } %>
+ <% file_opts.merge!({ :disabled => true }) if @user.banned? %>
+ <%= file_field_tag :file, file_opts %>
</p>
<ul>
diff --git a/app/views/user/set_profile_about_me.html.erb b/app/views/user/set_profile_about_me.html.erb
index fb7de7e97..42607ddf8 100644
--- a/app/views/user/set_profile_about_me.html.erb
+++ b/app/views/user/set_profile_about_me.html.erb
@@ -17,8 +17,12 @@
</div>
<p>
- <label class="form_label" for="set_profile_about_me"><%= _('About you:')%></label>
- <%= f.text_area :about_me, :rows => 5, :cols => 55 %>
+ <label class="form_label" for="set_profile_about_me">
+ <%= _('About you:')%>
+ </label>
+ <% about_me_opts = { :rows => 5, :cols => 55 } %>
+ <% about_me_opts.merge!({ :disabled => 'disabled' }) if @user.banned? %>
+ <%= f.text_area :about_me, about_me_opts %>
</p>
<div class="form_note">
diff --git a/app/views/user/show.html.erb b/app/views/user/show.html.erb
index 7c8d52568..78b513d6a 100644
--- a/app/views/user/show.html.erb
+++ b/app/views/user/show.html.erb
@@ -78,7 +78,7 @@
<% end %>
</p>
- <% if @display_user.public_banned? %>
+ <% if @display_user.banned? %>
<div id="user_public_banned">
<p>
<strong>
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index 413d395c5..443856cf3 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -1,6 +1,63 @@
# coding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+describe UserController do
+
+ describe :set_profile_photo do
+
+ context 'user is banned' do
+
+ before(:each) do
+ @user = FactoryGirl.create(:user, :ban_text => 'Causing trouble')
+ session[:user_id] = @user.id
+ @uploadedfile = fixture_file_upload("/files/parrot.png")
+
+ post :set_profile_photo, :id => @user.id,
+ :file => @uploadedfile,
+ :submitted_draft_profile_photo => 1,
+ :automatically_crop => 1
+ end
+
+ it 'redirects to the profile page' do
+ expect(response).to redirect_to(set_profile_photo_path)
+ end
+
+ it 'renders an error message' do
+ msg = 'Banned users cannot edit their profile'
+ expect(flash[:error]).to eq(msg)
+ end
+
+ end
+
+ end
+
+ describe :set_profile_about_me do
+
+ context 'user is banned' do
+
+ before(:each) do
+ @user = FactoryGirl.create(:user, :ban_text => 'Causing trouble')
+ session[:user_id] = @user.id
+
+ post :set_profile_about_me, :submitted_about_me => '1',
+ :about_me => 'Bad stuff'
+ end
+
+ it 'redirects to the profile page' do
+ expect(response).to redirect_to(set_profile_about_me_path)
+ end
+
+ it 'renders an error message' do
+ msg = 'Banned users cannot edit their profile'
+ expect(flash[:error]).to eq(msg)
+ end
+
+ end
+
+ end
+
+end
+
# TODO: Use route_for or params_from to check /c/ links better
# http://rspec.rubyforge.org/rspec-rails/1.1.12/classes/Spec/Rails/Example/ControllerExampleGroup.html
describe UserController, "when redirecting a show request to a canonical url" do
diff --git a/spec/models/about_me_validator_spec.rb b/spec/models/about_me_validator_spec.rb
new file mode 100644
index 000000000..5610cead8
--- /dev/null
+++ b/spec/models/about_me_validator_spec.rb
@@ -0,0 +1,53 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe AboutMeValidator do
+
+ describe :new do
+
+ it 'sets each supported attribute on the instance' do
+ params = { :about_me => 'My description' }
+ validator = AboutMeValidator.new(params)
+ expect(validator.about_me).to eq('My description')
+ end
+
+ end
+
+ describe :valid? do
+
+ it 'is valid if about_me is =< 500' do
+ params = { :about_me => 'a'*500 }
+ validator = AboutMeValidator.new(params)
+ expect(validator).to be_valid
+ end
+
+ it 'is valid if about_me is blank' do
+ params = { :about_me => '' }
+ validator = AboutMeValidator.new(params)
+ expect(validator).to be_valid
+ end
+
+ it 'is valid if about_me is nil' do
+ params = { :about_me => nil }
+ validator = AboutMeValidator.new(params)
+ expect(validator).to be_valid
+ end
+
+ it 'is invalid if about_me is > 500' do
+ params = { :about_me => 'a'*501 }
+ validator = AboutMeValidator.new(params)
+ expect(validator).to have(1).error_on(:about_me)
+ end
+
+ end
+
+ describe :about_me do
+
+ it 'has an attribute accessor' do
+ params = { :about_me => 'My description' }
+ validator = AboutMeValidator.new(params)
+ expect(validator.about_me).to eq('My description')
+ end
+
+ end
+
+end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 7dcd3ab8a..2245a024f 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -369,3 +369,21 @@ describe User, "when calculating if a user has exceeded the request limit" do
end
+
+describe User do
+
+ describe :banned? do
+
+ it 'is banned if the user has ban_text' do
+ user = FactoryGirl.build(:user, :ban_text => 'banned')
+ expect(user).to be_banned
+ end
+
+ it 'is not banned if the user has no ban_text' do
+ user = FactoryGirl.build(:user, :ban_text => '')
+ expect(user).to_not be_banned
+ end
+
+ end
+
+end