Commit c9306125e630b9f77b61382afdc41a0ac5d2b093
1 parent
564beb33
Exists in
master
and in
1 other branch
Fix profile condition in point rules
Showing
1 changed file
with
19 additions
and
13 deletions
Show diff stats
lib/merit/point_rules.rb
| ... | ... | @@ -10,7 +10,7 @@ module Merit |
| 10 | 10 | value: 1, |
| 11 | 11 | description: _('Comment author'), |
| 12 | 12 | default_weight: 40, |
| 13 | - condition: lambda {|comment, profile| profile.nil? or comment.source.profile == profile}, | |
| 13 | + target_profile: lambda {|comment| comment.source.profile }, | |
| 14 | 14 | }, |
| 15 | 15 | comment_article_author: { |
| 16 | 16 | action: 'comment#create', |
| ... | ... | @@ -19,7 +19,7 @@ module Merit |
| 19 | 19 | value: 1, |
| 20 | 20 | description: _('Article author of a comment'), |
| 21 | 21 | default_weight: 50, |
| 22 | - condition: lambda {|comment, profile| profile.nil? or comment.source.profile == profile}, | |
| 22 | + target_profile: lambda {|comment| comment.source.profile }, | |
| 23 | 23 | }, |
| 24 | 24 | comment_article: { |
| 25 | 25 | action: 'comment#create', |
| ... | ... | @@ -28,7 +28,7 @@ module Merit |
| 28 | 28 | value: 1, |
| 29 | 29 | description: _('Source article of a comment'), |
| 30 | 30 | default_weight: 50, |
| 31 | - condition: lambda {|comment, profile| profile.nil? or comment.source.profile == profile}, | |
| 31 | + target_profile: lambda {|comment| comment.source.profile }, | |
| 32 | 32 | }, |
| 33 | 33 | comment_community: { |
| 34 | 34 | action: 'comment#create', |
| ... | ... | @@ -37,7 +37,8 @@ module Merit |
| 37 | 37 | value: 1, |
| 38 | 38 | description: _('Article community of a comment'), |
| 39 | 39 | default_weight: 50, |
| 40 | - condition: lambda {|comment, profile| profile.nil? or (comment.profile.community? and comment.profile == profile) } | |
| 40 | + target_profile: lambda {|comment| comment.source.profile }, | |
| 41 | + condition: lambda {|comment, profile| comment.profile.community?} | |
| 41 | 42 | }, |
| 42 | 43 | article_author: { |
| 43 | 44 | action: 'article#create', |
| ... | ... | @@ -46,7 +47,7 @@ module Merit |
| 46 | 47 | value: 1, |
| 47 | 48 | description: _('Article author'), |
| 48 | 49 | default_weight: 50, |
| 49 | - condition: lambda {|article, profile| profile.nil? or article.profile == profile}, | |
| 50 | + target_profile: lambda {|article| article.profile }, | |
| 50 | 51 | }, |
| 51 | 52 | article_community: { |
| 52 | 53 | action: 'article#create', |
| ... | ... | @@ -55,7 +56,8 @@ module Merit |
| 55 | 56 | value: 1, |
| 56 | 57 | description: _('Article community'), |
| 57 | 58 | default_weight: 10, |
| 58 | - condition: lambda {|article, profile| profile.nil? or (article.profile.present? and article.profile.community? and article.profile == profile) } | |
| 59 | + target_profile: lambda {|article| article.profile }, | |
| 60 | + condition: lambda {|article, profile| article.profile.present? and article.profile.community? } | |
| 59 | 61 | }, |
| 60 | 62 | vote_voteable_author: { |
| 61 | 63 | action: 'vote#create', |
| ... | ... | @@ -64,7 +66,7 @@ module Merit |
| 64 | 66 | value: lambda {|vote| vote.vote}, |
| 65 | 67 | description: _('Author of a voted content'), |
| 66 | 68 | default_weight: 20, |
| 67 | - condition: lambda {|vote, profile| profile.nil? or (vote.voteable and vote.voteable.profile == profile) } | |
| 69 | + target_profile: lambda {|vote| vote.voteable.present? ? vote.voteable.profile : nil }, | |
| 68 | 70 | }, |
| 69 | 71 | vote_voteable: { |
| 70 | 72 | action: 'vote#create', |
| ... | ... | @@ -73,7 +75,7 @@ module Merit |
| 73 | 75 | value: lambda {|vote| vote.vote}, |
| 74 | 76 | description: _('Voted content'), |
| 75 | 77 | default_weight: 30, |
| 76 | - condition: lambda {|vote, profile| profile.nil? or (vote.voteable and vote.voteable.profile == profile) } | |
| 78 | + target_profile: lambda {|vote| vote.voteable.present? ? vote.voteable.profile : nil }, | |
| 77 | 79 | }, |
| 78 | 80 | vote_voter: { |
| 79 | 81 | action: 'vote#create', |
| ... | ... | @@ -82,7 +84,7 @@ module Merit |
| 82 | 84 | value: lambda {|vote| 1}, |
| 83 | 85 | description: _('Voter'), |
| 84 | 86 | default_weight: 10, |
| 85 | - condition: lambda {|vote, profile| profile.nil? or (vote.voteable and vote.voteable.profile == profile) } | |
| 87 | + target_profile: lambda {|vote| vote.voteable.present? ? vote.voteable.profile : nil }, | |
| 86 | 88 | }, |
| 87 | 89 | friends: { |
| 88 | 90 | action: 'friendship#create', |
| ... | ... | @@ -109,7 +111,7 @@ module Merit |
| 109 | 111 | description: _('Follower'), |
| 110 | 112 | default_weight: 10, |
| 111 | 113 | model: 'ArticleFollower', |
| 112 | - condition: lambda {|follow, profile| profile.nil? or follow.article.profile == profile }, | |
| 114 | + target_profile: lambda {|follow| follow.article.profile }, | |
| 113 | 115 | }, |
| 114 | 116 | followed_article: { |
| 115 | 117 | action: 'articlefollower#create', |
| ... | ... | @@ -119,7 +121,7 @@ module Merit |
| 119 | 121 | description: _('Article followed'), |
| 120 | 122 | default_weight: 30, |
| 121 | 123 | model: 'ArticleFollower', |
| 122 | - condition: lambda {|follow, profile| profile.nil? or follow.article.profile == profile }, | |
| 124 | + target_profile: lambda {|follow| follow.article.profile }, | |
| 123 | 125 | }, |
| 124 | 126 | followed_article_author: { |
| 125 | 127 | action: 'articlefollower#create', |
| ... | ... | @@ -129,7 +131,7 @@ module Merit |
| 129 | 131 | description: _('Author of a followed content'), |
| 130 | 132 | default_weight: 20, |
| 131 | 133 | model: 'ArticleFollower', |
| 132 | - condition: lambda {|follow, profile| profile.nil? or follow.article.profile == profile }, | |
| 134 | + target_profile: lambda {|follow| follow.article.profile }, | |
| 133 | 135 | } |
| 134 | 136 | } |
| 135 | 137 | |
| ... | ... | @@ -147,6 +149,10 @@ module Merit |
| 147 | 149 | end |
| 148 | 150 | end |
| 149 | 151 | |
| 152 | + def profile_condition(setting, target, profile) | |
| 153 | + profile.nil? || setting[:target_profile].blank? || setting[:target_profile].call(target) == profile | |
| 154 | + end | |
| 155 | + | |
| 150 | 156 | def self.setup |
| 151 | 157 | AVAILABLE_RULES.map do |rule_name, rule| |
| 152 | 158 | point_type = GamificationPlugin::PointsType.find_by_name rule_name |
| ... | ... | @@ -167,7 +173,7 @@ module Merit |
| 167 | 173 | weight = categorization.weight |
| 168 | 174 | profile = categorization.profile |
| 169 | 175 | score lambda {|target| signal * calculate_score(target, weight, setting[:value])}, options do |target| |
| 170 | - condition(setting, target, profile) | |
| 176 | + profile_condition(setting, target, profile) && condition(setting, target, profile) | |
| 171 | 177 | end |
| 172 | 178 | end |
| 173 | 179 | end | ... | ... |