Skip to content

Commit

Permalink
Merge pull request #355 from djangonaut-space/develop
Browse files Browse the repository at this point in the history
Production Release - Application work and some caching

PRs:
- #327
- #328
- #330
- #331
- #335
- #264
- #309
- #341
- #342
- #333
- #334
- #343
- #347
- #345
- #348
- #340
- #351
  • Loading branch information
tim-schilling authored Mar 29, 2024
2 parents f19f79b + 427d1fe commit eae67eb
Show file tree
Hide file tree
Showing 76 changed files with 1,206 additions and 242 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ select = B950
extend-ignore = E203, E501
per-file-ignores =
*/__init__.py:F401
*/migrations/*:B950,
*/puput_migrations/*:B950,
indymeet/settings/*.py:F403,F405
6 changes: 6 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# .git-blame-ignore-revs
# Apply pre-commit to the project
b9f6c18a38a38728e27889762300d6a30821bfaa
# Run pre-commit on all files
# + 3x subsequent, manual flake8 B950 fixes
a945aa754469fff23731ad58b27ca6644d5dfe22
144cfa12ad8947fe1c2de75a3cd06bb9cca325f0
5af48fc6cf958c416400b51fc03f331f21ee192c
d8db7d19915ca88b8b427fab8b928af29229fd07
3 changes: 0 additions & 3 deletions .github/workflows/develop_djangonaut_space.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ jobs:
env:
ENVIRONMENT: 'production'
DJANGO_SETTINGS_MODULE: 'indymeet.settings.production'
APPINSIGHTS_INSTRUMENTATIONKEY: ${{ secrets.STAGING_APPINSIGHTS_INSTRUMENTATIONKEY }}
APPLICATIONINSIGHTSAGENT_EXTENSION_ENABLED: 'true'
DEBUG: 'True'
RECAPTCHA_PRIVATE_KEY: ${{ secrets.RECAPTCHA_PRIVATE_KEY }}
RECAPTCHA_PUBLIC_KEY: ${{ secrets.RECAPTCHA_PUBLIC_KEY }}
SCM_DO_BUILD_DURING_DEPLOYMENT: 'true'
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/main_djangonaut-space.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ jobs:
env:
ENVIRONMENT: 'production'
DJANGO_SETTINGS_MODULE: 'indymeet.settings.production'
APPINSIGHTS_INSTRUMENTATIONKEY: ${{ secrets.APPINSIGHTS_INSTRUMENTATIONKEY }}
APPLICATIONINSIGHTSAGENT_EXTENSION_ENABLED: 'true'
DEBUG: False
RECAPTCHA_PRIVATE_KEY: ${{ secrets.RECAPTCHA_PRIVATE_KEY }}
RECAPTCHA_PUBLIC_KEY: ${{ secrets.RECAPTCHA_PUBLIC_KEY }}
SCM_DO_BUILD_DURING_DEPLOYMENT: 'true'
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ This is an example of how to list things you need to use the software and how to
```
```sh
postgres=# CREATE DATABASE "djangonaut-space";
CREATE DATABASE
postgres=# CREATE USER djangonaut WITH SUPERUSER PASSWORD 'djangonaut';
postgres=# GRANT ALL PRIVILEGES ON DATABASE 'djangonaut-space' TO djangonaut;
```
```sh
postgres=# exit
Expand Down
6 changes: 5 additions & 1 deletion accounts/factories.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from __future__ import annotations

import factory
from django.db.models.signals import post_save
from accounts.models import CustomUser, UserProfile

from accounts.models import CustomUser
from accounts.models import UserProfile


@factory.django.mute_signals(post_save)
Expand Down
43 changes: 31 additions & 12 deletions accounts/forms.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
from __future__ import annotations

from captcha.fields import ReCaptchaField
from captcha.widgets import ReCaptchaV2Checkbox
from django import forms
from django.contrib.auth.forms import UserChangeForm
from django.contrib.auth.forms import UserCreationForm
from django_recaptcha.fields import ReCaptchaField
from django_recaptcha.widgets import ReCaptchaV2Checkbox

from .models import CustomUser


class CustomUserCreationForm(UserCreationForm):
captcha = ReCaptchaField(widget=ReCaptchaV2Checkbox())
email_consent = forms.BooleanField(
help_text="Required: Please check this to consent to receiving "
"administrative emails like: email verification, password reset etc.",
label="Email Consent*",
)
class BaseCustomUserForm(forms.ModelForm):
receive_newsletter = forms.BooleanField(
required=False,
help_text="Optional: Please check this to opt-in for receiving "
Expand All @@ -35,6 +28,15 @@ class CustomUserCreationForm(UserCreationForm):
"emails about upcoming program sessions. You can opt-out on "
"your profile page at anytime.",
)


class CustomUserCreationForm(BaseCustomUserForm, UserCreationForm):
captcha = ReCaptchaField(widget=ReCaptchaV2Checkbox())
email_consent = forms.BooleanField(
help_text="Required: Please check this to consent to receiving "
"administrative emails like: email verification, password reset etc.",
label="Email Consent*",
)
accepted_coc = forms.BooleanField(
required=True,
label="Accept CoC*",
Expand Down Expand Up @@ -65,12 +67,29 @@ def __init__(self, *args, **kwargs):
self.fields["email"].required = True


class CustomUserChangeForm(UserChangeForm):
class Meta:
class CustomUserChangeForm(BaseCustomUserForm):
class Meta(BaseCustomUserForm):
model = CustomUser
fields = (
"username",
"email",
"first_name",
"last_name",
"receive_program_updates",
"receive_event_updates",
"receive_newsletter",
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["email"].required = True
user = kwargs["instance"]
if user.profile.email_confirmed:
help_text = (
"<p class='text-amber-600'>If you update your email"
" you will need to reconfirm your email address.</p>"
)
self.fields["email"].help_text = help_text
else:
help_text = "<p class='text-amber-600'>You have not confirmed your email address.</p>"
self.fields["email"].help_text = help_text
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Generated by Django 4.1.13 on 2024-02-15 19:42
from __future__ import annotations

from django.db import migrations, models
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
("accounts", "0007_alter_userprofile_user"),
]
Expand Down
5 changes: 4 additions & 1 deletion accounts/tests/test_activate_view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from django.test import Client, TestCase
from __future__ import annotations

from django.test import Client
from django.test import TestCase
from django.urls import reverse
from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_encode
Expand Down
38 changes: 37 additions & 1 deletion accounts/tests/test_profile_view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from django.test import Client, TestCase
from __future__ import annotations

from django.test import Client
from django.test import TestCase
from django.urls import reverse

from accounts.factories import ProfileFactory
Expand All @@ -13,6 +16,7 @@ def setUpTestData(cls):
profile = ProfileFactory.create(user__username="test")
cls.user = profile.user
cls.profile_url = reverse("profile")
cls.update_profile_url = reverse("update_user")

def test_redirect_when_unauthenticated(self):
response = self.client.get(self.profile_url, follow=True)
Expand All @@ -26,3 +30,35 @@ def test_profile(self):
self.assertContains(response, "Profile Info")
self.assertContains(response, "test")
self.assertContains(response, "Jane Doe")

def test_update_profile_initial_data(self):
self.client.force_login(self.user)
response = self.client.get(self.update_profile_url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Update Profile Info")
self.assertContains(response, "test")
self.assertContains(response, "Jane")
self.assertContains(response, "Doe")
self.assertContains(response, "You have not confirmed your email address.")

def test_update_profile(self):
self.client.force_login(self.user)
response = self.client.post(
self.update_profile_url,
data={
"username": "janedoe",
"email": "jane@newemail.com",
"first_name": "Jane",
"last_name": "Doe",
"receive_newsletter": True,
"receive_program_updates": True,
"receive_event_updates": True,
},
follow=True,
)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Profile Info")
self.user.profile.refresh_from_db()
self.assertEqual(self.user.profile.receiving_newsletter, True)
self.assertEqual(self.user.profile.receiving_event_updates, True)
self.assertEqual(self.user.profile.receiving_program_updates, True)
12 changes: 9 additions & 3 deletions accounts/tests/test_signup_view.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from __future__ import annotations

from unittest.mock import patch

from django.core import mail
from django.test import Client, TestCase
from django.test import Client
from django.test import TestCase
from django.urls import reverse

from accounts.models import CustomUser
Expand All @@ -17,7 +20,7 @@ def test_signup_template_renders(self):
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Registration")

@patch("captcha.fields.ReCaptchaField.validate", return_value=True)
@patch("django_recaptcha.fields.ReCaptchaField.validate", return_value=True)
def test_signup_template_post_success(self, mock_captcha):
response = self.client.post(
self.url,
Expand All @@ -41,7 +44,10 @@ def test_signup_template_post_success(self, mock_captcha):
self.assertContains(response, "Registration")
self.assertContains(
response,
"Your registration was successful. Please check your email provided for a confirmation link.",
(
"Your registration was successful."
" Please check your email provided for a confirmation link."
),
)
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(
Expand Down
5 changes: 4 additions & 1 deletion accounts/tests/test_unsubscribe_view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from django.test import Client, TestCase
from __future__ import annotations

from django.test import Client
from django.test import TestCase
from django.urls import reverse

from accounts.factories import ProfileFactory
Expand Down
8 changes: 8 additions & 0 deletions accounts/urls.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
from __future__ import annotations

from django.contrib.auth import views as auth_views
from django.urls import include
from django.urls import path

from .views import ActivateAccountView
from .views import profile
from .views import SignUpView
from .views import unsubscribe
from .views import UpdateUserView

urlpatterns = [
path(
"login/",
auth_views.LoginView.as_view(redirect_field_name="next_page"),
name="login",
),
path("", include("django.contrib.auth.urls")),
path("profile/", profile, name="profile"),
path("profile/update/", UpdateUserView.as_view(), name="update_user"),
path("signup/", SignUpView.as_view(), name="signup"),
path(
"activate/<uidb64>/<token>",
Expand Down
Loading

0 comments on commit eae67eb

Please sign in to comment.