Commit 20b57b8d4c62b30f8f1762dda5959bf464eea08a
Committed by
Rodrigo Souto
1 parent
0ed62231
Exists in
master
and in
29 other branches
api: return logged in user
Showing
2 changed files
with
12 additions
and
2 deletions
Show diff stats
lib/noosfero/api/v1/users.rb
@@ -24,11 +24,15 @@ module Noosfero | @@ -24,11 +24,15 @@ module Noosfero | ||
24 | 24 | ||
25 | present user, :with => Entities::User | 25 | present user, :with => Entities::User |
26 | end | 26 | end |
27 | - | 27 | + |
28 | + get "/me" do | ||
29 | + present current_user, :with => Entities::User | ||
30 | + end | ||
31 | + | ||
28 | get ":id" do | 32 | get ":id" do |
29 | present environment.users.find_by_id(params[:id]), :with => Entities::User | 33 | present environment.users.find_by_id(params[:id]), :with => Entities::User |
30 | end | 34 | end |
31 | - | 35 | + |
32 | get ":id/permissions" do | 36 | get ":id/permissions" do |
33 | user = environment.users.find(params[:id]) | 37 | user = environment.users.find(params[:id]) |
34 | output = {} | 38 | output = {} |
test/unit/api/users_test.rb
@@ -40,4 +40,10 @@ class UsersTest < ActiveSupport::TestCase | @@ -40,4 +40,10 @@ class UsersTest < ActiveSupport::TestCase | ||
40 | assert_includes json["user"]["permissions"], community.identifier | 40 | assert_includes json["user"]["permissions"], community.identifier |
41 | end | 41 | end |
42 | 42 | ||
43 | + should 'get logged user' do | ||
44 | + get "/api/v1/users/me?#{params.to_query}" | ||
45 | + json = JSON.parse(last_response.body) | ||
46 | + assert_equal user.id, json['user']['id'] | ||
47 | + end | ||
48 | + | ||
43 | end | 49 | end |