Skip to content

Commit

Permalink
Add previously-linked accounts to user profile
Browse files Browse the repository at this point in the history
Only ACM staff view users will see this. Add tests.
  • Loading branch information
amstilp committed May 31, 2024
1 parent 38d6920 commit fd8c792
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
28 changes: 27 additions & 1 deletion gregor_django/templates/users/user_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ <h5>Verified Date</h5>
</ul>
{% elif object.useremailentry_set.all %}
<ul>
{% for uee in object.useremailentry_set.all %}
{% for uee in user_email_entries %}
<li><i class="bi bi-hourglass-split"></i> AnVIL account user email verification in progress for email: {{ uee.email }}
<ul>
<li>Email sent: {{ uee.date_verification_email_sent }}</li>
Expand All @@ -98,10 +98,36 @@ <h5>Verified Date</h5>
{% endif %}
{% endif %}
<p class='alert alert-secondary mt-3'><i class="bi bi-question-circle-fill"></i> If this is incorrect, please contact the DCC at <a href="mailto:{{ DCC_CONTACT_EMAIL }}">{{ DCC_CONTACT_EMAIL }}</a></p>

</div><i class="bi bi-c-square"></i>


</div>


{% if perms.anvil_consortium_manager.anvil_consortium_manager_staff_view and unlinked_accounts %}
<div class='card card-shadow-sm mt-3'>
<div class='card-header'>
<h3><i class="bi bi-clock-history"></i> Previously-linked accounts</h3>
</div>
<div class='card-body'>
<ul>
{% for account in unlinked_accounts %}
<li><a href="{{ account.get_absolute_url }}">{{ account.email }}</a></li>
{% endfor %}
</ul>
</div><i class="bi bi-c-square"></i>
</div>
{% endif %}

</div>
</div>

</div>
{% endblock content %}



<div class="bg-light">

</div>
26 changes: 25 additions & 1 deletion gregor_django/users/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import json

import pytest
from anvil_consortium_manager.models import AnVILProjectManagerAccess
from anvil_consortium_manager.tests.factories import AccountFactory
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AnonymousUser
from django.contrib.auth.models import AnonymousUser, Permission
from django.contrib.messages.middleware import MessageMiddleware
from django.contrib.sessions.middleware import SessionMiddleware
from django.http import HttpRequest
Expand Down Expand Up @@ -108,6 +110,28 @@ def test_not_authenticated(self, user: User, rf: RequestFactory):
assert response.url == f"{login_url}?next=/fake-url/"


class UserDetailTest(TestCase):
def test_unlinked_accounts(self):
"""The unlinked accounts are in the context."""
staff_user = User.objects.create_user(username="test", password="test")
staff_user.user_permissions.add(
Permission.objects.get(codename=AnVILProjectManagerAccess.STAFF_VIEW_PERMISSION_CODENAME)
)
staff_user.user_permissions.add(
Permission.objects.get(codename=AnVILProjectManagerAccess.STAFF_EDIT_PERMISSION_CODENAME)
)
account = AccountFactory.create(verified=True)
account_user = account.user
account.unlink_user()
account.save()
self.client.force_login(staff_user)
response = self.client.get(reverse("users:detail", kwargs={"username": account_user.username}))
self.assertIn("unlinked_accounts", response.context_data)
self.assertEqual(len(response.context_data["unlinked_accounts"]), 1)
self.assertIn(account, response.context_data["unlinked_accounts"])
self.assertContains(response, "Previously-linked accounts")


class UserAutocompleteViewTest(TestCase):
def setUp(self):
"""Set up test class."""
Expand Down
8 changes: 8 additions & 0 deletions gregor_django/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ class UserDetailView(LoginRequiredMixin, DetailView):
slug_field = "username"
slug_url_kwarg = "username"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["unlinked_accounts"] = self.object.unlinked_accounts.all()
print(context["unlinked_accounts"])
context["user_email_entries"] = self.object.useremailentry_set.filter(date_verified=None)
context["is_me"] = self.request.user == self.object
return context


user_detail_view = UserDetailView.as_view()

Expand Down

0 comments on commit fd8c792

Please sign in to comment.