Commit e647c029db9165f0abf0e86d6360a87a2416138f
1 parent
696c40b4
Exists in
master
and in
1 other branch
Adjust rules for generic pontuation
Showing
2 changed files
with
20 additions
and
19 deletions
Show diff stats
lib/merit/badge_rules.rb
| ... | ... | @@ -14,7 +14,7 @@ module Merit |
| 14 | 14 | action: 'comment#create', |
| 15 | 15 | default_threshold: 5, |
| 16 | 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 | 20 | comment_received: [ |
| ... | ... | @@ -22,7 +22,7 @@ module Merit |
| 22 | 22 | action: 'comment#create', |
| 23 | 23 | default_threshold: 5, |
| 24 | 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 | 28 | article_author: [ |
| ... | ... | @@ -30,7 +30,7 @@ module Merit |
| 30 | 30 | action: 'article#create', |
| 31 | 31 | default_threshold: 5, |
| 32 | 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 | 36 | positive_votes_received: [ | ... | ... |
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| comment.source.profile == profile}, | |
| 13 | + condition: lambda {|comment, profile| profile.nil? or comment.source.profile == 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| comment.source.profile == profile}, | |
| 22 | + condition: lambda {|comment, profile| profile.nil? or comment.source.profile == 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| comment.source.profile == profile}, | |
| 31 | + condition: lambda {|comment, profile| profile.nil? or comment.source.profile == profile}, | |
| 32 | 32 | }, |
| 33 | 33 | comment_community: { |
| 34 | 34 | action: 'comment#create', |
| ... | ... | @@ -37,7 +37,7 @@ module Merit |
| 37 | 37 | value: 1, |
| 38 | 38 | description: _('Article community of a comment'), |
| 39 | 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 | 42 | article_author: { |
| 43 | 43 | action: 'article#create', |
| ... | ... | @@ -45,8 +45,8 @@ module Merit |
| 45 | 45 | to: :author, |
| 46 | 46 | value: 1, |
| 47 | 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 | 51 | article_community: { |
| 52 | 52 | action: 'article#create', |
| ... | ... | @@ -55,7 +55,7 @@ module Merit |
| 55 | 55 | value: 1, |
| 56 | 56 | description: _('Article community'), |
| 57 | 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 | 60 | vote_voteable_author: { |
| 61 | 61 | action: 'vote#create', |
| ... | ... | @@ -65,7 +65,7 @@ module Merit |
| 65 | 65 | value: lambda {|vote| vote.vote}, |
| 66 | 66 | description: _('Author of a voted content'), |
| 67 | 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 | 70 | vote_voteable: { |
| 71 | 71 | action: 'vote#create', |
| ... | ... | @@ -75,7 +75,7 @@ module Merit |
| 75 | 75 | value: lambda {|vote| vote.vote}, |
| 76 | 76 | description: _('Voted content'), |
| 77 | 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 | 80 | vote_voter: { |
| 81 | 81 | action: 'vote#create', |
| ... | ... | @@ -84,7 +84,7 @@ module Merit |
| 84 | 84 | value: lambda {|vote| 1}, |
| 85 | 85 | description: _('Voter'), |
| 86 | 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 | 89 | friends: { |
| 90 | 90 | action: 'friendship#create', |
| ... | ... | @@ -113,7 +113,7 @@ module Merit |
| 113 | 113 | value: 1, |
| 114 | 114 | description: _('Follower'), |
| 115 | 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 | 117 | profile_action: true |
| 118 | 118 | }, |
| 119 | 119 | followed_article_author: { |
| ... | ... | @@ -123,7 +123,7 @@ module Merit |
| 123 | 123 | value: 1, |
| 124 | 124 | description: _('Followed'), |
| 125 | 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 | 127 | profile_action: true |
| 128 | 128 | }, |
| 129 | 129 | #mobilizer: { |
| ... | ... | @@ -133,7 +133,7 @@ module Merit |
| 133 | 133 | #value: 1, |
| 134 | 134 | #description: _('Mobilized Article Author'), |
| 135 | 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 | 137 | #profile_action: true |
| 138 | 138 | #}, |
| 139 | 139 | #mobilized_article_author: { |
| ... | ... | @@ -143,7 +143,7 @@ module Merit |
| 143 | 143 | #value: 1, |
| 144 | 144 | #description: _('Mobilized Article Author'), |
| 145 | 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 | 147 | #profile_action: true |
| 148 | 148 | #}, |
| 149 | 149 | #mobilized_article: { |
| ... | ... | @@ -153,7 +153,7 @@ module Merit |
| 153 | 153 | #value: 1, |
| 154 | 154 | #description: _('Mobilized Article Author'), |
| 155 | 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 | 157 | #profile_action: true |
| 158 | 158 | #} |
| 159 | 159 | } |
| ... | ... | @@ -183,7 +183,8 @@ module Merit |
| 183 | 183 | AVAILABLE_RULES.each do |point_type, setting| |
| 184 | 184 | GamificationPlugin::PointsCategorization.for_type(point_type).includes(:profile).each do |categorization| |
| 185 | 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 | 188 | condition(setting, target, categorization.profile) |
| 188 | 189 | end |
| 189 | 190 | end | ... | ... |