dosubot[bot] commented on issue #36110:
URL: https://github.com/apache/superset/issues/36110#issuecomment-3531196304
<!-- Answer -->
Yes, you can assign roles like "gamma" and your custom "readonly" role to
dashboards using the API in Superset 5.0.0, but there are a few requirements:
- Make sure the DASHBOARD_RBAC feature flag is enabled in your
superset_config.py.
- Enable the API for security by setting FAB_ADD_SECURITY_API = True in
superset_config.py.
- The /api/v1/dashboard/{pk} endpoint accepts a PUT request with a JSON
payload containing a roles field, which should be a list of role IDs (not
names).
Example API request (using curl):
```bash
curl -X PUT "https://<your-superset-host>/api/v1/dashboard/<dashboard_id>" \
-H "Authorization: Bearer <your_access_token>" \
-H "X-CSRFToken: <your_csrf_token>" \
-H "Content-Type: application/json" \
-d '{"roles": [<gamma_role_id>, <readonly_role_id>]}'
```
You can get the role IDs by querying the roles endpoint or from the roles
list in the UI.
If you want to automate this for all dashboards after import, you can loop
through all dashboard IDs and send the above request for each one.
Alternatively, you can use a backend Python script with the Superset app
context and ORM to assign roles in bulk, which is more maintainable for large
numbers of dashboards or repeated operations. Example script and more details
are available in this discussion: [GitHub Discussion: Automating Dashboard Role
Assignment](https://github.com/apache/superset/discussions/35570).
Note: Role associations are not preserved during export/import, so you must
re-assign them after importing dashboards. There is currently no built-in way
to automate role assignment on import; you need to script it yourself or run a
scheduled job. For more details on the API and dashboard RBAC, see [this
discussion](https://github.com/apache/superset/issues/34733) and [dashboard API
code
reference](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/dashboards/api.py#L191-L1591).
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*
---
<sup>How did I do?
[Good](https://app.dosu.dev/response-feedback/cd690b22-7972-4f38-b012-cec5c63dbfcf?feedback_type=great_response)
|
[Irrelevant](https://app.dosu.dev/response-feedback/cd690b22-7972-4f38-b012-cec5c63dbfcf?feedback_type=irrelevant_answer)
|
[Incorrect](https://app.dosu.dev/response-feedback/cd690b22-7972-4f38-b012-cec5c63dbfcf?feedback_type=incorrect_sources)
|
[Verbose](https://app.dosu.dev/response-feedback/cd690b22-7972-4f38-b012-cec5c63dbfcf?feedback_type=too_verbose)
|
[Hallucination](https://app.dosu.dev/response-feedback/cd690b22-7972-4f38-b012-cec5c63dbfcf?feedback_type=hallucination)
| [Report
🐛](https://app.dosu.dev/response-feedback/cd690b22-7972-4f38-b012-cec5c63dbfcf?feedback_type=bug_report)
|
[Other](https://app.dosu.dev/response-feedback/cd690b22-7972-4f38-b012-cec5c63dbfcf?feedback_type=other)</sup> [](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=githu
b) [](https://go.dosu.dev/discord-bot) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/issues/36110)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]