Commit 5cc167113c1edef96aca53ffefbb3ec89eab9f81
Exists in
master
Merge branch 'conference_badge_rules' into 'master'
Add conference specific badges rules See merge request !1
Showing
3 changed files
with
155 additions
and
0 deletions
Show diff stats
lib/ext/article.rb
lib/ext/entities.rb
... | ... | @@ -24,3 +24,142 @@ module Noosfero |
24 | 24 | end |
25 | 25 | end |
26 | 26 | end |
27 | + | |
28 | +module Merit | |
29 | + class BadgeRules | |
30 | + include Merit::BadgeRulesMethods | |
31 | + | |
32 | + CONFERENCE_RULES = { | |
33 | + comment_author_conferencia: [ | |
34 | + { | |
35 | + action: 'comment#create', | |
36 | + default_threshold: 5, | |
37 | + to: :author, | |
38 | + value: lambda { |comment, author| author.present? ? author.conference_comments.count : 0 } | |
39 | + } | |
40 | + ], | |
41 | + comment_received_conferencia: [ | |
42 | + { | |
43 | + action: 'comment#create', | |
44 | + default_threshold: 5, | |
45 | + to: lambda {|comment| comment.source.author}, | |
46 | + value: lambda { |comment, author| author.present? ? Comment.where(source_id: Article.conference_articles.where(author_id: author.id)).count : 0 } | |
47 | + } | |
48 | + ], | |
49 | + article_author_conferencia: [ | |
50 | + { | |
51 | + action: 'article#create', | |
52 | + default_threshold: 5, | |
53 | + to: :author, | |
54 | + value: lambda { |article, author| author.present? ? TextArticle.conference_articles.where(author_id: author.id).count : 0 } | |
55 | + }, | |
56 | + ], | |
57 | + positive_votes_received_conferencia: [ | |
58 | + { | |
59 | + action: 'vote#create', | |
60 | + default_threshold: 5, | |
61 | + to: lambda {|vote| vote.voteable.author}, | |
62 | + value: lambda { |vote, author| vote.voteable.profile.identifier == 'conferencia' ? Vote.for_voteable(vote.voteable).where('vote > 0').count : 0 } | |
63 | + } | |
64 | + ], | |
65 | + negative_votes_received_conferencia: [ | |
66 | + { | |
67 | + action: 'vote#create', | |
68 | + default_threshold: 5, | |
69 | + to: lambda {|vote| vote.voteable.author}, | |
70 | + value: lambda { |vote, author| vote.voteable.profile.identifier == 'conferencia' ? Vote.for_voteable(vote.voteable).where('vote < 0').count : 0 } | |
71 | + } | |
72 | + ], | |
73 | + votes_performed_conferencia: [ | |
74 | + { | |
75 | + action: 'vote#create', | |
76 | + default_threshold: 5, | |
77 | + to: lambda {|vote| vote.voter}, | |
78 | + value: lambda { |vote, voter| vote.voteable.profile.identifier == 'conferencia' ? Vote.for_voter(voter).count : 0} | |
79 | + } | |
80 | + ], | |
81 | + creative_conferencia: [ | |
82 | + { | |
83 | + action: 'comment#create', | |
84 | + default_threshold: 5, | |
85 | + to: :author, | |
86 | + value: lambda { |comment, author| author.present? ? author.conference_comments.count : 0 } | |
87 | + }, | |
88 | + { | |
89 | + action: 'article#create', | |
90 | + default_threshold: 5, | |
91 | + to: :author, | |
92 | + value: lambda { |article, author| author.present? ? TextArticle.conference_articles.where(author_id: author.id).count : 0 } | |
93 | + }, | |
94 | + ], | |
95 | + observer_conferencia: [ | |
96 | + { | |
97 | + action: 'articlefollower#create', | |
98 | + default_threshold: 5, | |
99 | + to: :person, | |
100 | + model: 'ArticleFollower', | |
101 | + value: lambda { |article, person| person.present? ? person.article_followers.where(article_id: Article.conference_articles).count : 0 } | |
102 | + } | |
103 | + ], | |
104 | + #activist_conferencia: [ | |
105 | + #{ | |
106 | + #action: 'Vote#create', | |
107 | + #default_threshold: 5, | |
108 | + #to: lambda { |vote| vote.voter }, | |
109 | + #value: lambda { |vote, voter| vote.voteable.profile.identifier == 'conferencia' ? Vote.for_voter(voter).count : 0 } | |
110 | + #}, | |
111 | + #{ | |
112 | + #action: 'Event#create', | |
113 | + #default_threshold: 5, | |
114 | + #to: lambda { |event| event.author }, | |
115 | + #value: lambda { |event, author| author.events.count } | |
116 | + #}, | |
117 | + #], | |
118 | + #mobilizer_conferencia: [ | |
119 | + #{ | |
120 | + #action: 'Vote#create', | |
121 | + #default_threshold: 5, | |
122 | + #to: lambda { |vote| vote.voter }, | |
123 | + #value: lambda { |vote, voter| vote.voteable.profile.identifier == 'conferencia' ? Vote.for_voter(voter).count : 0 } | |
124 | + #}, | |
125 | + #{ | |
126 | + #action: 'Event#create', | |
127 | + #default_threshold: 5, | |
128 | + #to: lambda { |event| event.author }, | |
129 | + #value: lambda { |event, author| author.events.count } | |
130 | + #}, | |
131 | + #], | |
132 | + generous_conferencia: [ | |
133 | + { | |
134 | + action: 'vote#create', | |
135 | + default_threshold: 5, | |
136 | + to: lambda {|vote| vote.voter}, | |
137 | + value: lambda { |vote, voter| voter.present? ? voter.votes.where('vote > 0').where('voteable_id' => Article.conference_articles, 'voteable_type' => 'Article').count : 0 } | |
138 | + }, | |
139 | + { | |
140 | + action: 'comment#create', | |
141 | + default_threshold: 5, | |
142 | + to: :author, | |
143 | + value: lambda { |comment, author| author.present? ? Comment.where(source_id: Article.conference_articles.where(author_id: author.id)).count : 0 } | |
144 | + } | |
145 | + ], | |
146 | + articulator_conferencia: [ | |
147 | + { | |
148 | + action: 'articlefollower#create', | |
149 | + default_threshold: 5, | |
150 | + to: :person, | |
151 | + model: 'ArticleFollower', | |
152 | + value: lambda { |article, person| person.present? ? person.article_followers.where(article_id: Article.conference_articles).count : 0 } | |
153 | + }, | |
154 | + { | |
155 | + action: 'comment#create', | |
156 | + default_threshold: 5, | |
157 | + to: :author, | |
158 | + value: lambda { |comment, author| author.present? ? Comment.where(source_id: Article.conference_articles.where(author_id: author.id)).count : 0 } | |
159 | + }, | |
160 | + #mobilizer#create | |
161 | + ] | |
162 | + } | |
163 | + | |
164 | + end | |
165 | +end | ... | ... |
lib/ext/person.rb
... | ... | @@ -6,4 +6,18 @@ class Person |
6 | 6 | |
7 | 7 | attr_accessible :orientacao_sexual, :identidade_genero, :transgenero, :tipo, :etnia |
8 | 8 | |
9 | + def is_profile_complete? | |
10 | + #FIXME: this check is hardcoded to satisfy a temporary issue. | |
11 | + #a better fix is being implemented already | |
12 | + !(self.name.blank? or | |
13 | + (self.data[:identidade_genero].blank? and self.data[:transgenero].blank?) or | |
14 | + self.data[:etnia].blank? or | |
15 | + self.data[:orientacao_sexual].blank? or | |
16 | + self.data[:state].blank? or | |
17 | + self.data[:city].blank?) | |
18 | + end | |
19 | + | |
20 | + def conference_comments | |
21 | + Profile['conferencia'].comments_received.where(author_id: id) | |
22 | + end | |
9 | 23 | end | ... | ... |