users with no negative feedback can now change their names

This commit is contained in:
albert
2011-12-20 16:18:35 -05:00
parent 30fb0b660c
commit 5e3b243b67
6 changed files with 48 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
class UsersController < ApplicationController
respond_to :html, :xml, :json
before_filter :member_only, :only => [:edit, :update]
before_filter :member_only, :only => [:edit, :update, :upgrade]
rescue_from User::PrivilegeError, :with => "static/access_denied"
def new
@@ -53,6 +53,12 @@ class UsersController < ApplicationController
redirect_to user_path(@user), :notice => "Email was sent"
end
def cache
@user = User.find(params[:id])
@user.update_cache
render :nothing => true
end
private
def check_privilege(user)

View File

@@ -9,8 +9,7 @@ class PopularPostExplorer
private
def load_posts
# Post.tag_match("order:rank").where("image_width >= ?", Danbooru.config.medium_image_width).limit(5).offset(offset)
@posts = Post.where("image_width >= ?", Danbooru.config.medium_image_width).limit(50)
Post.tag_match("order:rank").where("image_width >= ?", Danbooru.config.medium_image_width).limit(5).offset(offset)
end
def sort_posts

View File

@@ -25,10 +25,12 @@ class User < ActiveRecord::Base
validates_confirmation_of :password
validates_presence_of :email, :if => lambda {|rec| rec.new_record? && Danbooru.config.enable_email_verification?}
validate :validate_ip_addr_is_not_banned, :on => :create
validate :validate_feedback_on_name_change, :on => :update
before_validation :normalize_blacklisted_tags
before_create :encrypt_password_on_create
before_update :encrypt_password_on_update
after_save :update_cache
after_update :update_remote_cache
before_create :promote_to_admin_if_first_user
has_many :feedback, :class_name => "UserFeedback", :dependent => :destroy
has_many :posts, :foreign_key => "uploader_id"
@@ -71,7 +73,7 @@ class User < ActiveRecord::Base
module ClassMethods
def name_to_id(name)
Cache.get("uni:#{Cache.sanitize(name)}") do
Cache.get("uni:#{Cache.sanitize(name)}", 1.hour) do
select_value_sql("SELECT id FROM users WHERE lower(name) = ?", name.downcase)
end
end
@@ -98,6 +100,21 @@ class User < ActiveRecord::Base
def update_cache
Cache.put("uin:#{id}", name)
end
def update_remote_cache
if name_changed?
Danbooru.config.other_server_hosts.each do |server|
Net::HTTP.delete(URI.parse("http://#{server}/users/#{id}/cache"))
end
end
end
def validate_feedback_on_name_change
if feedback.negative.count > 0 && name_changed?
self.errors[:base] << "You can not change your name if you have any negative feedback"
return false
end
end
end
module PasswordMethods

View File

@@ -4,11 +4,14 @@
<%= simple_form_for @user do |f| %>
<fieldset>
<% if @user.feedback.negative.count == 0 %>
<%= f.input :name %>
<% end %>
<%= f.input :email, :required => Danbooru.config.enable_email_verification?, :hint => "Used for messages and for password resets", :as => :email %>
<%= f.input :time_zone %>
<%= f.input :receive_email_notifications %>
<%= f.input :comment_threshold, :hint => "Comments below this score will be hidden by default" %>
<%= f.input :always_resize_images, :hint => "Automatically resize images to fit your browser window" %>
<%= f.input :default_image_size, :hint => "Medium shows images resized to #{Danbooru.config.medium_image_width} pixels wide, large is #{Danbooru.config.large_image_width} pixels wide, and original is whatever the original image is", :collection => %w(medium large original), :include_blank => false %>
<%= f.input :favorite_tags, :hint => "A list of whitespace delimited tags that show up in your profile", :input_html => {:size => "40x5"} %>
<%= f.input :blacklisted_tags, :hint => "A list of newline delimited tags that you never want to see", :input_html => {:size => "40x5"} %>

View File

@@ -158,6 +158,7 @@ Danbooru::Application.routes.draw do
end
member do
delete :cache
post :upgrade
end
end
@@ -171,7 +172,7 @@ Danbooru::Application.routes.draw do
end
end
resources :wiki_page_versions, :only => [:index, :show]
# aliases
resources :wpages, :controller => "wiki_pages"
resources :ftopics, :controller => "forum_topics"

View File

@@ -31,6 +31,22 @@ class UserTest < ActiveSupport::TestCase
assert_equal(User::Levels::MEMBER, @user.level)
end
end
context "who has negeative feedback and is trying to change their name" do
setup do
@mod = Factory.create(:moderator_user)
CurrentUser.scoped(@mod, "127.0.0.1") do
Factory.create(:user_feedback, :user => @user, :category => "negative")
end
end
should "not validate" do
@user.reload
@user.update_attributes(:name => "fanfarlo")
assert_equal(["You can not change your name if you have any negative feedback"], @user.errors.full_messages)
end
end
should "not validate if the originating ip address is banned" do
Factory.create(:ip_ban)