|
|
|
@ -122,6 +122,10 @@ class User < Principal
|
|
|
|
|
#####
|
|
|
|
|
has_many :shares ,:dependent => :destroy
|
|
|
|
|
|
|
|
|
|
# add by zjc
|
|
|
|
|
has_one :level, :class_name => 'UserLevels', :dependent => :destroy
|
|
|
|
|
has_many :memos , :foreign_key => 'author_id'
|
|
|
|
|
#####
|
|
|
|
|
scope :logged, lambda { where("#{User.table_name}.status <> #{STATUS_ANONYMOUS}") }
|
|
|
|
|
scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) }
|
|
|
|
|
scope :visible, lambda {|*args|
|
|
|
|
@ -876,6 +880,63 @@ class User < Principal
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#获取user的等级 -by zjc
|
|
|
|
|
def get_level
|
|
|
|
|
if self.level.nil?
|
|
|
|
|
update_user_level
|
|
|
|
|
end
|
|
|
|
|
self.level.level
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#更新用户等级 - by zjc
|
|
|
|
|
def update_user_level
|
|
|
|
|
user_level = UserLevels.new
|
|
|
|
|
user_level.user = self
|
|
|
|
|
|
|
|
|
|
#判断user的等级
|
|
|
|
|
pis = self.project_infos #ProjectInfo.find_all_by_user_id(self.id)
|
|
|
|
|
isManager = false;
|
|
|
|
|
pis.each do |pi|
|
|
|
|
|
#判断是否为项目管理员
|
|
|
|
|
if self.allowed_to?({:controller => "projects", :action => "edit"}, pi.project)
|
|
|
|
|
isManager = true;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
has_effective_praise_count = false;
|
|
|
|
|
self.messages.each do |message|
|
|
|
|
|
if message.parent_id.nil?
|
|
|
|
|
ptcs = PraiseTreadCache.find_all_by_object_id(message.id)
|
|
|
|
|
ptcs.each do |ptc|
|
|
|
|
|
if ptc.object_type == 'Message' && ptc.praise_num.to_i > 5
|
|
|
|
|
has_effective_praise_count = true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if !has_effective_praise_count
|
|
|
|
|
self.memos do |memo|
|
|
|
|
|
if memo.parent_id.nil?
|
|
|
|
|
ptcs = PraiseTreadCache.find_all_by_object_id(memo.id)
|
|
|
|
|
ptcs.each do |ptc|
|
|
|
|
|
if ptc.object_type == 'Memo' && ptc.praise_num > 5
|
|
|
|
|
has_effective_praise_count = true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if isManager || self.changesets.count > 100
|
|
|
|
|
user_level.level = 3
|
|
|
|
|
elsif (self.changesets.count > 1 && self.changesets.count <= 100) || has_effective_praise_count
|
|
|
|
|
user_level.level = 2
|
|
|
|
|
else
|
|
|
|
|
user_level.level = 1
|
|
|
|
|
end
|
|
|
|
|
user_level.save
|
|
|
|
|
self.reload
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
|
|
def validate_password_length
|
|
|
|
@ -884,7 +945,6 @@ class User < Principal
|
|
|
|
|
errors.add(:password, :too_short, :count => Setting.password_min_length.to_i)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def act_as_activity
|
|
|
|
@ -926,6 +986,8 @@ class User < Principal
|
|
|
|
|
Redmine::Utils.random_hex(16)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
class AnonymousUser < User
|
|
|
|
|