Skip to content

Commit 0dd1af4

Browse files
authored
Merge pull request #3763 from teovin/templates
cleanup user management templates' and views' auth checks
2 parents 320a285 + 632385e commit 0dd1af4

17 files changed

Lines changed: 478 additions & 108 deletions

perma_web/perma/templates/manage-layout.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,32 @@
88
<div id="dashboard-container" class="container cont-fixed">
99
<div class="row">
1010
<div class="col-sm-12">
11-
{% if request.user.is_staff or request.user.is_registrar_user %}
11+
{% if user_management_perms.show_full_manage_title %}
1212
<h1 id="page-title" class="page-title">Manage users and organizations</h1>
13-
{% elif request.user.is_organization_user %}
13+
{% elif user_management_perms.show_org_manage_title %}
1414
<h1 id="page-title" class="page-title">Manage users</h1>
1515
{% endif %}
1616
</div>
1717
</div> <!-- end row -->
1818
<div class="row admin-content">
19-
{% if request.user.is_staff or request.user.is_registrar_user or request.user.is_organization_user %}
19+
{% if user_management_perms.show_manage_sidebar %}
2020
<div class="col-sm-3">
2121

2222
<!-- Dashboard tabs -->
2323
<nav aria-labelledby="page-title">
2424
<ul class="nav nav-pills nav-stacked">
2525

2626
<!-- Manage users -->
27-
{% if request.user.is_staff %}
27+
{% if user_management_perms.show_admin_registrar_nav %}
2828
<li {% if this_page == "users_admin_users" %}class="active" aria-current="page"{% endif %}><a href="{% url 'user_management_manage_admin_user' %}"><span>Admin users</span></a></li>
2929
<li {% if this_page == "users_registrars" %}class="active" aria-current="page"{% endif %}><a href="{% url 'user_management_manage_registrar' %}"><span>Registrars</span></a></li>
3030
{% endif %}
3131

32-
{% if request.user.is_staff or request.user.is_registrar_user %}
32+
{% if user_management_perms.show_registrar_sponsored_nav %}
3333
<li {% if this_page == "users_registrar_users" %}class="active" aria-current="page"{% endif %}><a href="{% url 'user_management_manage_registrar_user' %}"><span>Registrar users</span></a></li>
3434
{% endif %}
3535

36-
{% if request.user.is_staff or request.user.is_registrar_user %}
36+
{% if user_management_perms.show_registrar_sponsored_nav %}
3737
<li {% if this_page == "users_sponsored_users" %}class="active" aria-current="page"{% endif %}><a href="{% url 'user_management_manage_sponsored_user' %}"><span>Sponsored users</span></a></li>
3838
{% endif %}
3939

@@ -43,7 +43,7 @@ <h1 id="page-title" class="page-title">Manage users</h1>
4343
<li {% if this_page == "users_organization_users" %}class="active" aria-current="page"{% endif %}><a href="{% url 'user_management_manage_organization_user' %}"><span>Org users</span></a></li>
4444

4545
<!-- Regular users -->
46-
{% if request.user.is_staff %}
46+
{% if user_management_perms.show_individual_users_nav %}
4747
<li {% if this_page == "users_users" %}class="active" aria-current="page"{% endif %}><a href="{% url 'user_management_manage_user' %}"><span>Users</span></a></li>
4848
{% endif %}
4949
</ul><!--/#dashboard-tabs-->

perma_web/perma/templates/user_management/approve_pending_registrar.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ <h6 class="item-title" id="user-{{ listed_user.id }}">
102102
</h6>
103103
<div class="item-subtitle">{{ listed_user.raw_email }}</div>
104104

105-
{% if request.user.is_staff and listed_user.requested_account_type %}
105+
{% if user_management_perms.show_upgrade_interest_note and listed_user.requested_account_type %}
106106
<div class="item-org">Interested in a {{listed_user.requested_account_type}} account with {{listed_user.requested_account_note}}</div>
107107
{% endif %}
108108
</div>
@@ -117,7 +117,7 @@ <h6 class="item-title" id="user-{{ listed_user.id }}">
117117
{% endif %}
118118
</div>
119119
</div>
120-
{% if request.user.is_staff %}
120+
{% if user_management_perms.can_select_pending_registrar %}
121121
<div>
122122
<button type="submit" name="registrar_user" value="{{ listed_user.email }}" class="btn btn-small pull-right" form="form">Select<span class="sr-only"> {{ listed_user.get_full_name }}</button>
123123
</div>

