push code, add score.
This commit is contained in:
parent
6bd71ce9f1
commit
5bc20cf6af
|
@ -18,6 +18,9 @@
|
||||||
class Changeset < ActiveRecord::Base
|
class Changeset < ActiveRecord::Base
|
||||||
belongs_to :repository
|
belongs_to :repository
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
|
after_save :be_user_score # user_score
|
||||||
|
|
||||||
has_many :filechanges, :class_name => 'Change', :dependent => :delete_all
|
has_many :filechanges, :class_name => 'Change', :dependent => :delete_all
|
||||||
# fq
|
# fq
|
||||||
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
|
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
|
||||||
|
@ -292,4 +295,14 @@ class Changeset < ActiveRecord::Base
|
||||||
def self.to_utf8(str, encoding)
|
def self.to_utf8(str, encoding)
|
||||||
Redmine::CodesetUtil.to_utf8(str, encoding)
|
Redmine::CodesetUtil.to_utf8(str, encoding)
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -126,9 +126,12 @@ class UserScore < ActiveRecord::Base
|
||||||
# Returns boolean. 返回积分保存结果
|
# Returns boolean. 返回积分保存结果
|
||||||
def self.project(operate, current_user, options={})
|
def self.project(operate, current_user, options={})
|
||||||
current_user, target_user = get_users(current_user, nil)
|
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
|
case operate
|
||||||
when :push_code # current_user 提交了代码
|
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})"
|
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
|
when :push_document # current_user
|
||||||
user_score.active = user_score.active.to_i + 4
|
user_score.active = user_score.active.to_i + 4
|
||||||
|
|
Loading…
Reference in New Issue