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 | 421 | !profiles.exists? |
422 | 422 | end |
423 | 423 | |
424 | + def self.visible_for_person(person) | |
425 | + self.all | |
426 | + end | |
427 | + | |
424 | 428 | validates_presence_of :identifier, :name |
425 | 429 | validates_length_of :nickname, :maximum => 16, :allow_nil => true |
426 | 430 | validate :valid_template | ... | ... |
lib/noosfero/api/entities.rb
lib/noosfero/api/v1/people.rb
... | ... | @@ -4,6 +4,8 @@ module Noosfero |
4 | 4 | class People < Grape::API |
5 | 5 | before { authenticate! } |
6 | 6 | |
7 | + MAX_PER_PAGE = 50 | |
8 | + | |
7 | 9 | desc 'API Root' |
8 | 10 | |
9 | 11 | resource :people do |
... | ... | @@ -105,6 +107,20 @@ module Noosfero |
105 | 107 | present output |
106 | 108 | end |
107 | 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 | 124 | end |
109 | 125 | end |
110 | 126 | end | ... | ... |
lib/noosfero/api/v1/profiles.rb
... | ... | @@ -8,13 +8,15 @@ module Noosfero |
8 | 8 | |
9 | 9 | get do |
10 | 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 | 12 | profiles = profiles.by_location(params) # Must be the last. May return Exception obj. |
13 | 13 | present profiles, :with => Entities::Profile, :current_person => current_person |
14 | 14 | end |
15 | 15 | |
16 | 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 | 20 | present profile, :with => Entities::Profile, :current_person => current_person |
19 | 21 | end |
20 | 22 | end | ... | ... |