Commit e647c029db9165f0abf0e86d6360a87a2416138f

Authored by Hugo Melo
1 parent 696c40b4

Adjust rules for generic pontuation

lib/merit/badge_rules.rb
@@ -14,7 +14,7 @@ module Merit @@ -14,7 +14,7 @@ module Merit
14 action: 'comment#create', 14 action: 'comment#create',
15 default_threshold: 5, 15 default_threshold: 5,
16 to: :author, 16 to: :author,
17 - value: lambda { |comment, author| author.present? ? author.conference_comments.count : 0 } 17 + value: lambda { |comment, author| author.present? ? author.comments.count : 0 }
18 } 18 }
19 ], 19 ],
20 comment_received: [ 20 comment_received: [
@@ -22,7 +22,7 @@ module Merit @@ -22,7 +22,7 @@ module Merit
22 action: 'comment#create', 22 action: 'comment#create',
23 default_threshold: 5, 23 default_threshold: 5,
24 to: lambda {|comment| comment.source.author}, 24 to: lambda {|comment| comment.source.author},
25 - value: lambda { |comment, author| author.present? ? Comment.where(source_id: Article.conference_articles.where(author_id: author.id)).count : 0 } 25 + value: lambda { |comment, author| author.present? ? Comment.where(source_id: Article.where(author_id: author.id)).count : 0 }
26 } 26 }
27 ], 27 ],
28 article_author: [ 28 article_author: [
@@ -30,7 +30,7 @@ module Merit @@ -30,7 +30,7 @@ module Merit
30 action: 'article#create', 30 action: 'article#create',
31 default_threshold: 5, 31 default_threshold: 5,
32 to: :author, 32 to: :author,
33 - value: lambda { |article, author| author.present? ? TextArticle.conference_articles.comments.where(author_id: author.id).count : 0 } 33 + value: lambda { |article, author| author.present? ? TextArticle.where(author_id: author.id).count : 0 }
34 }, 34 },
35 ], 35 ],
36 positive_votes_received: [ 36 positive_votes_received: [
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| comment.source.profile == profile}, 13 + condition: lambda {|comment, profile| profile.nil? or comment.source.profile == 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| comment.source.profile == profile}, 22 + condition: lambda {|comment, profile| profile.nil? or comment.source.profile == 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| comment.source.profile == profile}, 31 + condition: lambda {|comment, profile| profile.nil? or comment.source.profile == profile},
32 }, 32 },
33 comment_community: { 33 comment_community: {
34 action: 'comment#create', 34 action: 'comment#create',
@@ -37,7 +37,7 @@ module Merit @@ -37,7 +37,7 @@ 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| comment.profile.community? and comment.profile == profile } 40 + condition: lambda {|comment, profile| profile.nil? or (comment.profile.community? and comment.profile == profile) }
41 }, 41 },
42 article_author: { 42 article_author: {
43 action: 'article#create', 43 action: 'article#create',
@@ -45,8 +45,8 @@ module Merit @@ -45,8 +45,8 @@ module Merit
45 to: :author, 45 to: :author,
46 value: 1, 46 value: 1,
47 description: _('Article author'), 47 description: _('Article author'),
48 - default_weight: 10,  
49 - condition: lambda {|article, profile| article.profile == profile}, 48 + default_weight: 50,
  49 + condition: lambda {|article, profile| profile.nil? or article.profile == profile},
50 }, 50 },
51 article_community: { 51 article_community: {
52 action: 'article#create', 52 action: 'article#create',
@@ -55,7 +55,7 @@ module Merit @@ -55,7 +55,7 @@ module Merit
55 value: 1, 55 value: 1,
56 description: _('Article community'), 56 description: _('Article community'),
57 default_weight: 10, 57 default_weight: 10,
58 - condition: lambda {|article, profile| article.profile.present? and article.profile.community? and article.profile == profile } 58 + condition: lambda {|article, profile| profile.nil? or (article.profile.present? and article.profile.community? and article.profile == profile) }
59 }, 59 },
60 vote_voteable_author: { 60 vote_voteable_author: {
61 action: 'vote#create', 61 action: 'vote#create',
@@ -65,7 +65,7 @@ module Merit @@ -65,7 +65,7 @@ module Merit
65 value: lambda {|vote| vote.vote}, 65 value: lambda {|vote| vote.vote},
66 description: _('Author of a voted content'), 66 description: _('Author of a voted content'),
67 default_weight: 20, 67 default_weight: 20,
68 - condition: lambda {|vote, profile| vote.voteable.profile == profile } 68 + condition: lambda {|vote, profile| profile.nil? or vote.voteable.profile == profile }
69 }, 69 },
70 vote_voteable: { 70 vote_voteable: {
71 action: 'vote#create', 71 action: 'vote#create',
@@ -75,7 +75,7 @@ module Merit @@ -75,7 +75,7 @@ module Merit
75 value: lambda {|vote| vote.vote}, 75 value: lambda {|vote| vote.vote},
76 description: _('Voted content'), 76 description: _('Voted content'),
77 default_weight: 30, 77 default_weight: 30,
78 - condition: lambda {|vote, profile| vote.voteable.profile == profile } 78 + condition: lambda {|vote, profile| profile.nil? or vote.voteable.profile == profile }
79 }, 79 },
80 vote_voter: { 80 vote_voter: {
81 action: 'vote#create', 81 action: 'vote#create',
@@ -84,7 +84,7 @@ module Merit @@ -84,7 +84,7 @@ module Merit
84 value: lambda {|vote| 1}, 84 value: lambda {|vote| 1},
85 description: _('Voter'), 85 description: _('Voter'),
86 default_weight: 10, 86 default_weight: 10,
87 - condition: lambda {|vote, profile| vote.voteable.profile == profile } 87 + condition: lambda {|vote, profile| profile.nil? or vote.voteable.profile == profile }
88 }, 88 },
89 friends: { 89 friends: {
90 action: 'friendship#create', 90 action: 'friendship#create',
@@ -113,7 +113,7 @@ module Merit @@ -113,7 +113,7 @@ module Merit
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| follow.source.profile == profile }, 116 + condition: lambda {|follow, profile| profile.nil? or follow.source.profile == profile },
117 profile_action: true 117 profile_action: true
118 }, 118 },
119 followed_article_author: { 119 followed_article_author: {
@@ -123,7 +123,7 @@ module Merit @@ -123,7 +123,7 @@ module Merit
123 value: 1, 123 value: 1,
124 description: _('Followed'), 124 description: _('Followed'),
125 default_weight: 20, 125 default_weight: 20,
126 - condition: lambda {|follow, profile| follow.source.profile == profile }, 126 + condition: lambda {|follow, profile| profile.nil? or follow.source.profile == profile },
127 profile_action: true 127 profile_action: true
128 }, 128 },
129 #mobilizer: { 129 #mobilizer: {
@@ -133,7 +133,7 @@ module Merit @@ -133,7 +133,7 @@ module Merit
133 #value: 1, 133 #value: 1,
134 #description: _('Mobilized Article Author'), 134 #description: _('Mobilized Article Author'),
135 #default_weight: 60, 135 #default_weight: 60,
136 - #condition: lambda {|target, profile| target.source.profile == profile }, 136 + #condition: lambda {|target, profile| profile.nil? or target.source.profile == profile },
137 #profile_action: true 137 #profile_action: true
138 #}, 138 #},
139 #mobilized_article_author: { 139 #mobilized_article_author: {
@@ -143,7 +143,7 @@ module Merit @@ -143,7 +143,7 @@ module Merit
143 #value: 1, 143 #value: 1,
144 #description: _('Mobilized Article Author'), 144 #description: _('Mobilized Article Author'),
145 #default_weight: 70, 145 #default_weight: 70,
146 - #condition: lambda {|follow, profile| follow.source.profile == profile }, 146 + #condition: lambda {|follow, profile| profile.nil? or follow.source.profile == profile },
147 #profile_action: true 147 #profile_action: true
148 #}, 148 #},
149 #mobilized_article: { 149 #mobilized_article: {
@@ -153,7 +153,7 @@ module Merit @@ -153,7 +153,7 @@ module Merit
153 #value: 1, 153 #value: 1,
154 #description: _('Mobilized Article Author'), 154 #description: _('Mobilized Article Author'),
155 #default_weight: 70, 155 #default_weight: 70,
156 - #condition: lambda {|follow, profile| follow.source.profile == profile }, 156 + #condition: lambda {|follow, profile| profile.nil? or follow.source.profile == profile },
157 #profile_action: true 157 #profile_action: true
158 #} 158 #}
159 } 159 }
@@ -183,7 +183,8 @@ module Merit @@ -183,7 +183,8 @@ module Merit
183 AVAILABLE_RULES.each do |point_type, setting| 183 AVAILABLE_RULES.each do |point_type, setting|
184 GamificationPlugin::PointsCategorization.for_type(point_type).includes(:profile).each do |categorization| 184 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| 185 [setting[:action], setting[:undo_action]].compact.zip([1, -1]).each do |action, signal|
186 - score lambda {|target| signal * calculate_score(target, categorization.weight, setting[:value])}, on: action, to: setting[:to], category: categorization.id.to_s do |target| 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|
187 condition(setting, target, categorization.profile) 188 condition(setting, target, categorization.profile)
188 end 189 end
189 end 190 end