-
{% blocktrans %}A token lets a script or a tool use the REST API as you, without your password or OTP: send it as Authorization: Token <token>. A password change does not delete tokens: delete a token you no longer use, or one that may have leaked.{% endblocktrans %}
- {% if api_tokens %}
- {% include "api_token_table.html" %}
- {% endif %}
-
-
{% endblock %}
-{% block script %}
-{% include "tab_from_hash.html" %}
-{% endblock %}
diff --git a/accounts/tests/test_views.py b/accounts/tests/test_views.py
index 46f01ffe..789395ae 100644
--- a/accounts/tests/test_views.py
+++ b/accounts/tests/test_views.py
@@ -236,7 +236,7 @@ class AccountsTestCase(TestCase):
"keypublic": self.rsa_key,
},
)
- self.assertRedirects(response, reverse("accounts:profile"))
+ self.assertRedirects(response, reverse("accounts:profile") + "#sshkeys")
key = UserSSHKey.objects.get(keyname="keyname")
self.assertEqual(key.keyname, "keyname")
@@ -246,7 +246,22 @@ class AccountsTestCase(TestCase):
self.assertEqual(response.status_code, 200)
response = self.client.post(reverse("accounts:ssh_key_delete", args=[key.id]))
- self.assertRedirects(response, reverse("accounts:profile"))
+ self.assertRedirects(response, reverse("accounts:profile") + "#sshkeys")
+
+ def test_the_profile_lists_keys_and_tokens_where_links_land(self):
+ admin = get_user_model().objects.get(username="admin")
+ key = UserSSHKey.objects.create(user=admin, keyname="laptop", keypublic=self.rsa_key)
+ response = self.client.get(reverse("accounts:profile"))
+ # other pages link to #sshkeys and #apitokens
+ self.assertContains(response, 'id="sshkeys"')
+ self.assertContains(response, 'id="apitokens"')
+ self.assertContains(response, f'href="{reverse("accounts:ssh_key_delete", args=[key.id])}"')
+ self.assertContains(response, f'href="{reverse("accounts:change_password")}"')
+ # an LDAP user's password is changed in LDAP
+ admin.set_unusable_password()
+ admin.save()
+ self.client.force_login(admin)
+ self.assertNotContains(self.client.get(reverse("accounts:profile")), f'href="{reverse("accounts:change_password")}"')
def test_validate_ssh_key(self):
self.assertFalse(validate_ssh_key(""))
diff --git a/accounts/views.py b/accounts/views.py
index 9ec4f9be..ef75f062 100644
--- a/accounts/views.py
+++ b/accounts/views.py
@@ -124,7 +124,7 @@ def ssh_key_create(request):
with audit(request, None, f"SSH key {key_form.cleaned_data['keyname']}", "add"):
key_form.save()
messages.success(request, _("SSH key added"))
- return redirect("accounts:profile")
+ return redirect(reverse("accounts:profile") + "#sshkeys")
return render(
request,
@@ -142,7 +142,7 @@ def ssh_key_delete(request, pk, user_id=None):
if user_id is None:
ssh_key = get_object_or_404(UserSSHKey, pk=pk, user=request.user)
subject = f"SSH key {ssh_key.keyname}"
- back = reverse("accounts:profile")
+ back = reverse("accounts:profile") + "#sshkeys"
elif request.user.is_superuser:
ssh_key = get_object_or_404(UserSSHKey, pk=pk, user_id=user_id)
subject = f"SSH key {ssh_key.keyname} of {ssh_key.user.username}"