perma_web/perma/templates/user_management/includes/edit_sponsorship.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% load visible_sponsorships %}
2-
{% if request.user.is_staff %}
2+
{% if user_management_perms.can_use_short_sponsorship_label %}
33
<a class="action" href="{% url 'user_management_manage_single_sponsored_user' listed_user.id %}">edit <span class="sr-only">{{ listed_user.get_full_name}}</span></a>
44
{% else %}
55
<a class="action" href="{% url 'user_management_manage_single_sponsored_user' listed_user.id %}">edit sponsorship{{ listed_user|visible_sponsorships:request.user|length|pluralize }}<span class="sr-only">for {{ listed_user.get_full_name}}</span></a>

perma_web/perma/templates/user_management/manage_orgs.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
{% block dashboardContent %}
77
<h2 class="body-ah">Organizations</h2>
8-
{% if request.user.is_staff or request.user.is_registrar_user %}
8+
{% if user_management_perms.can_add_organization %}
99

1010
<a class="action-heading" data-toggle="collapse" href="#add-member" aria-expanded="false" aria-controls="#add-member"><i class="icon-plus-sign" aria-hidden="true"></i> add<span class="_verbose"> organization</span></a>
1111

@@ -102,7 +102,7 @@ <h3 class="sr-only">Organization List</h3>
102102
</li>
103103
</ul>
104104
</div>
105-
{% if request.user.is_staff %}
105+
{% if user_management_perms.show_registrar_org_filter %}
106106
<div class="dropdown">
107107
<button class="btn-transparent" aria-haspopup="true" aria-expanded="false" data-toggle="dropdown">Registrar <span class="caret"></span></button>
108108
<ul class="dropdown-menu">
@@ -138,7 +138,7 @@ <h4 class="item-title" id="org-{{ org.id }}" tabindex="-1">
138138
{{ org.name }}
139139
</a>
140140
</h4>
141-
{% if request.user.is_staff %}
141+
{% if user_management_perms.show_org_registrar_link %}
142142
<div class="item-affil">
143143
<span class="sr-only">Associated with: </span>
144144
<a href="{% url 'user_management_manage_registrar' %}?q={{org.registrar.name.split|join:'+'|lower}}#registrar-{{ org.registrar.id }}">{{ org.registrar }}</a>
@@ -180,7 +180,7 @@ <h4 class="item-title" id="org-{{ org.id }}" tabindex="-1">
180180
<a class="action" href="{% url 'user_management_manage_single_organization_delete' org.id %}">delete <span class="sr-only">{{ org.name }}</span></a>
181181
{% endif %}
182182
<a class="action" href="{% url 'user_management_manage_single_organization' org.id %}">edit <span class="sr-only">{{ org.name }}</span></a>
183-
{% if request.user.is_staff %}
183+
{% if user_management_perms.can_link_org_admin %}
184184
<a class="action" href="{% url 'admin:perma_organization_change' org.id %}">edit <div class="sr-wrapper"><span class="sr-only">{{ org.name }}</span></div> in admin console</a>
185185
{% endif %}
186186
</div>

perma_web/perma/templates/user_management/manage_registrars.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ <h4 class="item-title" id="registrar-{{ registrar.id }}" tabindex="-1">
167167
</a>
168168
{% else %}
169169
<a class="action" href="{% url 'user_management_manage_single_registrar' registrar.id %}">edit <span class="sr-only">{{ registrar.name }}</span></a>
170-
{% if request.user.is_staff %}
170+
{% if user_management_perms.can_link_registrar_admin %}
171171
<a class="action" href="{% url "admin:perma_registrar_change" registrar.id %}">edit <div class="sr-wrapper"><span class="sr-only">{{ registrar.name }} </span></div>in admin console</a>
172172
{% endif %}
173173
{% endif %}

