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,9 +81,10 @@ module Merit | ||
81 | ], | 81 | ], |
82 | observer: [ | 82 | observer: [ |
83 | { | 83 | { |
84 | - action: 'article_follower#create', | 84 | + action: 'articlefollower#create', |
85 | default_threshold: 5, | 85 | default_threshold: 5, |
86 | to: lambda {|article| article.person }, | 86 | to: lambda {|article| article.person }, |
87 | + model: 'ArticleFollower', | ||
87 | value: lambda { |article, person| person.present? ? person.article_followers.count : 0 } | 88 | value: lambda { |article, person| person.present? ? person.article_followers.count : 0 } |
88 | } | 89 | } |
89 | ], | 90 | ], |
@@ -117,9 +118,10 @@ module Merit | @@ -117,9 +118,10 @@ module Merit | ||
117 | ], | 118 | ], |
118 | articulator: [ | 119 | articulator: [ |
119 | { | 120 | { |
120 | - action: 'article_follower#create', | 121 | + action: 'articlefollower#create', |
121 | default_threshold: 5, | 122 | default_threshold: 5, |
122 | to: :person, | 123 | to: :person, |
124 | + model: 'ArticleFollower', | ||
123 | value: lambda { |article_follower, person| person.present? ? person.article_followers.count : 0 } | 125 | value: lambda { |article_follower, person| person.present? ? person.article_followers.count : 0 } |
124 | }, | 126 | }, |
125 | { | 127 | { |
@@ -128,7 +130,6 @@ module Merit | @@ -128,7 +130,6 @@ module Merit | ||
128 | to: :author, | 130 | to: :author, |
129 | value: lambda { |comment, author| author.present? ? author.comments.count : 0 } | 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,7 +143,9 @@ module Merit | ||
142 | environment.gamification_plugin_badges.all.each do |badge| | 143 | environment.gamification_plugin_badges.all.each do |badge| |
143 | next if rules[badge.name.to_sym].nil? | 144 | next if rules[badge.name.to_sym].nil? |
144 | rules[badge.name.to_sym].each do |setting| | 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 | can_be_granted = true | 149 | can_be_granted = true |
147 | rules[badge.name.to_sym].each do |s| | 150 | rules[badge.name.to_sym].each do |s| |
148 | if setting[:to].is_a? Symbol | 151 | if setting[:to].is_a? Symbol |
lib/merit/point_rules.rb
@@ -107,23 +107,25 @@ module Merit | @@ -107,23 +107,25 @@ module Merit | ||
107 | profile_action: false | 107 | profile_action: false |
108 | }, | 108 | }, |
109 | follower: { | 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 | value: 1, | 113 | value: 1, |
114 | description: _('Follower'), | 114 | description: _('Follower'), |
115 | default_weight: 10, | 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 | profile_action: true | 118 | profile_action: true |
118 | }, | 119 | }, |
119 | followed_article_author: { | 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 | value: 1, | 124 | value: 1, |
124 | description: _('Followed'), | 125 | description: _('Followed'), |
125 | default_weight: 20, | 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 | profile_action: true | 129 | profile_action: true |
128 | }, | 130 | }, |
129 | #mobilizer: { | 131 | #mobilizer: { |
@@ -183,8 +185,9 @@ module Merit | @@ -183,8 +185,9 @@ module Merit | ||
183 | AVAILABLE_RULES.each do |point_type, setting| | 185 | AVAILABLE_RULES.each do |point_type, setting| |
184 | GamificationPlugin::PointsCategorization.for_type(point_type).includes(:profile).each do |categorization| | 186 | GamificationPlugin::PointsCategorization.for_type(point_type).includes(:profile).each do |categorization| |
185 | [setting[:action], setting[:undo_action]].compact.zip([1, -1]).each do |action, signal| | 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 | condition(setting, target, categorization.profile) | 191 | condition(setting, target, categorization.profile) |
189 | end | 192 | end |
190 | end | 193 | end |