villebro commented on a change in pull request #12680:
URL: https://github.com/apache/superset/pull/12680#discussion_r567237420



##########
File path: superset/dashboards/filters.py
##########
@@ -107,8 +121,11 @@ def apply(self, query: Query, value: Any) -> Query:
         query = query.filter(
             or_(
                 Dashboard.id.in_(owner_ids_query),
-                Dashboard.id.in_(published_dash_query),
+                Dashboard.id.in_(datasource_perm_query),
                 Dashboard.id.in_(users_favorite_dash_query),
+                Dashboard.id.in_(roles_based_query)
+                if is_feature_enabled("DASHBOARD_RBAC")
+                else None,

Review comment:
       Here we could do the same i.e.
   ```python
   dashboard_rbac_or_filters = []
   if is_feature_enabled("DASHBOARD_RBAC"):
       dashboard_rbac_or_filters.append(Dashboard.id.in_(roles_based_query))
   ```
   , and then unpack that in a similar fashion:
   ```python
               or_(
                   Dashboard.id.in_(owner_ids_query),
                   Dashboard.id.in_(datasource_perm_query),
                   Dashboard.id.in_(users_favorite_dash_query),
                   *dashboard_rbac_or_filters,
   ```

##########
File path: superset/dashboards/filters.py
##########
@@ -74,12 +75,14 @@ def apply(self, query: Query, value: Any) -> Query:
 
         datasource_perms = 
security_manager.user_view_menu_names("datasource_access")
         schema_perms = security_manager.user_view_menu_names("schema_access")
-        published_dash_query = (
+        dashboard_has_roles = Dashboard.roles.any()
+        datasource_perm_query = (
             db.session.query(Dashboard.id)
             .join(Dashboard.slices)
             .filter(
                 and_(
-                    Dashboard.published == True,  # pylint: 
disable=singleton-comparison
+                    Dashboard.published.is_(True),
+                    ~dashboard_has_roles,

Review comment:
       This addition doesn't take into consideration the FF. Could we do 
something like this?
   ```python
   dashboard_rbac_and_filters = []
   if is_feature_enabled("DASHBOARD_RBAC"):
       dashboard_rbac_and_filters.append(~dashboard_has_roles)
   ```
   and then later
   ```python
           datasource_perm_query = (
               db.session.query(Dashboard.id)
               .join(Dashboard.slices)
               .filter(
                   and_(
                       Dashboard.published.is_(True),
                       *dashboard_rbac_and_filters,
   ```
   This way the logic would be fully unchanged when the FF is disabled and the 
additional `AND` only added when turned on.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to