Commit 425f6c701328534187e33338bc18ef23b5fcea52
Committed by
Rodrigo Souto
1 parent
65b06407
Exists in
master
and in
29 other branches
adding permission stuff
Showing
2 changed files
with
20 additions
and
0 deletions
Show diff stats
lib/api/entities.rb
... | ... | @@ -61,6 +61,15 @@ module API |
61 | 61 | root 'users', 'user' |
62 | 62 | expose :login |
63 | 63 | expose :person, :using => Profile |
64 | + expose :permissions do |user, options| | |
65 | + output = {} | |
66 | + user.person.role_assignments.map do |role_assigment| | |
67 | + if role_assigment.resource.respond_to?(:identifier) | |
68 | + output[role_assigment.resource.identifier] = role_assigment.role.permissions | |
69 | + end | |
70 | + end | |
71 | + output | |
72 | + end | |
64 | 73 | end |
65 | 74 | |
66 | 75 | class UserLogin < User | ... | ... |
lib/api/v1/users.rb
... | ... | @@ -17,6 +17,17 @@ module API |
17 | 17 | present environment.users.find(params[:id]), :with => Entities::User |
18 | 18 | end |
19 | 19 | |
20 | + get ":id/permissions" do | |
21 | + user = environment.users.find(params[:id]) | |
22 | + output = {} | |
23 | + user.person.role_assignments.map do |role_assigment| | |
24 | + if role_assigment.resource.respond_to?(:identifier) && role_assigment.resource.identifier == params[:profile] | |
25 | + output[:permissions] = role_assigment.role.permissions | |
26 | + end | |
27 | + end | |
28 | + present output | |
29 | + end | |
30 | + | |
20 | 31 | end |
21 | 32 | |
22 | 33 | end | ... | ... |