Managing user role assignments
From DreamFactory
Toddappleton (Talk | contribs) (Created page with "Each user can be assigned a role for each application. This can be done via the API by updating the user and specifying the relationship 'user_to_app_to_role_by_user_id'.") |
Toddappleton (Talk | contribs) |
||
Line 1: | Line 1: | ||
− | Each user can be assigned a role for each application. This can be done via the API by updating the user and | + | 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. |
+ | <br/><br/> | ||
+ | <pre> | ||
+ | PUT /api/v2/system/user/100?related=user_to_app_to_role_by_user_id | ||
+ | </pre> | ||
+ | <pre> | ||
+ | { | ||
+ | "user_to_app_to_role_by_user_id": [{ | ||
+ | "app_id": "5", | ||
+ | "role_id": 7, | ||
+ | "user_id": 100 | ||
+ | }] | ||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | 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. | ||
+ | <br/><br/> | ||
+ | <pre> | ||
+ | GET /api/v2/system/user/100?related=user_to_app_to_role_by_user_id | ||
+ | </pre> | ||
+ | <pre> | ||
+ | { | ||
+ | "id": 8, | ||
+ | "user_to_app_to_role_by_user_id": [ | ||
+ | { | ||
+ | "id": 23, | ||
+ | "user_id": 8, | ||
+ | "app_id": 1, | ||
+ | "role_id": 7 | ||
+ | }, | ||
+ | { | ||
+ | "id": 24, | ||
+ | "user_id": 8, | ||
+ | "app_id": 2, | ||
+ | "role_id": 7 | ||
+ | }, | ||
+ | { | ||
+ | "id": 25, | ||
+ | "user_id": 8, | ||
+ | "app_id": 3, | ||
+ | "role_id": 7 | ||
+ | }, | ||
+ | { | ||
+ | "id": 26, | ||
+ | "user_id": 8, | ||
+ | "app_id": 4, | ||
+ | "role_id": 7 | ||
+ | }, | ||
+ | { | ||
+ | "id": 31, | ||
+ | "user_id": 8, | ||
+ | "app_id": 5, | ||
+ | "role_id": 7 | ||
+ | }, | ||
+ | { | ||
+ | "id": 32, | ||
+ | "user_id": 8, | ||
+ | "app_id": 6, | ||
+ | "role_id": 7 | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | </pre> |
Revision as of 20:38, 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": 8, "user_to_app_to_role_by_user_id": [ { "id": 23, "user_id": 8, "app_id": 1, "role_id": 7 }, { "id": 24, "user_id": 8, "app_id": 2, "role_id": 7 }, { "id": 25, "user_id": 8, "app_id": 3, "role_id": 7 }, { "id": 26, "user_id": 8, "app_id": 4, "role_id": 7 }, { "id": 31, "user_id": 8, "app_id": 5, "role_id": 7 }, { "id": 32, "user_id": 8, "app_id": 6, "role_id": 7 } ] }