implements user name change requests
This commit is contained in:
@@ -464,9 +464,9 @@ class User < ActiveRecord::Base
|
||||
if is_platinum?
|
||||
nil
|
||||
elsif is_privileged?
|
||||
40_000
|
||||
else
|
||||
20_000
|
||||
else
|
||||
10_000
|
||||
end
|
||||
end
|
||||
|
||||
@@ -573,7 +573,7 @@ class User < ActiveRecord::Base
|
||||
if params[:id].present?
|
||||
q = q.where("id = ?", params[:id].to_i)
|
||||
end
|
||||
|
||||
|
||||
case params[:order]
|
||||
when "name"
|
||||
q = q.order("name")
|
||||
|
||||
@@ -4,13 +4,27 @@ class UserNameChangeRequest < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :approver, :class_name => "User"
|
||||
validate :uniqueness_of_desired_name
|
||||
validate :not_limited
|
||||
validates_length_of :desired_name, :within => 2..100, :on => :create
|
||||
validates_format_of :desired_name, :with => /\A[^\s:]+\Z/, :on => :create, :message => "cannot have whitespace or colons"
|
||||
before_validation :normalize_name
|
||||
after_create :notify_admins
|
||||
|
||||
def self.pending
|
||||
where(:status => "pending")
|
||||
end
|
||||
|
||||
def self.approved
|
||||
where(:status => "approved")
|
||||
end
|
||||
|
||||
def rejected?
|
||||
status == "rejected"
|
||||
end
|
||||
|
||||
def normalize_name
|
||||
self.desired_name = desired_name.strip.gsub(/ /, "_")
|
||||
end
|
||||
|
||||
def feedback
|
||||
UserFeedback.for_user(user_id).order("id desc").all
|
||||
@@ -29,6 +43,8 @@ class UserNameChangeRequest < ActiveRecord::Base
|
||||
user.update_attribute(:name, desired_name)
|
||||
body = "Your name change request has been approved. Be sure to log in with your new user name."
|
||||
Dmail.create_split(:title => "Name change request approved", :body => body, :to_id => user_id)
|
||||
UserFeedback.create(:user_id => user_id, :category => "neutral", :body => "Name changed from #{original_name} to #{desired_name}")
|
||||
ModAction.create(:description => "Name changed from #{original_name} to #{desired_name}")
|
||||
end
|
||||
|
||||
def reject!(reason)
|
||||
@@ -37,6 +53,15 @@ class UserNameChangeRequest < ActiveRecord::Base
|
||||
Dmail.create_split(:title => "Name change request rejected", :body => body, :to_id => user_id)
|
||||
end
|
||||
|
||||
def not_limited
|
||||
if UserNameChangeRequest.where("user_id = ? and created_at >= ?", CurrentUser.user.id, 1.week.ago).exists?
|
||||
errors.add(:base, "You can only submit one name change request per week")
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
def uniqueness_of_desired_name
|
||||
if User.find_by_name(desired_name)
|
||||
errors.add(:desired_name, "already exists")
|
||||
|
||||
Reference in New Issue
Block a user