-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1121 from TOMToolkit/1102-create-a-user-profile-page
1102 create a user profile page
- Loading branch information
Showing
8 changed files
with
130 additions
and
8 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
tom_common/templates/tom_common/partials/confirm_user_delete.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{% load tom_common_extras %} | ||
|
||
<div class="modal fade" id="userDeleteModal" tabindex="-1" role="dialog" aria-labelledby="userDeleteModalLabel" aria-hidden="true"> | ||
<div class="modal-dialog" role="document"> | ||
<div class="modal-content"> | ||
<div class="modal-header alert-danger"> | ||
<h5 class="modal-title" id="userDeleteModalLabel">Warning: This will permanently delete user.</h5> | ||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
Are you sure that you want to remove <b>{{ user.username }}</b> from {% tom_name %}? | ||
</div> | ||
<div class="modal-footer"> | ||
<form action="{% url 'user-delete' user.id %}" method="POST"> | ||
{% csrf_token %} | ||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> | ||
<button type="submit" class="btn btn-danger" role="button">Delete User</button> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{% load tom_common_extras %} | ||
|
||
<div class="card"> | ||
<div class="card-header"> | ||
<div style="display: flex; justify-content: space-between"> | ||
<h4 class="card-title">User Info</h4> | ||
<div> | ||
<a title="Edit" href="{% url 'user-update' pk=user.id %}" ><i class="fa fa-pencil" aria-hidden="true"></i></a> | ||
<a title="Remove User" data-toggle="modal" data-target="#userDeleteModal" href="#" ><i class="fa fa-trash" aria-hidden="true"></i></a> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="card-body"> | ||
<dl class="row"> | ||
{% for key, value in profile_data.items %} | ||
{% if value %} | ||
<dt class="col-sm-6" >{% verbose_name user key %}</dt> | ||
<dd class="col-sm-6">{{ value }}</dd> | ||
{% endif %} | ||
{% endfor %} | ||
</dl> | ||
</div> | ||
</div> | ||
|
||
<!-- Modal --> | ||
{% include 'tom_common/partials/confirm_user_delete.html' %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{% extends 'tom_common/base.html' %} | ||
{% load tom_common_extras user_extras %} | ||
{% load bootstrap4 %} | ||
{% block title %}User Profile{% endblock %} | ||
{% block content %} | ||
<h3> | ||
{% if user.first_name or user.last_name %} | ||
{{ user.first_name }} {{ user.last_name }} ({{ user.username }}) | ||
{% else %} | ||
{{ user.username }} | ||
{% endif %} | ||
</h3> | ||
|
||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-lg"> | ||
{% user_data user %} | ||
</div> | ||
<div class="col-lg"> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,15 +66,19 @@ def test_user_delete(self): | |
self.assertEqual(response.status_code, 302) | ||
self.assertFalse(User.objects.filter(pk=user.id).exists()) | ||
|
||
def test_non_superuser_cannot_delete_other_user(self): | ||
user = User.objects.create(username='deleteme', email='[email protected]', password='deleted') | ||
other_user = User.objects.create_user(username='other', email='[email protected]', password='other') | ||
self.client.force_login(user) | ||
response = self.client.post(reverse('user-delete', kwargs={'pk': other_user.id})) | ||
self.assertRedirects(response, reverse('user-delete', kwargs={'pk': user.id})) | ||
|
||
def test_must_be_superuser(self): | ||
user = User.objects.create_user(username='notallowed', email='[email protected]', password='notallowed') | ||
self.client.force_login(user) | ||
response = self.client.get(reverse('admin-user-change-password', kwargs={'pk': user.id})) | ||
self.assertEqual(response.status_code, 302) | ||
|
||
response = self.client.get(reverse('user-delete', kwargs={'pk': user.id})) | ||
self.assertEqual(response.status_code, 302) | ||
|
||
def test_user_can_update_self(self): | ||
user = User.objects.create(username='luke', password='forc3') | ||
self.client.force_login(user) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters