Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create user list view #69

Merged
merged 7 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion usaon_vta_survey/constants/roles.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ROLES = [
'admin',
# 'respondent',
'respondent',
# 'analyst',
]
1 change: 1 addition & 0 deletions usaon_vta_survey/routes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
import usaon_vta_survey.routes.profile
import usaon_vta_survey.routes.survey
import usaon_vta_survey.routes.surveys
import usaon_vta_survey.routes.users
13 changes: 13 additions & 0 deletions usaon_vta_survey/routes/users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from flask import render_template

from usaon_vta_survey import app
from usaon_vta_survey.models.tables import User


@app.route('/users')
def view_users():
users = User.query.order_by(User.name).all()
return render_template(
'users.html',
users=users,
)
2 changes: 1 addition & 1 deletion usaon_vta_survey/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% from 'macros/user_login_management_buttons.j2' import user_login_buttons %}
{% from 'macros/login_button_or_private_nav_buttons.j2' import user_login_buttons %}

<!doctype html>
<head>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% macro user_login_buttons(current_user) -%}
{% if current_user.is_authenticated %}
{% if current_user.role=='admin' %}
<a href="{{url_for('profile', user_id=current_user.id)}}">Profile</a>
<a href="{{url_for('view_users')}}">Users</a>
<a href="{{url_for('logout')}}">Logout</a>
{% else %}
<a href="{{url_for('profile', user_id=current_user.id)}}">Profile</a>
<a href="{{url_for('logout')}}">Logout</a>
{% endif %}
{% else %}
<a href="{{url_for('login')}}">Login</a>
{% endif %}

{%- endmacro -%}

This file was deleted.

31 changes: 31 additions & 0 deletions usaon_vta_survey/templates/users.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% extends 'base.html' %}


{% block content %}
<h2>{% block title %}Users{% endblock %}</h1>

{% if not current_user.role=='admin' %}
Copy link

@MattF-NSIDC MattF-NSIDC Jul 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work as expected for logged out users? I'd expect an error like undefined has no attribute 'role'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this to reflect that.

<h3>You don't belong here! This page is for admins only.</h3>
{% else %}
<table>

<tr>
<th>id</th>
<th>Name</th>
<th>Role</th>
<th>Affiliation</th>
<th>Bio</th>

{% for user in users %}
<tr>
<td>{{user.id}} </td>
<td>{{user.name}}</td>
<td>{{user.role}}</td>
<td>{{user.affiliation}}</td>
<td>{{user.biography}}</td>
</tr>
{% endfor %}

</table>
{% endif %}
{% endblock %}