diff --git a/app/models/changeset.rb b/app/models/changeset.rb index e3e7ac705..93248850b 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -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 diff --git a/app/models/user_score.rb b/app/models/user_score.rb index 662229fad..c306dbf1c 100644 --- a/app/models/user_score.rb +++ b/app/models/user_score.rb @@ -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