perma_web/perma/templates/user_management/manage_single_user.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ <h3 class="body-bh">Edit organization affiliation</h3>
5252
{% endfor %}
5353
</div>
5454
{% endif %}
55-
{% if request.user.is_staff %}
55+
{% if user_management_perms.can_delete_or_deactivate %}
5656
<h3 class="body-bh">{% if target_user.is_confirmed %}Deactivate{% else %}Delete{% endif %}</h3>
5757
<a href="{% url delete_user_url target_user.id %}">
58-
<p class="page-dek"><strong>{{ target_user.raw_email}}</strong>'s account was created on {{ target_user.date_joined}}{% if target_user.last_login%} Last login occurred on {{ target_user.last_login}}{% else %}They have never logged in.{% endif %}</p>
58+
<p class="page-dek"><strong>{{ target_user.raw_email}}</strong>'s account was created on {{ target_user.date_joined}}{% if target_user.last_login%}. Last login occurred on {{ target_user.last_login}}{% else %}. They have never logged in.{% endif %}</p>
5959
<span class="field-error">
6060
<i class="icon-trash"></i>
6161

perma_web/perma/templates/user_management/manage_single_user_links.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% extends "manage-layout.html" %}
22

33
{% block dashboardContent %}
4-
<h2 class="body-ah">Links sponsored by {% if request.user.is_staff %}<a href="{% url 'user_management_manage_registrar' %}?q={{registrar.name.split|join:'+'|lower}}#registrar-{{ registrar.id }}">{{ registrar }}</a>{% else %}{{ registrar}}{% endif %} for <a href="{% url 'user_management_manage_sponsored_user' %}?q={{target_user.email|urlencode}}#user-{{ target_user.id }}">{{ target_user }}</a></h2>
4+
<h2 class="body-ah">Links sponsored by {% if user_management_perms.can_link_registrar_in_heading %}<a href="{% url 'user_management_manage_registrar' %}?q={{registrar.name.split|join:'+'|lower}}#registrar-{{ registrar.id }}">{{ registrar }}</a>{% else %}{{ registrar}}{% endif %} for <a href="{% url 'user_management_manage_sponsored_user' %}?q={{target_user.email|urlencode}}#user-{{ target_user.id }}">{{ target_user }}</a></h2>
55
<div class="col-xs-12 col-links">
66
<div class="container item-rows"></div>
77
{% for link in links %}

perma_web/perma/templates/user_management/manage_users.html

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,26 @@ <h2 class="body-ah">{{ pretty_group_name_plural|title }}</h2>
3131

3232
<div class="row row-no-bleed admin-data">
3333
<h3 class="sr-only">Stats</h3>
34-
<div class="col {% if request.user.is_staff and group_name == 'user' %}col-xs-3{% else %}col-xs-4{% endif %} col col-no-gutter admin-data-point">
34+
<div class="col {% if user_management_perms.show_four_column_stats %}col-xs-3{% else %}col-xs-4{% endif %} col col-no-gutter admin-data-point">
3535
<div class="count-label">Users</div>
3636
<div class="count-number">
3737
{{ users.paginator.count|intcomma }}
3838
</div>
3939
</div>
4040

41-
{% if request.user.is_staff and group_name == 'user' %}
41+
{% if user_management_perms.show_deactivated_count %}
4242
<div class="col col-xs-3 col-no-gutter admin-data-point">
4343
<div class="count-label">Deactivated Users</div>
4444
<div class="count-number">{{ deactivated_users }}</div>
4545
</div>
4646
{% endif %}
4747

48-
<div class="col {% if request.user.is_staff and group_name == 'user' %}col-xs-3{% else %}col-xs-4{% endif %} col col-no-gutter admin-data-point">
48+
<div class="col {% if user_management_perms.show_four_column_stats %}col-xs-3{% else %}col-xs-4{% endif %} col col-no-gutter admin-data-point">
4949
<div class="count-label">Unactivated Users</div>
5050
<div class="count-number">{{ unactivated_users }}</div>
5151
</div>
5252

