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,7 +10,7 @@ module Merit | ||
10 | value: 1, | 10 | value: 1, |
11 | description: _('Comment author'), | 11 | description: _('Comment author'), |
12 | default_weight: 40, | 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 | comment_article_author: { | 15 | comment_article_author: { |
16 | action: 'comment#create', | 16 | action: 'comment#create', |
@@ -19,7 +19,7 @@ module Merit | @@ -19,7 +19,7 @@ module Merit | ||
19 | value: 1, | 19 | value: 1, |
20 | description: _('Article author of a comment'), | 20 | description: _('Article author of a comment'), |
21 | default_weight: 50, | 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 | comment_article: { | 24 | comment_article: { |
25 | action: 'comment#create', | 25 | action: 'comment#create', |
@@ -28,7 +28,7 @@ module Merit | @@ -28,7 +28,7 @@ module Merit | ||
28 | value: 1, | 28 | value: 1, |
29 | description: _('Source article of a comment'), | 29 | description: _('Source article of a comment'), |
30 | default_weight: 50, | 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 | comment_community: { | 33 | comment_community: { |
34 | action: 'comment#create', | 34 | action: 'comment#create', |
@@ -37,7 +37,8 @@ module Merit | @@ -37,7 +37,8 @@ module Merit | ||
37 | value: 1, | 37 | value: 1, |
38 | description: _('Article community of a comment'), | 38 | description: _('Article community of a comment'), |
39 | default_weight: 50, | 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 | article_author: { | 43 | article_author: { |
43 | action: 'article#create', | 44 | action: 'article#create', |
@@ -46,7 +47,7 @@ module Merit | @@ -46,7 +47,7 @@ module Merit | ||
46 | value: 1, | 47 | value: 1, |
47 | description: _('Article author'), | 48 | description: _('Article author'), |
48 | default_weight: 50, | 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 | article_community: { | 52 | article_community: { |
52 | action: 'article#create', | 53 | action: 'article#create', |
@@ -55,7 +56,8 @@ module Merit | @@ -55,7 +56,8 @@ module Merit | ||
55 | value: 1, | 56 | value: 1, |
56 | description: _('Article community'), | 57 | description: _('Article community'), |
57 | default_weight: 10, | 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 | vote_voteable_author: { | 62 | vote_voteable_author: { |
61 | action: 'vote#create', | 63 | action: 'vote#create', |
@@ -64,7 +66,7 @@ module Merit | @@ -64,7 +66,7 @@ module Merit | ||
64 | value: lambda {|vote| vote.vote}, | 66 | value: lambda {|vote| vote.vote}, |
65 | description: _('Author of a voted content'), | 67 | description: _('Author of a voted content'), |
66 | default_weight: 20, | 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 | vote_voteable: { | 71 | vote_voteable: { |
70 | action: 'vote#create', | 72 | action: 'vote#create', |
@@ -73,7 +75,7 @@ module Merit | @@ -73,7 +75,7 @@ module Merit | ||
73 | value: lambda {|vote| vote.vote}, | 75 | value: lambda {|vote| vote.vote}, |
74 | description: _('Voted content'), | 76 | description: _('Voted content'), |
75 | default_weight: 30, | 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 | vote_voter: { | 80 | vote_voter: { |
79 | action: 'vote#create', | 81 | action: 'vote#create', |
@@ -82,7 +84,7 @@ module Merit | @@ -82,7 +84,7 @@ module Merit | ||
82 | value: lambda {|vote| 1}, | 84 | value: lambda {|vote| 1}, |
83 | description: _('Voter'), | 85 | description: _('Voter'), |
84 | default_weight: 10, | 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 | friends: { | 89 | friends: { |
88 | action: 'friendship#create', | 90 | action: 'friendship#create', |
@@ -109,7 +111,7 @@ module Merit | @@ -109,7 +111,7 @@ module Merit | ||
109 | description: _('Follower'), | 111 | description: _('Follower'), |
110 | default_weight: 10, | 112 | default_weight: 10, |
111 | model: 'ArticleFollower', | 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 | followed_article: { | 116 | followed_article: { |
115 | action: 'articlefollower#create', | 117 | action: 'articlefollower#create', |
@@ -119,7 +121,7 @@ module Merit | @@ -119,7 +121,7 @@ module Merit | ||
119 | description: _('Article followed'), | 121 | description: _('Article followed'), |
120 | default_weight: 30, | 122 | default_weight: 30, |
121 | model: 'ArticleFollower', | 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 | followed_article_author: { | 126 | followed_article_author: { |
125 | action: 'articlefollower#create', | 127 | action: 'articlefollower#create', |
@@ -129,7 +131,7 @@ module Merit | @@ -129,7 +131,7 @@ module Merit | ||
129 | description: _('Author of a followed content'), | 131 | description: _('Author of a followed content'), |
130 | default_weight: 20, | 132 | default_weight: 20, |
131 | model: 'ArticleFollower', | 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,6 +149,10 @@ module Merit | ||
147 | end | 149 | end |
148 | end | 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 | def self.setup | 156 | def self.setup |
151 | AVAILABLE_RULES.map do |rule_name, rule| | 157 | AVAILABLE_RULES.map do |rule_name, rule| |
152 | point_type = GamificationPlugin::PointsType.find_by_name rule_name | 158 | point_type = GamificationPlugin::PointsType.find_by_name rule_name |
@@ -167,7 +173,7 @@ module Merit | @@ -167,7 +173,7 @@ module Merit | ||
167 | weight = categorization.weight | 173 | weight = categorization.weight |
168 | profile = categorization.profile | 174 | profile = categorization.profile |
169 | score lambda {|target| signal * calculate_score(target, weight, setting[:value])}, options do |target| | 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 | end | 177 | end |
172 | end | 178 | end |
173 | end | 179 | end |