Commit 6522edbff0b946c32e1f485c0f801f874c2bac29
Committed by
Rodrigo Souto
1 parent
31ce4ce7
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,6 +61,15 @@ module API | ||
61 | root 'users', 'user' | 61 | root 'users', 'user' |
62 | expose :login | 62 | expose :login |
63 | expose :person, :using => Profile | 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 | end | 73 | end |
65 | 74 | ||
66 | class UserLogin < User | 75 | class UserLogin < User |
lib/api/v1/users.rb
@@ -17,6 +17,17 @@ module API | @@ -17,6 +17,17 @@ module API | ||
17 | present environment.users.find(params[:id]), :with => Entities::User | 17 | present environment.users.find(params[:id]), :with => Entities::User |
18 | end | 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 | end | 31 | end |
21 | 32 | ||
22 | end | 33 | end |