Commit 0d1f104bf6081822b15a72ebefbf27a3ab011bdf
Exists in
staging
and in
3 other branches
Merge branch 'angular_poc' into staging
Showing
4 changed files
with
25 additions
and
2 deletions
Show diff stats
app/models/profile.rb
@@ -421,6 +421,10 @@ class Profile < ActiveRecord::Base | @@ -421,6 +421,10 @@ class Profile < ActiveRecord::Base | ||
421 | !profiles.exists? | 421 | !profiles.exists? |
422 | end | 422 | end |
423 | 423 | ||
424 | + def self.visible_for_person(person) | ||
425 | + self.all | ||
426 | + end | ||
427 | + | ||
424 | validates_presence_of :identifier, :name | 428 | validates_presence_of :identifier, :name |
425 | validates_length_of :nickname, :maximum => 16, :allow_nil => true | 429 | validates_length_of :nickname, :maximum => 16, :allow_nil => true |
426 | validate :valid_template | 430 | validate :valid_template |
lib/noosfero/api/entities.rb
@@ -111,6 +111,7 @@ module Noosfero | @@ -111,6 +111,7 @@ module Noosfero | ||
111 | end | 111 | end |
112 | expose :image, :using => Image | 112 | expose :image, :using => Image |
113 | expose :region, :using => Region | 113 | expose :region, :using => Region |
114 | + expose :type | ||
114 | end | 115 | end |
115 | 116 | ||
116 | class UserBasic < Entity | 117 | class UserBasic < Entity |
lib/noosfero/api/v1/people.rb
@@ -4,6 +4,8 @@ module Noosfero | @@ -4,6 +4,8 @@ module Noosfero | ||
4 | class People < Grape::API | 4 | class People < Grape::API |
5 | before { authenticate! } | 5 | before { authenticate! } |
6 | 6 | ||
7 | + MAX_PER_PAGE = 50 | ||
8 | + | ||
7 | desc 'API Root' | 9 | desc 'API Root' |
8 | 10 | ||
9 | resource :people do | 11 | resource :people do |
@@ -105,6 +107,20 @@ module Noosfero | @@ -105,6 +107,20 @@ module Noosfero | ||
105 | present output | 107 | present output |
106 | end | 108 | end |
107 | end | 109 | end |
110 | + | ||
111 | + resource :profiles do | ||
112 | + segment '/:profile_id' do | ||
113 | + resource :members do | ||
114 | + paginate per_page: MAX_PER_PAGE, max_per_page: MAX_PER_PAGE | ||
115 | + get do | ||
116 | + profile = environment.profiles.find_by_id(params[:profile_id]) | ||
117 | + members = select_filtered_collection_of(profile, 'members', params) | ||
118 | + present members, :with => Entities::Person, :current_person => current_person | ||
119 | + end | ||
120 | + end | ||
121 | + end | ||
122 | + end | ||
123 | + | ||
108 | end | 124 | end |
109 | end | 125 | end |
110 | end | 126 | end |
lib/noosfero/api/v1/profiles.rb
@@ -8,13 +8,15 @@ module Noosfero | @@ -8,13 +8,15 @@ module Noosfero | ||
8 | 8 | ||
9 | get do | 9 | get do |
10 | profiles = select_filtered_collection_of(environment, 'profiles', params) | 10 | profiles = select_filtered_collection_of(environment, 'profiles', params) |
11 | - profiles = profiles.visible_for_person(current_person) if profiles.respond_to?(:visible_for_person) | 11 | + profiles = profiles.visible_for_person(current_person) |
12 | profiles = profiles.by_location(params) # Must be the last. May return Exception obj. | 12 | profiles = profiles.by_location(params) # Must be the last. May return Exception obj. |
13 | present profiles, :with => Entities::Profile, :current_person => current_person | 13 | present profiles, :with => Entities::Profile, :current_person => current_person |
14 | end | 14 | end |
15 | 15 | ||
16 | get ':id' do | 16 | get ':id' do |
17 | - profile = environment.profiles.visible_for_person(current_person).find_by_id(params[:id]) | 17 | + profiles = environment.profiles |
18 | + profiles = profiles.visible_for_person(current_person) | ||
19 | + profile = profiles.find_by_id(params[:id]) | ||
18 | present profile, :with => Entities::Profile, :current_person => current_person | 20 | present profile, :with => Entities::Profile, :current_person => current_person |
19 | end | 21 | end |
20 | end | 22 | end |