Skip to content

Commit

Permalink
fix: set up different URL for wagtail content API
Browse files Browse the repository at this point in the history
  • Loading branch information
ngurenyaga committed Nov 22, 2021
1 parent 960873a commit 23b73e7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
wagtail_api_router.register_endpoint("documents", DocumentsAPIViewSet)

urlpatterns += [
path("api/cms/", wagtail_api_router.urls),
path("contentapi/", wagtail_api_router.urls),
path("admin/", include(wagtailadmin_urls)),
path("documents/", include(wagtaildocs_urls)),
re_path(
Expand Down
8 changes: 8 additions & 0 deletions mycarehub/templates/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
{% block content %}
<h1>Page not found</h1>

{% block sidebar %}
{#% do not show the sidebar %#}
{% endblock sidebar %}

{% block topbar %}
{#% do not show the top bar %#}
{% endblock topbar %}

<!-- 404 Error Text -->
<div class="text-center">
<div class="error mx-auto" data-text="404">404</div>
Expand Down
2 changes: 1 addition & 1 deletion mycarehub/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def default_organisation():
return org.pk
except (ProgrammingError, Exception): # pragma: nocover
# this will occur during initial migrations on a clean db
return settings.DEFAULT_ORG_ID
return uuid.UUID(settings.DEFAULT_ORG_ID)


class TermsOfService(Model):
Expand Down
7 changes: 7 additions & 0 deletions mycarehub/users/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.dispatch import receiver
from django.http import HttpRequest
from django.template.loader import get_template
from rest_framework.authtoken.models import Token

LOGGER = logging.getLogger(__name__)
BASIC_PERMISSIONS = [
Expand Down Expand Up @@ -148,3 +149,9 @@ def send_user_account_approved_email(user):
# record the notification so that we do not re-send it
user.approval_notified = True
user.save()


@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_auth_token(sender, instance=None, created=False, **kwargs):
if created:
Token.objects.create(user=instance)
24 changes: 24 additions & 0 deletions mycarehub/users/tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.contrib.auth import get_user_model
from faker import Faker
from model_bakery import baker
from rest_framework.authtoken.models import Token

from mycarehub.users.signals import (
BASIC_PERMISSIONS,
Expand Down Expand Up @@ -153,3 +154,26 @@ def test_account_confirmed_handler_newly_created_whitelist_user():
email="noreply@savannahghi.org",
)
assert account_confirmed_handler(User, user, created=True) is None


def test_create_auth_token():
# create a user
user = baker.make(
User,
email="token@savannahghi.org",
)

# confirm that a token was created
token = Token.objects.get(user=user)
assert token is not None

# update the user
user.email = "token2@savannahghi.org"
user.save()

# re-fetch the token
token2 = Token.objects.get(user__email="token2@savannahghi.org")
assert token2 is not None

# confirm that the token was not regenerated
assert token.pk == token2.pk

0 comments on commit 23b73e7

Please sign in to comment.