-
Notifications
You must be signed in to change notification settings - Fork 6
Description
From the User Administration interface, creating a new Permission of data type Sites fails with an Internal Server Error and an error in logs as jinja2.exceptions.UndefinedError: 'form_data' is undefined. However, creating a Permission of any other data type works as expected (i.e., you click on the data type and are redirected to the form for defining the new permission). This happens both in a local dev environment and in a production environment.
The root cause seems to be the jinja2 if-else code is the sfa_dash/templates/forrms/admin/permissions_form.html that switches the row_macro based on the data_type. More specifically, it seems that when that code block was first added via PR #175, a if-else statement was mistakenly placed inside another if-else statement.
The code as it currently exists: https://github.com/SolarArbiter/solarforecastarbiter-dashboard/blob/master/sfa_dash/templates/forms/admin/permissions_form.html#L11-L20
{% if data_type == 'site' %}
{% set row_macro = table_macros.site_row %}
{% elif data_type == 'report' %}
{% set row_macro = table_macros.report_row %}
{% else %}
{% if form_data is not defined %}
{% set form_data = {} %}
{% endif %}
{% set row_macro = table_macros.data_row %}
{% endif %}where the set row_macro = table_macros.data_row got pushed to outside the if-else for the data type by the if-else for the form data.
My initial tests in a local dev environment show moving that set row_macro = table_macros.data_row resolves the issue (which makes table_macros.data_row used if the data type is anything except Site or Report):
{% if data_type == 'site' %}
{% set row_macro = table_macros.site_row %}
{% elif data_type == 'report' %}
{% set row_macro = table_macros.report_row %}
{% else %}
{% set row_macro = table_macros.data_row %}
{% endif %}
{% if form_data is not defined %}
{% set form_data = {} %}
{% endif %}Steps to reproduce:
- run a local instance of the
arbiter_datadatabase, API and Dashboard - log into the Dashboard with a user with User Admin permissions
- open the User Admin page: Account >> User Administration
- open the Permissions tab
- click "Sites" as the data type under the "Create a New Permission" section
What I expect to happen: step 5 redirects to the form for defining a new Site permission
What actually happens: step 5 returns an Internal Server Error, even though clicking "Observation" or other data types work as expected