Commit 86274a0de2e7a1b5a3aa64b24c242590dbe828d2
1 parent
2cf8abdd
Exists in
theme-brasil-digital-from-staging
and in
9 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
@@ -14,6 +14,17 @@ module API | @@ -14,6 +14,17 @@ module API | ||
14 | get ":id" do | 14 | get ":id" do |
15 | present environment.users.find(params[:id]), :with => Entities::User | 15 | present environment.users.find(params[:id]), :with => Entities::User |
16 | end | 16 | end |
17 | + | ||
18 | + get ":id/permissions" do | ||
19 | + user = environment.users.find(params[:id]) | ||
20 | + output = {} | ||
21 | + user.person.role_assignments.map do |role_assigment| | ||
22 | + if role_assigment.resource.respond_to?(:identifier) && role_assigment.resource.identifier == params[:profile] | ||
23 | + output[:permissions] = role_assigment.role.permissions | ||
24 | + end | ||
25 | + end | ||
26 | + present output | ||
27 | + end | ||
17 | 28 | ||
18 | end | 29 | end |
19 | 30 |