villebro opened a new pull request, #22526:
URL: https://github.com/apache/superset/pull/22526

   ### SUMMARY
   This is a continuation of #21515, which made it possible to exclude specific 
users from dropdown lists, to make it possible to add arbitrary filter 
conditions to both the user and role dropdowns. The primary reason for this is 
to be able to restrict the available roles in the Dashboard role dropdown when 
using `DASHBOARD_RBAC`, as users may unintentionally give too wide access to 
dashboards by sharing with a too generic role. Similarly, there may be a need 
to restrict to whom a user should be able to give ownership of an object.
   
   To demonstrate, by adding the following to `superset_config.py`, the owners 
dropdown now only contains the entry `admin`, and the roles dropdown only 
contains entries containing the letter "a":
   
   ```python
   def role_filter(query):
       from superset import security_manager
   
       role_model = security_manager.role_model
       filters = [role_model.name.like("A%")]
       return query.filter(or_(*filters))
   
   
   def user_filter(query):
       from superset import security_manager
   
       user_model = security_manager.user_model
       filters = [user_model.username == "admin"]
       return query.filter(or_(*filters))
   
   
   EXTRA_RELATED_QUERY_FILTERS = {
       "role": role_filter,
       "user": user_filter,
   }
   ```
   
   Now users only displays "Admin":
   
   <img width="887" alt="image" 
src="https://user-images.githubusercontent.com/33317356/209462025-fb9c46be-b772-461d-bf8b-473aeeda0760.png";>
   
   Similarly roles only contains "Admin" and "Alpha":
   
   <img width="884" alt="image" 
src="https://user-images.githubusercontent.com/33317356/209462080-af7f9786-fb74-41e9-8906-052fc8e148e9.png";>
   
   ### TESTING INSTRUCTIONS
   1. Add the above to `superset_config.py`
   2. Go to dashboard, chart and dataset CRUD views and ensure that the owners 
and roles dropdowns only contains the expected values.
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
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: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to