Commit 4553d86d0988f76b4ac24dc8e0b37c3ec1fccbd7
1 parent
550c2015
Exists in
staging
and in
4 other branches
api: return profile members
Showing
3 changed files
with
21 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/v1/people.rb
| @@ -105,6 +105,19 @@ module Noosfero | @@ -105,6 +105,19 @@ module Noosfero | ||
| 105 | present output | 105 | present output |
| 106 | end | 106 | end |
| 107 | end | 107 | end |
| 108 | + | ||
| 109 | + resource :profiles do | ||
| 110 | + segment '/:profile_id' do | ||
| 111 | + resource :members do | ||
| 112 | + get do | ||
| 113 | + profile = environment.profiles.find_by_id(params[:profile_id]) | ||
| 114 | + members = profile.members | ||
| 115 | + present members, :with => Entities::Person, :current_person => current_person | ||
| 116 | + end | ||
| 117 | + end | ||
| 118 | + end | ||
| 119 | + end | ||
| 120 | + | ||
| 108 | end | 121 | end |
| 109 | end | 122 | end |
| 110 | end | 123 | 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 |