53-
<div class="col {% if request.user.is_staff and group_name == 'user' %}col-xs-3{% else %}col-xs-4{% endif %} col col-no-gutter admin-data-point">
53+
<div class="col {% if user_management_perms.show_four_column_stats %}col-xs-3{% else %}col-xs-4{% endif %} col col-no-gutter admin-data-point">
5454
<div class="count-label">Links</div>
5555
<div class="count-number">{{ total_created_links_count|default:0|intcomma }}</div>
5656
</div>
@@ -125,7 +125,7 @@ <h3 class="sr-only">User List</h3>
125125
</ul>
126126
</div>
127127

128-
{% if request.user.is_staff and group_name == 'user' %}
128+
{% if user_management_perms.show_upgrade_interest_filter %}
129129
<div class="dropdown">
130130
<button class="btn-transparent" aria-haspopup="true" aria-expanded="false" data-toggle="dropdown">Upgrade interest <span class="caret"></span></button>
131131
<ul class="dropdown-menu">
@@ -151,7 +151,7 @@ <h3 class="sr-only">User List</h3>
151151
<li>
152152
<a {% if status == 'active' %}class="selected" aria-current="true" {% endif %}href="?{% current_query_string page='' status="active" %}"><i aria-hidden="true" class="icon-ok"></i> Active</a>
153153
</li>
154-
{% if request.user.is_staff and group_name|slice:"-4:" == 'user' %}
154+
{% if user_management_perms.show_deactivated_filter %}
155155
<li>
156156
<a {% if status == 'deactivated' %}class="selected" aria-current="true" {% endif %}href="?{% current_query_string page='' status="deactivated" %}"><i aria-hidden="true" class="icon-ok"></i> Deactivated</a>
157157
</li>
@@ -162,7 +162,7 @@ <h3 class="sr-only">User List</h3>
162162
</ul>
163163
</div>
164164

165-
{% if request.user.is_staff or request.user.is_registrar_user %}
165+
{% if user_management_perms.show_affiliation_filters %}
166166
{% if group_name == 'organization_user' %}
167167
<div class="dropdown">
168168
<button class="btn-transparent" aria-haspopup="true" aria-expanded="false" data-toggle="dropdown">Organization <span class="caret"></span></button>
@@ -199,8 +199,7 @@ <h3 class="sr-only">User List</h3>
199199
{% endif %}
200200
{% endif %}
201201

202-
{% if request.user.is_staff %}
203-
{% if not group_name == 'user' and not group_name == 'admin_user' %}
202+
{% if user_management_perms.show_registrar_filter %}
204203
<div class="dropdown">
205204
<button class="btn-transparent" aria-haspopup="true" aria-expanded="false" data-toggle="dropdown">Registrar <span class="caret"></span></button>
206205
<ul class="dropdown-menu">
@@ -221,7 +220,6 @@ <h3 class="sr-only">User List</h3>
221220
{% endif %}
222221
</ul>
223222
</div>
224-
{% endif %}
225223
{% endif %}
226224
</div><!-- sort filter bar -->
227225
</div><!-- admin found -->
@@ -255,11 +253,11 @@ <h4 class="item-title" id="user-{{ listed_user.id }}">
255253
</div>
256254
{% endif %}
257255

258-
{% if request.user.is_staff and listed_user.requested_account_type %}
256+
{% if user_management_perms.show_upgrade_interest_note and listed_user.requested_account_type %}
259257
<div class="item-org">Interested in a {{listed_user.requested_account_type}} account with {{listed_user.requested_account_note}}</div>
260258
{% endif %}
261259

262-
{% if group_name == 'registrar_user' and request.user.is_staff %}
260+
{% if user_management_perms.show_listed_user_registrar %}
263261
<div class="item-affil"><span class="sr-only">Member of:</span> <a href="{% url 'user_management_manage_registrar' %}?q={{listed_user.registrar.name.split|join:'+'|lower}}#registrar-{{ listed_user.registrar.id }}">{{ listed_user.registrar.name }}</a></div>
264262
{% endif %}
265263

