push code, add score.

This commit is contained in:
yanxd 2014-06-09 13:52:21 +08:00
parent 6bd71ce9f1
commit 5bc20cf6af
2 changed files with 17 additions and 1 deletions

View File

@ -18,6 +18,9 @@
class Changeset < ActiveRecord::Base
belongs_to :repository
belongs_to :user
after_save :be_user_score # user_score
has_many :filechanges, :class_name => 'Change', :dependent => :delete_all
# fq
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
@ -292,4 +295,14 @@ class Changeset < ActiveRecord::Base
def self.to_utf8(str, encoding)
Redmine::CodesetUtil.to_utf8(str, encoding)
end
private
# update user score
def be_user_score
if self.new_record?
UserScore.project(:push_code, self.user, { changeset_id: self.id })
end
end
end

View File

@ -126,9 +126,12 @@ class UserScore < ActiveRecord::Base
# Returns boolean. 返回积分保存结果
def self.project(operate, current_user, options={})
current_user, target_user = get_users(current_user, nil)
user_score = current_user.user_score_attr
user_score = current_user.try(:user_score_attr)
return false if current_user.nil?
case operate
when :push_code # current_user 提交了代码
user_score = user_score.active.to_i + 4
user_score.save
Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed code one time. options => (#{options.to_s})"
when :push_document # current_user
user_score.active = user_score.active.to_i + 4