From 6a09ce489c53f31408ca72b362a81266d21ef9a3 Mon Sep 17 00:00:00 2001 From: Robyn Marowitz Date: Thu, 27 Jul 2023 13:48:59 -0600 Subject: [PATCH 1/7] Add additional role --- usaon_vta_survey/constants/roles.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usaon_vta_survey/constants/roles.py b/usaon_vta_survey/constants/roles.py index 97e880b6..ef3b73d2 100644 --- a/usaon_vta_survey/constants/roles.py +++ b/usaon_vta_survey/constants/roles.py @@ -1,5 +1,5 @@ ROLES = [ 'admin', - # 'respondent', + 'respondent', # 'analyst', ] From 95f963aba77fd954f43a2db3204afd6422f51e1f Mon Sep 17 00:00:00 2001 From: Robyn Marowitz Date: Thu, 27 Jul 2023 14:24:54 -0600 Subject: [PATCH 2/7] Add user view with table --- usaon_vta_survey/routes/__init__.py | 1 + usaon_vta_survey/routes/users.py | 13 +++++++++++ usaon_vta_survey/templates/base.html | 1 + usaon_vta_survey/templates/users.html | 31 +++++++++++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 usaon_vta_survey/routes/users.py create mode 100644 usaon_vta_survey/templates/users.html diff --git a/usaon_vta_survey/routes/__init__.py b/usaon_vta_survey/routes/__init__.py index 4e7f74bc..92acccdf 100644 --- a/usaon_vta_survey/routes/__init__.py +++ b/usaon_vta_survey/routes/__init__.py @@ -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 diff --git a/usaon_vta_survey/routes/users.py b/usaon_vta_survey/routes/users.py new file mode 100644 index 00000000..6f3a18c1 --- /dev/null +++ b/usaon_vta_survey/routes/users.py @@ -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, + ) diff --git a/usaon_vta_survey/templates/base.html b/usaon_vta_survey/templates/base.html index 08736176..5b474495 100644 --- a/usaon_vta_survey/templates/base.html +++ b/usaon_vta_survey/templates/base.html @@ -11,6 +11,7 @@

US AON VTA Survey System

Home {{user_login_buttons(current_user)}} + Users
diff --git a/usaon_vta_survey/templates/users.html b/usaon_vta_survey/templates/users.html new file mode 100644 index 00000000..ebd4bf93 --- /dev/null +++ b/usaon_vta_survey/templates/users.html @@ -0,0 +1,31 @@ +{% extends 'base.html' %} + + +{% block content %} +

{% block title %}Users{% endblock %}

+ + {% if current_user.role=='admin' %} + + + + + + + + + + {% for user in users %} + + + + + + + + {% endfor %} + +
idNameRoleAffiliationBio
{{user.id}} {{user.name}}{{user.role}}{{user.affiliation}}{{user.biography}}
+ {% else %} +

Please login to view this page.

+ {% endif %} +{% endblock %} From 5b21282e61332489d5c2a0bbf33d9edb3cdf202c Mon Sep 17 00:00:00 2001 From: Robyn Marowitz Date: Thu, 27 Jul 2023 14:28:25 -0600 Subject: [PATCH 3/7] Remove else statement --- usaon_vta_survey/templates/users.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/usaon_vta_survey/templates/users.html b/usaon_vta_survey/templates/users.html index ebd4bf93..a39a5885 100644 --- a/usaon_vta_survey/templates/users.html +++ b/usaon_vta_survey/templates/users.html @@ -25,7 +25,5 @@

{% block title %}Users{% endblock %}

{% endfor %} - {% else %} -

Please login to view this page.

{% endif %} {% endblock %} From 0f08df52fda10fcc995e9e390e42b4230b3d8204 Mon Sep 17 00:00:00 2001 From: Robyn Marowitz Date: Thu, 27 Jul 2023 15:49:52 -0600 Subject: [PATCH 4/7] Update where user list shows --- usaon_vta_survey/templates/base.html | 1 - .../templates/macros/user_login_management_buttons.j2 | 10 ++++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/usaon_vta_survey/templates/base.html b/usaon_vta_survey/templates/base.html index 5b474495..08736176 100644 --- a/usaon_vta_survey/templates/base.html +++ b/usaon_vta_survey/templates/base.html @@ -11,7 +11,6 @@

US AON VTA Survey System

Home {{user_login_buttons(current_user)}} - Users
diff --git a/usaon_vta_survey/templates/macros/user_login_management_buttons.j2 b/usaon_vta_survey/templates/macros/user_login_management_buttons.j2 index c3449ccd..d70719b1 100644 --- a/usaon_vta_survey/templates/macros/user_login_management_buttons.j2 +++ b/usaon_vta_survey/templates/macros/user_login_management_buttons.j2 @@ -1,7 +1,13 @@ {% macro user_login_buttons(current_user) -%} {% if current_user.is_authenticated %} - Profile - Logout + {% if current_user.role=='admin' %} + Profile + Users + Logout + {% else %} + Profile + Logout + {% endif %} {% else %} Login {% endif %} From 3a3a055069c1281d1d06bd489f59b092c728f40b Mon Sep 17 00:00:00 2001 From: Robyn Marowitz Date: Thu, 27 Jul 2023 16:24:43 -0600 Subject: [PATCH 5/7] Add warning for non admin attempting to access user list --- usaon_vta_survey/templates/users.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/usaon_vta_survey/templates/users.html b/usaon_vta_survey/templates/users.html index a39a5885..6760150b 100644 --- a/usaon_vta_survey/templates/users.html +++ b/usaon_vta_survey/templates/users.html @@ -4,7 +4,9 @@ {% block content %}

{% block title %}Users{% endblock %}

- {% if current_user.role=='admin' %} + {% if not current_user.role=='admin' %} +

You don't belong here! This page is for admins only.

+ {% else %} From 97a6ceef1a51e162086744bcf7311c316974cd72 Mon Sep 17 00:00:00 2001 From: Robyn Marowitz Date: Thu, 27 Jul 2023 16:27:58 -0600 Subject: [PATCH 6/7] Rename macro file --- usaon_vta_survey/templates/base.html | 2 +- ...gement_buttons.j2 => login_button_or_private_nav_buttons.j2} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename usaon_vta_survey/templates/macros/{user_login_management_buttons.j2 => login_button_or_private_nav_buttons.j2} (100%) diff --git a/usaon_vta_survey/templates/base.html b/usaon_vta_survey/templates/base.html index 08736176..98ab71cd 100644 --- a/usaon_vta_survey/templates/base.html +++ b/usaon_vta_survey/templates/base.html @@ -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 %} diff --git a/usaon_vta_survey/templates/macros/user_login_management_buttons.j2 b/usaon_vta_survey/templates/macros/login_button_or_private_nav_buttons.j2 similarity index 100% rename from usaon_vta_survey/templates/macros/user_login_management_buttons.j2 rename to usaon_vta_survey/templates/macros/login_button_or_private_nav_buttons.j2 From 1752c1f011e28f6b1f54476997ab52e657244ee7 Mon Sep 17 00:00:00 2001 From: Robyn Marowitz Date: Mon, 31 Jul 2023 09:03:02 -0600 Subject: [PATCH 7/7] Update message page for users not logged in. --- usaon_vta_survey/templates/users.html | 42 +++++++++++++++------------ 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/usaon_vta_survey/templates/users.html b/usaon_vta_survey/templates/users.html index 6760150b..cb4a5956 100644 --- a/usaon_vta_survey/templates/users.html +++ b/usaon_vta_survey/templates/users.html @@ -4,28 +4,32 @@ {% block content %}

{% block title %}Users{% endblock %}

- {% if not current_user.role=='admin' %} -

You don't belong here! This page is for admins only.

+ {% if not current_user.is_authenticated %} +

Please login to view this page.

{% else %} -
+ {% if not current_user.role=='admin' %} +

You don't belong here! This page is for admins only.

+ {% else %} +
- - - - - - + + + + + + - {% for user in users %} - - - - - - - - {% endfor %} + {% for user in users %} + + + + + + + + {% endfor %} -
idNameRoleAffiliationBio
idNameRoleAffiliationBio
{{user.id}} {{user.name}}{{user.role}}{{user.affiliation}}{{user.biography}}
{{user.id}} {{user.name}}{{user.role}}{{user.affiliation}}{{user.biography}}
+ + {% endif %} {% endif %} {% endblock %}