@@ -269,7 +267,7 @@ <h4 class="item-title" id="user-{{ listed_user.id }}">
269267
{% for sponsorship in sponsorships %}
270268
<div class="item-sponsor-group">
271269
<span class="item-sponsor-label">
272-
{% if request.user.is_staff %}
270+
{% if user_management_perms.can_link_sponsored_user_links %}
273271
<a href="{% url 'user_management_manage_single_sponsored_user_links' listed_user.id sponsorship.registrar.id %}">{{ sponsorship.registrar.name }}: view links
274272
{% if sponsorship.status == 'inactive' %} (inactive sponsorship){% endif %}</a>
275273
{% else %}
@@ -307,7 +305,7 @@ <h4 class="item-title" id="user-{{ listed_user.id }}">
307305
<div>
308306
<div class="item-status">
309307
{% if listed_user.is_active %}
310-
{% if request.user.is_staff %}
308+
{% if user_management_perms.can_edit_remove_as_staff %}
311309
{% if group_name == 'sponsored_user' %}
312310
{% include "user_management/includes/edit_sponsorship.html" %}
313311
{% elif group_name == 'organization_user' %}
@@ -317,7 +315,7 @@ <h4 class="item-title" id="user-{{ listed_user.id }}">
317315
{% else %}
318316
<a class="action action-delete" href="{% url 'user_management_manage_single_admin_user_remove' listed_user.id %}">remove <span class="sr-only">{{ listed_user.get_full_name}}</span></a>
319317
{% endif %}
320-
{% elif request.user.is_registrar_user %}
318+
{% elif user_management_perms.can_edit_remove_as_registrar %}
321319
{% if group_name == 'organization_user' %}
322320
<a class="action action-delete" href="{% url single_user_url listed_user.id %}">edit/remove <span class="sr-only">{{ listed_user.get_full_name}}</span></a>
323321
{% elif group_name == 'registrar_user' %}
@@ -330,11 +328,11 @@ <h4 class="item-title" id="user-{{ listed_user.id }}">
330328
{% endif %}
331329
{% elif listed_user.is_confirmed %}
332330
<span class="text-warning">deactivated account</span>
333-
{% if request.user.is_staff %}
331+
{% if user_management_perms.can_reactivate %}
334332
<a class="action" href="{% url reactivate_user_url listed_user.id %}">reactivate <span class="sr-only">{{ listed_user.get_full_name}}</span></a>
335333
{% endif %}
336334
{% else %}
337-
{% if request.user.is_staff %}
335+
{% if user_management_perms.can_manage_unconfirmed_as_staff %}
338336
{% if group_name == 'sponsored_user' %}
339337
{% include "user_management/includes/edit_sponsorship.html" %}
340338
{% else %}
@@ -351,13 +349,13 @@ <h4 class="item-title" id="user-{{ listed_user.id }}">
351349
{% endif %}
352350
{% endif %}
353351
</div>
354-
{% if request.user.is_staff %}
352+
{% if user_management_perms.can_link_user_admin %}
355353
<div class="item-status"><a class="action" href="{% url "admin:perma_linkuser_change" listed_user.id %}">edit <div class="sr-wrapper"><span class="sr-only">{{ listed_user.get_full_name }} </span></div>in admin console</span></a></div>
356354
{% endif %}
357355
{% if not listed_user.is_confirmed %}
358356
<div class="item-status"><a class="action" href="{% url 'user_management_resend_activation' listed_user.id %}">resend activation email <span class="sr-only"> to {{ listed_user.get_full_name}}</span></a></div>
359357
{% endif %}
360-
{% if group_name == 'sponsored_user' and not request.user.is_staff %}
358+
{% if user_management_perms.can_view_sponsored_user_links %}
361359
<div class="item-status"><a class="action" href="{% url 'user_management_manage_single_sponsored_user_links' listed_user.id request.user.registrar.id %}">view links</a></div>
362360
{% endif %}
363361
</div>

perma_web/perma/templates/user_management/user_add_to_registrar_confirm.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h3 class="body-bh">Add {{ user_email }} to registrar</h3>
1313
{% if object.id %}
1414
<p>{{ user_email }} already has an account. Would you like to add them to a registrar?</p>
1515

16-
{% if request.user.is_staff %}
16+
{% if user_management_perms.can_show_registrar_upgrade_warning %}
1717
{% if object.is_organization_user %}
1818
<p><b>WARNING:</b> This user is currently a member of the following organizations. Upgrading them to a registrar will REPLACE these affiliations:</p>
1919
<ul>

0 commit comments

Comments
 (0)