bkyryliuk commented on a change in pull request #10963:
URL: 
https://github.com/apache/incubator-superset/pull/10963#discussion_r494446189



##########
File path: superset/views/utils.py
##########
@@ -298,6 +306,46 @@ def get_time_range_endpoints(
 CONTAINER_TYPES = ["COLUMN", "GRID", "TABS", "TAB", "ROW"]
 
 
+def get_dashboard(dashboard_id_or_slug: str,) -> Dashboard:
+    session = db.session()
+    qry = session.query(Dashboard)
+    if dashboard_id_or_slug.isdigit():
+        qry = qry.filter_by(id=int(dashboard_id_or_slug))
+    else:
+        qry = qry.filter_by(slug=dashboard_id_or_slug)
+    dashboard = qry.one_or_none()
+
+    if not dashboard:
+        abort(404)
+
+    return dashboard
+
+
+def get_datasources_from_dashboard(
+    dashboard: Dashboard,
+) -> DefaultDict[Any, List[Any]]:
+    datasources = defaultdict(list)
+    for slc in dashboard.slices:
+        datasource = slc.datasource
+        if datasource:
+            datasources[datasource].append(slc)
+    return datasources
+
+
+def get_dashboard_latest_changed_on(_self: Any, dashboard_id_or_slug: str) -> 
datetime:
+    """
+    Get latest changed datetime for a dashboard. The change could be dashboard

Review comment:
       s/Get latest changed datetime for a dashboard.
   /Get latest changed datetime for a dashboard and it's charts

##########
File path: superset/views/utils.py
##########
@@ -298,6 +306,46 @@ def get_time_range_endpoints(
 CONTAINER_TYPES = ["COLUMN", "GRID", "TABS", "TAB", "ROW"]
 
 
+def get_dashboard(dashboard_id_or_slug: str,) -> Dashboard:
+    session = db.session()
+    qry = session.query(Dashboard)
+    if dashboard_id_or_slug.isdigit():
+        qry = qry.filter_by(id=int(dashboard_id_or_slug))
+    else:
+        qry = qry.filter_by(slug=dashboard_id_or_slug)
+    dashboard = qry.one_or_none()
+
+    if not dashboard:
+        abort(404)
+
+    return dashboard
+
+
+def get_datasources_from_dashboard(

Review comment:
       looks like a good candidate for the Dashboard class method
   

##########
File path: superset/views/utils.py
##########
@@ -298,6 +306,46 @@ def get_time_range_endpoints(
 CONTAINER_TYPES = ["COLUMN", "GRID", "TABS", "TAB", "ROW"]
 
 
+def get_dashboard(dashboard_id_or_slug: str,) -> Dashboard:
+    session = db.session()
+    qry = session.query(Dashboard)
+    if dashboard_id_or_slug.isdigit():
+        qry = qry.filter_by(id=int(dashboard_id_or_slug))
+    else:
+        qry = qry.filter_by(slug=dashboard_id_or_slug)
+    dashboard = qry.one_or_none()
+
+    if not dashboard:
+        abort(404)
+
+    return dashboard
+
+
+def get_datasources_from_dashboard(
+    dashboard: Dashboard,
+) -> DefaultDict[Any, List[Any]]:
+    datasources = defaultdict(list)
+    for slc in dashboard.slices:
+        datasource = slc.datasource
+        if datasource:
+            datasources[datasource].append(slc)
+    return datasources
+
+
+def get_dashboard_latest_changed_on(_self: Any, dashboard_id_or_slug: str) -> 
datetime:

Review comment:
       what is _self here? ideally we should avoid Any types

##########
File path: superset/utils/decorators.py
##########
@@ -34,6 +34,10 @@
 logger = logging.getLogger(__name__)
 
 
+def is_dashboard_request(kwargs: Any) -> bool:
+    return kwargs.get("dashboard_id_or_slug") is not None

Review comment:
       doesn't seem robust, it it possible to validate via uri path or just 
pass a param ?

##########
File path: superset/views/utils.py
##########
@@ -490,6 +538,26 @@ def check_slice_perms(_self: Any, slice_id: int) -> None:
         viz_obj.raise_for_access()
 
 
+def check_dashboard_perms(_self: Any, dashboard_id_or_slug: str) -> None:

Review comment:
       best practice is to have a unit test for every function, it would be 
great if you could add some

##########
File path: superset/utils/decorators.py
##########
@@ -89,13 +103,25 @@ def wrapper(*args: Any, **kwargs: Any) -> 
ETagResponseMixin:
                         raise
                     logger.exception("Exception possibly due to cache 
backend.")
 
+            # if cache is stale?
+            if check_latest_changed_on:
+                latest_changed_on = check_latest_changed_on(*args, **kwargs)
+                if response and response.last_modified:
+                    latest_record = response.last_modified.replace(
+                        tzinfo=timezone.utc

Review comment:
       this assumes that superset server runs in utc zone, it may be safer to 
make it as a superset config variable




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