Skip to content

Commit

Permalink
Fix get chart (#223)
Browse files Browse the repository at this point in the history
Fix the sensors/<id>/chart view and allow non-admins to see their own sensor data with this view.


* Let non-admins view a graph of each of their own account's sensors.

I forgot to remove these in PR #168.

* Fix sensors/<id>/chart view

* Changelog entry
  • Loading branch information
Flix6x committed Oct 26, 2021
1 parent 3a4aa3b commit 8a5089e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
1 change: 1 addition & 0 deletions documentation/changelog.rst
Expand Up @@ -18,6 +18,7 @@ Bugfixes
-----------
* Fix users resetting their own password [see `PR #195 <http://www.github.com/SeitaBV/flexmeasures/pull/195>`_]
* Fix scheduling for heterogeneous settings, for instance, involving sensors with different timezones and/or resolutions [see `PR #207 <http://www.github.com/SeitaBV/flexmeasures/pull/207>`_]
* Fix ``sensors/<id>/chart`` view [see `PR #223 <http://www.github.com/SeitaBV/flexmeasures/pull/223>`_]

Infrastructure / Support
----------------------
Expand Down
28 changes: 13 additions & 15 deletions flexmeasures/ui/views/sensors.py
@@ -1,7 +1,9 @@
import json

from altair.utils.html import spec_to_html
from flask import current_app
from flask_classful import FlaskView, route
from flask_security import login_required, roles_required
from flask_security import login_required
from marshmallow import fields
from webargs.flaskparser import use_kwargs

Expand All @@ -20,7 +22,6 @@ class SensorUI(FlaskView):
route_base = "/sensors"

@login_required
@roles_required("admin") # todo: remove after we check for sensor ownership
@route("/<id>/chart/")
@use_kwargs(
{
Expand All @@ -34,23 +35,20 @@ class SensorUI(FlaskView):
)
def get_chart(self, id, **kwargs):
"""GET from /sensors/<id>/chart"""
chart_specs = SensorAPI().get_chart(
id, include_data=True, as_html=True, **kwargs
)
chart_specs = SensorAPI().get_chart(id, include_data=True, **kwargs)
return spec_to_html(
chart_specs,
"vega-lite",
vega_version=current_app.config.get("FLEXMEASURES_JS_VERSIONS").vega,
vegaembed_version=current_app.config.get(
"FLEXMEASURES_JS_VERSIONS"
).vegaembed,
vegalite_version=current_app.config.get(
"FLEXMEASURES_JS_VERSIONS"
).vegalite,
json.loads(chart_specs),
mode="vega-lite",
vega_version=current_app.config.get("FLEXMEASURES_JS_VERSIONS")["vega"],
vegaembed_version=current_app.config.get("FLEXMEASURES_JS_VERSIONS")[
"vegaembed"
],
vegalite_version=current_app.config.get("FLEXMEASURES_JS_VERSIONS")[
"vegalite"
],
)

@login_required
@roles_required("admin") # todo: remove after we check for sensor ownership
def get(self, id: int):
"""GET from /sensors/<id>"""
return render_flexmeasures_template(
Expand Down

0 comments on commit 8a5089e

Please sign in to comment.