Skip to content

Create Site permission error in User Admin interface #466

@dplarson

Description

@dplarson

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:

  1. run a local instance of the arbiter_data database, API and Dashboard
  2. log into the Dashboard with a user with User Admin permissions
  3. open the User Admin page: Account >> User Administration
  4. open the Permissions tab
  5. 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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions