forked from rapidpro/rapidpro
-
Notifications
You must be signed in to change notification settings - Fork 24
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 #5571 from nyaruka/tokens_as_real_list_page
Convert API tokens page to be real list page
- Loading branch information
Showing
11 changed files
with
136 additions
and
146 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -3237,39 +3237,6 @@ def test_recover(self): | |
self.assertEqual(0, FailedLogin.objects.filter(username="[email protected]").count()) # deleted | ||
self.assertEqual(1, FailedLogin.objects.filter(username="[email protected]").count()) # unaffected | ||
|
||
def test_tokens(self): | ||
tokens_url = reverse("orgs.user_tokens") | ||
|
||
self.assertRequestDisallowed(tokens_url, [None, self.user, self.agent]) | ||
self.assertReadFetch(tokens_url, [self.admin], context_object=self.admin) | ||
|
||
# add user to other org and create API tokens for both | ||
self.org2.add_user(self.admin, OrgRole.EDITOR) | ||
token1 = APIToken.create(self.org, self.admin) | ||
token2 = APIToken.create(self.org, self.admin) | ||
APIToken.create(self.org, self.editor) # other user | ||
APIToken.create(self.org2, self.admin) # other org | ||
|
||
response = self.assertReadFetch(tokens_url, [self.admin], context_object=self.admin, choose_org=self.org) | ||
self.assertEqual([token1, token2], list(response.context["tokens"])) | ||
self.assertContentMenu(tokens_url, self.admin, ["New Token"], choose_org=self.org) | ||
|
||
# can POST to create new token | ||
response = self.client.post(tokens_url, {"new": "1"}) | ||
self.assertRedirect(response, reverse("orgs.user_tokens")) | ||
self.assertEqual(3, self.admin.get_api_tokens(self.org).count()) | ||
token3 = self.admin.get_api_tokens(self.org).order_by("created").last() | ||
|
||
# and now option to create new token is gone because we've reached the limit | ||
response = self.assertReadFetch(tokens_url, [self.admin], context_object=self.admin, choose_org=self.org) | ||
self.assertEqual([token1, token2, token3], list(response.context["tokens"])) | ||
self.assertContentMenu(tokens_url, self.admin, [], choose_org=self.org) | ||
|
||
# and POSTing is noop | ||
response = self.client.post(tokens_url, {"new": "1"}) | ||
self.assertRedirect(response, reverse("orgs.user_tokens")) | ||
self.assertEqual(3, self.admin.get_api_tokens(self.org).count()) | ||
|
||
def test_verify_email(self): | ||
self.assertEqual(self.admin.settings.email_status, "U") | ||
self.assertTrue(self.admin.settings.email_verification_secret) | ||
|
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
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,58 @@ | ||
{% extends "orgs/base/list.html" %} | ||
{% load i18n temba %} | ||
|
||
{% block modaxes %} | ||
<temba-modax header="{{ _("Delete Token") |escapejs }}" id="delete-token"> | ||
</temba-modax> | ||
{% endblock modaxes %} | ||
{% block pre-table %} | ||
<div class="mb-4"> | ||
{% url "api.v2.root" as api_url %} | ||
{% blocktrans trimmed with api_url=api_url limit=token_limit %} | ||
These are your personal tokens for accessing the <a href="{{ api_url }}">API</a>. You can have a maximum of {{ limit }}. | ||
{% endblocktrans %} | ||
</div> | ||
{% endblock pre-table %} | ||
{% block table %} | ||
<table class="list lined scrolled"> | ||
<tr> | ||
<th>{% trans "Key" %}</th> | ||
<th>{% trans "Last Used" %}</th> | ||
<th></th> | ||
</tr> | ||
{% for obj in object_list %} | ||
<tr> | ||
<td>{{ obj.key }}</td> | ||
<td> | ||
{% if obj.last_used_on %} | ||
{{ obj.last_used_on|duration }} | ||
{% else %} | ||
-- | ||
{% endif %} | ||
</td> | ||
<td class="w-10"> | ||
<div style="visibility:hidden" | ||
onclick="event.stopPropagation(); showDeleteTokenModal('{{ obj.key }}');" | ||
class="pl-2 pt-1 delete-link linked text-gray-400"> | ||
<temba-icon name="delete_small"> | ||
</temba-icon> | ||
</div> | ||
</td> | ||
</tr> | ||
{% empty %} | ||
<tr class="empty_list"> | ||
<td colspan="99" class="text-center">{% trans "No tokens" %}</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
{% endblock table %} | ||
{% block extra-script %} | ||
{{ block.super }} | ||
<script> | ||
function showDeleteTokenModal(key) { | ||
var modax = document.querySelector('#delete-token'); | ||
modax.endpoint = `/apitoken/delete/${key}/`; | ||
modax.open = true; | ||
} | ||
</script> | ||
{% endblock extra-script %} |
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
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
Oops, something went wrong.