Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production deployment #291

Merged
merged 30 commits into from
Feb 18, 2024
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fa27828
fix media issue
dawnwages Jan 27, 2024
a01fa1c
fix media issue, change name from Azure storage Key to Azure account key
dawnwages Jan 27, 2024
ac8f5de
fix media issue, change name from Azure storage Key to Azure account key
dawnwages Jan 27, 2024
e847975
Improvements (#252)
dawnwages Jan 27, 2024
1cb3c87
Improvements (#253)
dawnwages Jan 27, 2024
9562251
Improvements (#254)
dawnwages Jan 27, 2024
fc7e561
Improvements (#255)
dawnwages Jan 27, 2024
b61c8e4
Update package.json
dawnwages Jan 27, 2024
6dcd3e8
Improvements (#256)
dawnwages Jan 27, 2024
ee8eab4
Improvements (#257)
dawnwages Jan 27, 2024
0b96b62
Revert "Improvements (#252)"
dawnwages Jan 29, 2024
a7a7a20
Merge branch 'develop' of github.com:dawnwages/wagtail-indymeet into …
dawnwages Jan 29, 2024
d927aaf
remove node and python upgrade
dawnwages Jan 30, 2024
971353c
Fixed accounts signup form. (#267)
sarahboyce Feb 14, 2024
aec55cb
Add Sentry setup. (#268)
sarahboyce Feb 14, 2024
cc73a84
Account page updates - tests, styling, email template. (#269)
sarahboyce Feb 16, 2024
5484f8e
Create MIT LICENSE
tim-schilling Feb 16, 2024
cf43a84
Account form updates. (#278)
sarahboyce Feb 16, 2024
99f205d
Run the migrate command after builds, but before deployment. (#277)
tim-schilling Feb 16, 2024
050054a
Log all errors and above to the console
tim-schilling Feb 17, 2024
69548d7
Remove migrate from postbuild script.
tim-schilling Feb 17, 2024
b641b3d
Attempt to install supervisor during the build
tim-schilling Feb 17, 2024
ca24ff3
I want to know if this file ends up in the app service or not.
tim-schilling Feb 17, 2024
e6b147c
Revise supervisor install to install on server
tim-schilling Feb 17, 2024
18ddd03
Add a supervisord section to supervisord.conf
tim-schilling Feb 17, 2024
5365170
Attempt to install supervisor via pip
tim-schilling Feb 17, 2024
80896f1
We still need to run gunicorn at the end of startup.sh
tim-schilling Feb 17, 2024
578cb3d
Add Factory boy for tests. (#289)
sarahboyce Feb 18, 2024
8ceb4a6
Add sign up for email notifications as an option in the session list.…
sarahboyce Feb 18, 2024
5fa8db3
Render non-field errors and other small tweaks. (#292)
sarahboyce Feb 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Djangonaut Space

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -342,7 +342,7 @@ Distributed under the MIT License. See `LICENSE.txt` for more information.
<!-- CONTACT -->
## Contact

- Dawn Wages - [@dawnwagessays](https://twitter.com/dawnwagessays) - [@fly00gemini8712@mastodon.online](https://mastodon.online/@fly00gemini8712)
- Dawn Wages - [@dawnwagessays](https://twitter.com/bajoranengineer) - [@bajoranengineer@mastodon.online](https://mastodon.online/@bajoranengineer)
- [Djangonaut Space Organizers](mailto:[email protected])


23 changes: 23 additions & 0 deletions accounts/factories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import factory
from django.db.models.signals import post_save
from accounts.models import CustomUser, UserProfile


@factory.django.mute_signals(post_save)
class ProfileFactory(factory.django.DjangoModelFactory):
class Meta:
model = UserProfile

user = factory.SubFactory("accounts.factories.UserFactory", profile=None)


@factory.django.mute_signals(post_save)
class UserFactory(factory.django.DjangoModelFactory):
class Meta:
model = CustomUser

username = factory.Sequence(lambda n: "user_%d" % n)
first_name = "Jane"
last_name = "Doe"
email = "[email protected]"
profile = factory.RelatedFactory(ProfileFactory, factory_related_name="user")
16 changes: 12 additions & 4 deletions accounts/forms.py
Original file line number Diff line number Diff line change
@@ -19,13 +19,20 @@ class CustomUserCreationForm(UserCreationForm):
receive_newsletter = forms.BooleanField(
required=False,
help_text="Optional: Please check this to opt-in for receiving "
"general updates about community and events. You can "
"opt-out on your profile page at anytime.",
"a newsletter containing general updates about Djangonaut Space. "
"This newsletter does not yet exist. You can opt-out on your profile "
"page at anytime.",
)
receive_event_updates = forms.BooleanField(
required=False,
help_text="Optional: Please check this to opt-in for receiving "
"emails to events you register to. You can opt-out on "
"emails about upcoming community events. You can opt-out on "
"your profile page at anytime.",
)
receive_program_updates = forms.BooleanField(
required=False,
help_text="Optional: Please check this to opt-in for receiving "
"emails about upcoming program sessions. You can opt-out on "
"your profile page at anytime.",
)
accepted_coc = forms.BooleanField(
@@ -48,8 +55,9 @@ class Meta:
"password2",
"email_consent",
"accepted_coc",
"receive_newsletter",
"receive_program_updates",
"receive_event_updates",
"receive_newsletter",
)

def __init__(self, *args, **kwargs):
18 changes: 18 additions & 0 deletions accounts/migrations/0008_userprofile_receiving_program_updates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.13 on 2024-02-15 19:42

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("accounts", "0007_alter_userprofile_user"),
]

operations = [
migrations.AddField(
model_name="userprofile",
name="receiving_program_updates",
field=models.BooleanField(default=False),
),
]
1 change: 1 addition & 0 deletions accounts/models.py
Original file line number Diff line number Diff line change
@@ -61,6 +61,7 @@ class UserProfile(models.Model):
email_confirmed = models.BooleanField(default=False)
receiving_newsletter = models.BooleanField(default=False)
receiving_event_updates = models.BooleanField(default=False)
receiving_program_updates = models.BooleanField(default=False)

def __str__(self):
return self.user.username
57 changes: 57 additions & 0 deletions accounts/tests/test_activate_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from django.test import Client, TestCase
from django.urls import reverse
from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_encode

from accounts.factories import UserFactory
from accounts.tokens import account_activation_token


class ActivateViewTests(TestCase):
def setUp(self):
self.client = Client()

@classmethod
def setUpTestData(cls):
cls.user = UserFactory.create()

def test_user_does_not_exist(self):
activate_url = reverse(
"activate_account",
kwargs={
"uidb64": urlsafe_base64_encode(force_bytes("500")),
"token": account_activation_token.make_token(self.user),
},
)
response = self.client.get(activate_url, follow=True)
self.assertRedirects(response, reverse("signup"))
self.assertContains(response, "Your confirmation link is invalid.")
self.user.profile.refresh_from_db()
self.assertFalse(self.user.profile.email_confirmed)

def test_invalid_token(self):
activate_url = reverse(
"activate_account",
kwargs={
"uidb64": urlsafe_base64_encode(force_bytes(self.user.pk)),
"token": "INVALID_TOKEN",
},
)
response = self.client.get(activate_url, follow=True)
self.assertRedirects(response, reverse("signup"))
self.assertContains(response, "Your confirmation link is invalid.")
self.user.profile.refresh_from_db()
self.assertFalse(self.user.profile.email_confirmed)

def test_activate_email(self):
activate_url = reverse(
"activate_account",
kwargs={
"uidb64": urlsafe_base64_encode(force_bytes(self.user.pk)),
"token": account_activation_token.make_token(self.user),
},
)
response = self.client.get(activate_url)
self.assertRedirects(response, reverse("profile"))
self.user.profile.refresh_from_db()
self.assertTrue(self.user.profile.email_confirmed)
28 changes: 28 additions & 0 deletions accounts/tests/test_profile_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django.test import Client, TestCase
from django.urls import reverse

from accounts.factories import ProfileFactory


class ProfileViewTests(TestCase):
def setUp(self):
self.client = Client()

@classmethod
def setUpTestData(cls):
profile = ProfileFactory.create(user__username="test")
cls.user = profile.user
cls.profile_url = reverse("profile")

def test_redirect_when_unauthenticated(self):
response = self.client.get(self.profile_url, follow=True)
self.assertRedirects(response, f"{reverse('login')}?next={self.profile_url}")

def test_profile(self):
self.client.force_login(self.user)
response = self.client.get(self.profile_url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Welcome, Jane")
self.assertContains(response, "Profile Info")
self.assertContains(response, "test")
self.assertContains(response, "Jane Doe")
59 changes: 59 additions & 0 deletions accounts/tests/test_signup_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from unittest.mock import patch

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

from accounts.models import CustomUser


class SignUpViewTests(TestCase):
def setUp(self):
self.client = Client()
self.url = reverse("signup")

def test_signup_template_renders(self):
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Registration")

@patch("captcha.fields.ReCaptchaField.validate", return_value=True)
def test_signup_template_post_success(self, mock_captcha):
response = self.client.post(
self.url,
data={
"username": "janedoe",
"email": "[email protected]",
"first_name": "Jane",
"last_name": "Doe",
"password1": "secretpassword123",
"password2": "secretpassword123",
"email_consent": True,
"accepted_coc": True,
"receive_newsletter": True,
"receive_program_updates": True,
"receive_event_updates": True,
"g-recaptcha-response": "dummy-response",
},
follow=True,
)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Registration")
self.assertContains(
response,
"Your registration was successful. Please check your email provided for a confirmation link.",
)
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(
mail.outbox[0].subject, "Djangonaut Space Registration Confirmation"
)
self.assertIn(
"Thank you for signing up to Djangonaut Space! Click the link to verify your email:",
mail.outbox[0].body,
)
created_user = CustomUser.objects.get(username="janedoe")
self.assertTrue(created_user.is_active)
self.assertTrue(created_user.profile.accepted_coc)
self.assertTrue(created_user.profile.receiving_newsletter)
self.assertTrue(created_user.profile.receiving_program_updates)
self.assertTrue(created_user.profile.receiving_event_updates)
43 changes: 43 additions & 0 deletions accounts/tests/test_unsubscribe_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from django.test import Client, TestCase
from django.urls import reverse

from accounts.factories import ProfileFactory


class UnsubscribeViewTests(TestCase):
def setUp(self):
self.client = Client()

@classmethod
def setUpTestData(cls):
profile = ProfileFactory.create(
receiving_newsletter=True,
receiving_program_updates=True,
receiving_event_updates=True,
)
cls.user = profile.user
cls.unsubscribe_url = reverse(
"unsubscribe", kwargs={"user_id": cls.user.id, "token": "dummytoken"}
)

def test_user_does_not_exist(self):
response = self.client.get(
reverse("unsubscribe", kwargs={"user_id": 500, "token": "dummytoken"})
)
self.assertEqual(response.status_code, 404)

def test_redirect_when_unauthenticated(self):
response = self.client.get(self.unsubscribe_url)
self.assertRedirects(
response, f"{reverse('login')}?next={self.unsubscribe_url}"
)

def test_unsubscribe(self):
self.client.force_login(self.user)
response = self.client.get(self.unsubscribe_url)
self.assertEqual(response.status_code, 200)
profile = self.user.profile
profile.refresh_from_db()
self.assertFalse(profile.receiving_newsletter)
self.assertFalse(profile.receiving_program_updates)
self.assertFalse(profile.receiving_event_updates)
31 changes: 17 additions & 14 deletions accounts/views.py
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
from django.shortcuts import get_object_or_404
from django.shortcuts import redirect
from django.shortcuts import render
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils.encoding import force_bytes
from django.utils.encoding import force_str
@@ -66,13 +67,17 @@ def form_valid(self, form):
user = self.object
user.profile.accepted_coc = form.cleaned_data["accepted_coc"]
user.profile.receiving_newsletter = form.cleaned_data["receive_newsletter"]
user.profile.receiving_program_updates = form.cleaned_data[
"receive_program_updates"
]
user.profile.receiving_event_updates = form.cleaned_data[
"receive_event_updates"
]
user.profile.save(
update_fields=[
"accepted_coc",
"receiving_newsletter",
"receiving_program_updates",
"receiving_event_updates",
]
)
@@ -83,15 +88,18 @@ def form_valid(self, form):
"token": account_activation_token.make_token(user),
},
)
message = (
"To confirm your email address on djangonaut.space please visit the link: "
+ self.request.build_absolute_uri(invite_link)
)
unsubscribe_link = user.profile.create_unsubscribe_link()
email_dict = {
"cta_link": self.request.build_absolute_uri(invite_link),
"name": user.get_full_name(),
"unsubscribe_link": unsubscribe_link,
}
send_mail(
"Djangonaut Space Registration Confirmation",
message,
render_to_string("emails/email_confirmation.txt", email_dict),
settings.DEFAULT_FROM_EMAIL,
[user.email],
html_message=render_to_string("emails/email_confirmation.html", email_dict),
fail_silently=False,
)
return super().form_valid(form)
@@ -115,17 +123,12 @@ def unsubscribe(request, user_id, token):
) or user.profile.check_token(token):
# unsubscribe them
profile = user.profile
if request.GET.get("events", None):
email_type = "events"
profile.receiving_event_updates = False
else:
email_type = "newsletters"
profile.receiving_newsletter = False
profile.receiving_event_updates = False
profile.receiving_program_updates = False
profile.receiving_newsletter = False
profile.save()

return render(
request, "registration/unsubscribed.html", {"email_type": email_type}
)
return render(request, "registration/unsubscribed.html")

# Otherwise redirect to login page
next_url = reverse(
Loading