Managing user role assignments
From DreamFactory
Toddappleton (Talk | contribs) |
Toddappleton (Talk | contribs) |
||
Line 21: | Line 21: | ||
<pre> | <pre> | ||
{ | { | ||
− | "id": | + | "id": 100, |
"user_to_app_to_role_by_user_id": [ | "user_to_app_to_role_by_user_id": [ | ||
{ | { | ||
"id": 23, | "id": 23, | ||
− | "user_id": | + | "user_id": 100, |
"app_id": 1, | "app_id": 1, | ||
"role_id": 7 | "role_id": 7 | ||
Line 31: | Line 31: | ||
{ | { | ||
"id": 24, | "id": 24, | ||
− | "user_id": | + | "user_id": 100, |
"app_id": 2, | "app_id": 2, | ||
"role_id": 7 | "role_id": 7 | ||
Line 37: | Line 37: | ||
{ | { | ||
"id": 25, | "id": 25, | ||
− | "user_id": | + | "user_id": 100, |
"app_id": 3, | "app_id": 3, | ||
"role_id": 7 | "role_id": 7 | ||
Line 43: | Line 43: | ||
{ | { | ||
"id": 26, | "id": 26, | ||
− | "user_id": | + | "user_id": 100, |
"app_id": 4, | "app_id": 4, | ||
"role_id": 7 | "role_id": 7 | ||
Line 49: | Line 49: | ||
{ | { | ||
"id": 31, | "id": 31, | ||
− | "user_id": | + | "user_id": 100, |
"app_id": 5, | "app_id": 5, | ||
"role_id": 7 | "role_id": 7 | ||
Line 55: | Line 55: | ||
{ | { | ||
"id": 32, | "id": 32, | ||
− | "user_id": | + | "user_id": 100, |
"app_id": 6, | "app_id": 6, | ||
"role_id": 7 | "role_id": 7 |
Revision as of 20:39, 20 September 2016
Each user can be assigned a role for each application. This can be done via the API by updating the user and including the relationship 'user_to_app_to_role_by_user_id'. As an example let's say we want to assign user id 100 with a certain role for a certain app. If the role id is 7 and the app id is 5, the following would create the required relationship to assign that role to that user for that app.
PUT /api/v2/system/user/100?related=user_to_app_to_role_by_user_id
{ "user_to_app_to_role_by_user_id": [{ "app_id": "5", "role_id": 7, "user_id": 100 }] }
To retrieve the role assignments, do a GET with relationship 'user_to_app_to_role_by_user_id'. The last one is the one we just created.
GET /api/v2/system/user/100?related=user_to_app_to_role_by_user_id
{ "id": 100, "user_to_app_to_role_by_user_id": [ { "id": 23, "user_id": 100, "app_id": 1, "role_id": 7 }, { "id": 24, "user_id": 100, "app_id": 2, "role_id": 7 }, { "id": 25, "user_id": 100, "app_id": 3, "role_id": 7 }, { "id": 26, "user_id": 100, "app_id": 4, "role_id": 7 }, { "id": 31, "user_id": 100, "app_id": 5, "role_id": 7 }, { "id": 32, "user_id": 100, "app_id": 6, "role_id": 7 } ] }