Commit f0f12c2a4c704b10c8568aa85057ce7739bde320
1 parent
53a8b04d
Exists in
master
and in
1 other branch
Fix article_follower badge pontuation
Showing
3 changed files
with
20 additions
and
15 deletions
Show diff stats
lib/ext/article_follower.rb
lib/merit/badge_rules.rb
... | ... | @@ -81,9 +81,10 @@ module Merit |
81 | 81 | ], |
82 | 82 | observer: [ |
83 | 83 | { |
84 | - action: 'article_follower#create', | |
84 | + action: 'articlefollower#create', | |
85 | 85 | default_threshold: 5, |
86 | 86 | to: lambda {|article| article.person }, |
87 | + model: 'ArticleFollower', | |
87 | 88 | value: lambda { |article, person| person.present? ? person.article_followers.count : 0 } |
88 | 89 | } |
89 | 90 | ], |
... | ... | @@ -117,9 +118,10 @@ module Merit |
117 | 118 | ], |
118 | 119 | articulator: [ |
119 | 120 | { |
120 | - action: 'article_follower#create', | |
121 | + action: 'articlefollower#create', | |
121 | 122 | default_threshold: 5, |
122 | 123 | to: :person, |
124 | + model: 'ArticleFollower', | |
123 | 125 | value: lambda { |article_follower, person| person.present? ? person.article_followers.count : 0 } |
124 | 126 | }, |
125 | 127 | { |
... | ... | @@ -128,7 +130,6 @@ module Merit |
128 | 130 | to: :author, |
129 | 131 | value: lambda { |comment, author| author.present? ? author.comments.count : 0 } |
130 | 132 | }, |
131 | - #mobilizer#create | |
132 | 133 | ] |
133 | 134 | } |
134 | 135 | |
... | ... | @@ -142,7 +143,9 @@ module Merit |
142 | 143 | environment.gamification_plugin_badges.all.each do |badge| |
143 | 144 | next if rules[badge.name.to_sym].nil? |
144 | 145 | rules[badge.name.to_sym].each do |setting| |
145 | - grant_on setting[:action], badge: badge.name, level: badge.level, to: setting[:to] do |source| | |
146 | + options = {badge: badge.name, level: badge.level, to: setting[:to]} | |
147 | + options[:model_name] = setting[:model] unless setting[:model].nil? | |
148 | + grant_on setting[:action], options do |source| | |
146 | 149 | can_be_granted = true |
147 | 150 | rules[badge.name.to_sym].each do |s| |
148 | 151 | if setting[:to].is_a? Symbol | ... | ... |
lib/merit/point_rules.rb
... | ... | @@ -107,23 +107,25 @@ module Merit |
107 | 107 | profile_action: false |
108 | 108 | }, |
109 | 109 | follower: { |
110 | - action: 'follow#create', | |
111 | - undo_action: 'follow#destroy', | |
112 | - to: lambda {|follow| follow.profile }, | |
110 | + action: 'articlefollower#create', | |
111 | + undo_action: 'articlefollower#destroy', | |
112 | + to: :person, | |
113 | 113 | value: 1, |
114 | 114 | description: _('Follower'), |
115 | 115 | default_weight: 10, |
116 | - condition: lambda {|follow, profile| profile.nil? or follow.source.profile == profile }, | |
116 | + model: 'ArticleFollower', | |
117 | + condition: lambda {|follow, profile| profile.nil? or follow.article.profile == profile }, | |
117 | 118 | profile_action: true |
118 | 119 | }, |
119 | 120 | followed_article_author: { |
120 | - action: 'follow#create', | |
121 | - undo_action: 'follow#destroy', | |
122 | - to: lambda {|follow| follow.source.author }, | |
121 | + action: 'articlefollower#create', | |
122 | + undo_action: 'articlefollower#destroy', | |
123 | + to: lambda {|follow| follow.article.author }, | |
123 | 124 | value: 1, |
124 | 125 | description: _('Followed'), |
125 | 126 | default_weight: 20, |
126 | - condition: lambda {|follow, profile| profile.nil? or follow.source.profile == profile }, | |
127 | + model: 'ArticleFollower', | |
128 | + condition: lambda {|follow, profile| profile.nil? or follow.article.profile == profile }, | |
127 | 129 | profile_action: true |
128 | 130 | }, |
129 | 131 | #mobilizer: { |
... | ... | @@ -183,8 +185,9 @@ module Merit |
183 | 185 | AVAILABLE_RULES.each do |point_type, setting| |
184 | 186 | GamificationPlugin::PointsCategorization.for_type(point_type).includes(:profile).each do |categorization| |
185 | 187 | [setting[:action], setting[:undo_action]].compact.zip([1, -1]).each do |action, signal| |
186 | - block = lambda {|target| signal * calculate_score(target, categorization.weight, setting[:value])} | |
187 | - score block, on: action, to: setting[:to], category: categorization.id.to_s do |target| | |
188 | + options = {on: action, to: setting[:to], category: categorization.id.to_s} | |
189 | + options[:model_name] = setting[:model] unless setting[:model].nil? | |
190 | + score lambda {|target| signal * calculate_score(target, categorization.weight, setting[:value])}, options do |target| | |
188 | 191 | condition(setting, target, categorization.profile) |
189 | 192 | end |
190 | 193 | end | ... | ... |