Commit 4d44e7f4dbe5d17793a43301f7912b84c4aac226
Exists in
master
and in
1 other branch
Merge branch '103_points_endpoints' into 101_points_categorization_by_profile3
Conflicts: lib/ext/person.rb lib/gamification_plugin/api.rb lib/merit/point_rules.rb
Showing
3 changed files
with
46 additions
and
1 deletions
Show diff stats
lib/ext/person.rb
@@ -12,4 +12,19 @@ class Person | @@ -12,4 +12,19 @@ class Person | ||
12 | # FIXME: FIND OUT A WAY TO CHECK EVERY REGISTRY FIELD | 12 | # FIXME: FIND OUT A WAY TO CHECK EVERY REGISTRY FIELD |
13 | false | 13 | false |
14 | end | 14 | end |
15 | + | ||
16 | + def points_by_type type | ||
17 | + categorizations = GamificationPlugin::PointsCategorization.by_type(type) | ||
18 | + categorizations.inject(0) {|sum, c| sum += self.points(category: c.id.to_s) } | ||
19 | + end | ||
20 | + | ||
21 | + def points_by_profile profile | ||
22 | + categorizations = GamificationPlugin::PointsCategorization.by_profile(profile) | ||
23 | + categorizations.inject(0) {|sum, c| sum += self.points(category: c.id.to_s) } | ||
24 | + end | ||
25 | + | ||
26 | + def points_out_of_profiles | ||
27 | + categorizations = GamificationPlugin::PointsCategorization.where(profile_id: nil) | ||
28 | + categorizations.inject(0) { |sum, c| sum += self.points(category: c.id.to_s) } | ||
29 | + end | ||
15 | end | 30 | end |
lib/gamification_plugin/api.rb
@@ -11,10 +11,23 @@ class GamificationPlugin::API < Grape::API | @@ -11,10 +11,23 @@ class GamificationPlugin::API < Grape::API | ||
11 | authenticate! | 11 | authenticate! |
12 | present current_person.badges, :with => Noosfero::API::Entities::Badge | 12 | present current_person.badges, :with => Noosfero::API::Entities::Badge |
13 | end | 13 | end |
14 | + | ||
14 | get 'points' do | 15 | get 'points' do |
15 | authenticate! | 16 | authenticate! |
16 | {points: current_person.points} | 17 | {points: current_person.points} |
17 | end | 18 | end |
19 | + get 'points_by_type' do | ||
20 | + authenticate! | ||
21 | + {points: current_person.points_by_type(params[:type]) } | ||
22 | + end | ||
23 | + get 'points_by_profile' do | ||
24 | + authenticate! | ||
25 | + {points: current_person.points_by_profile(params[:profile]) } | ||
26 | + end | ||
27 | + get 'points_out_of_profiles' do | ||
28 | + authenticate! | ||
29 | + {points: current_person.points_out_of_profiles } | ||
30 | + end | ||
18 | 31 | ||
19 | get 'level' do | 32 | get 'level' do |
20 | authenticate! | 33 | authenticate! |
@@ -35,6 +48,24 @@ class GamificationPlugin::API < Grape::API | @@ -35,6 +48,24 @@ class GamificationPlugin::API < Grape::API | ||
35 | {:points => person.points} | 48 | {:points => person.points} |
36 | end | 49 | end |
37 | 50 | ||
51 | + get ':id/points_by_type' do | ||
52 | + person = environment.people.visible_for_person(current_person).find_by_id(params[:id]) | ||
53 | + return not_found! if person.blank? | ||
54 | + {points: person.points_by_type(params[:type]) } | ||
55 | + end | ||
56 | + | ||
57 | + get ':id/points_by_profile' do | ||
58 | + person = environment.people.visible_for_person(current_person).find_by_id(params[:id]) | ||
59 | + return not_found! if person.blank? | ||
60 | + {points: person.points_by_type(params[:profile]) } | ||
61 | + end | ||
62 | + | ||
63 | + get ':id/points_out_of_profiles' do | ||
64 | + person = environment.people.visible_for_person(current_person).find_by_id(params[:id]) | ||
65 | + return not_found! if person.blank? | ||
66 | + {points: person.points_out_of_profiles } | ||
67 | + end | ||
68 | + | ||
38 | get ':id/level' do | 69 | get ':id/level' do |
39 | person = environment.people.visible_for_person(current_person).find_by_id(params[:id]) | 70 | person = environment.people.visible_for_person(current_person).find_by_id(params[:id]) |
40 | return not_found! if person.blank? | 71 | return not_found! if person.blank? |
lib/merit/point_rules.rb
@@ -85,7 +85,6 @@ module Merit | @@ -85,7 +85,6 @@ module Merit | ||
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| vote.voteable.profile == profile } |
88 | - | ||
89 | }, | 88 | }, |
90 | friends: { | 89 | friends: { |
91 | action: 'friendship#create', | 90 | action: 'friendship#create', |