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



##########
File path: superset/connectors/sqla/views.py
##########
@@ -369,6 +371,15 @@ class RowLevelSecurityFiltersModelView(  # pylint: 
disable=too-many-ancestors
         add_form_query_rel_fields = app.config["RLS_FORM_QUERY_REL_FIELDS"]
         edit_form_query_rel_fields = add_form_query_rel_fields
 
+    @staticmethod
+    def is_enabled() -> bool:
+        return is_feature_enabled("ROW_LEVEL_SECURITY")
+
+    @before_request
+    def ensure_enabled(self) -> None:
+        if not self.is_enabled():
+            raise NotFound()

Review comment:
       We could potentially generalize this by breaking this out into a Mixin 
that checks `is_feature_enabled` on a reserved property. Something like this:
   
   ```python
   class FeatureFlagMixin:
       feature_flag: str
   
       def is_enabled(self) -> bool:
           return is_feature_enabled(self.feature_flag)
   
       @before_request
       def ensure_enabled(self) -> None:
           if not self.is_enabled():
               raise NotFound()
   ```
   
   Then later this could be used as follows:
   
   ```python
   class RowLevelSecurityFiltersModelView(  # pylint: disable=too-many-ancestors
       FeatureFlagMixin, SupersetModelView, DeleteMixin
   ):
       feature_flag = "ROW_LEVEL_SECURITY"
       ....
   ```
   we could potentially also add support for callbacks that make it possible to 
add custom validators that don't rely on `is_feature_enabled`:
   
   ```python
   class FeatureFlagMixin:
       feature_flag: Union[str, Callable[[], bool]]
   
       def is_enabled(self) -> bool:
           if callable(self.feature_flag):
               return self.feature_flag()
           return is_feature_enabled(self.feature_flag)
   ```
   
   and then use it like this:
   
   ```python
       feature_flag = lambda _: app.config["FAB_ADD_SECURITY_VIEWS"] and 
app.config["SUPERSET_LOG_VIEW"]
   ```




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