From 7fb74308a8ac1e56a3c9ddce42415194d4064aba Mon Sep 17 00:00:00 2001 From: LuizaMaluf Date: Fri, 17 Nov 2023 19:33:32 -0300 Subject: [PATCH 01/28] fix(automatic-login): authentication done --- apps/users/views.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/users/views.py b/apps/users/views.py index 012556e..5695a9a 100644 --- a/apps/users/views.py +++ b/apps/users/views.py @@ -1,3 +1,4 @@ +from django.contrib.auth import login from django.http import HttpRequest, HttpResponse from django.shortcuts import redirect, render from django.views import View @@ -15,7 +16,14 @@ def get(self, request: HttpRequest) -> HttpResponse: def post(self, request: HttpRequest) -> HttpResponse: form = CreateUserForm(self.request.POST) if form.is_valid(): - form.save() - return redirect("login") + user = form.save() + + login( + request, + user, + backend="django.contrib.auth.backends.ModelBackend", + ) + + return redirect("home") return render(request, self.template_name, {"form": form}) From 44f82fdd6801b396866d45230862cc7c7bd71120 Mon Sep 17 00:00:00 2001 From: kyomi Date: Fri, 17 Nov 2023 22:09:16 -0300 Subject: [PATCH 02/28] docs(apps/users): document the login authentication backend --- apps/users/views.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/users/views.py b/apps/users/views.py index 5695a9a..adabd04 100644 --- a/apps/users/views.py +++ b/apps/users/views.py @@ -18,12 +18,10 @@ def post(self, request: HttpRequest) -> HttpResponse: if form.is_valid(): user = form.save() - login( - request, - user, - backend="django.contrib.auth.backends.ModelBackend", - ) - + # Since we have multiple authentication backends, we need to + # specify which one we want to use. In this case, we want to + # use the :class:`ModelBackend`, which is the default one. + login(request, user, "django.contrib.auth.backends.ModelBackend") return redirect("home") return render(request, self.template_name, {"form": form}) From acdd05296ecab219d770f1bee537de84410e2175 Mon Sep 17 00:00:00 2001 From: LuizaMaluf Date: Sun, 19 Nov 2023 11:40:48 -0300 Subject: [PATCH 03/28] fix(automatic-login): tests --- .pre-commit-config.yaml | 2 +- apps/users/tests.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c443555..e216ee5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,7 +33,7 @@ repos: hooks: - id: flake8 - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.5.1 + rev: v1.6.1 hooks: - id: mypy additional_dependencies: diff --git a/apps/users/tests.py b/apps/users/tests.py index b509386..24dd7d4 100644 --- a/apps/users/tests.py +++ b/apps/users/tests.py @@ -1,7 +1,9 @@ from django.test import TestCase +from django.urls import reverse from django.utils.translation import gettext as _ from apps.users.admin import UserAdmin +from apps.users.forms import CreateUserForm from apps.users.models import User @@ -86,3 +88,37 @@ def test_add_fieldsets(self) -> None: ) self.assertEqual(UserAdmin.add_fieldsets, expected_add_fieldsets) + + +class RegisterViewTest(TestCase): + def setUp(self) -> None: + self.url = reverse("users:register") + self.valid_data = { + "username": "testuser", + "email": "test@example.com", + "password1": "TestPassword123", + "password2": "TestPassword123", + } + + def test_register_view_get(self) -> None: + response = self.client.get(self.url) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, "registration/register.html") + self.assertIsInstance(response.context["form"], CreateUserForm) + + def test_post_valid_data(self) -> None: + response = self.client.post( + self.url, data=self.valid_data, folloe=True + ) + # Verifica se a página foi redirecionada + # para a página inicial após o registro + self.assertRedirects(response, reverse("home")) + # Verifica se o usuário foi criado no banco de dados + self.assertTrue( + User.objects.filter(username=self.valid_data["username"]).exists() + ) + # Autentica manualmente o usuário + user = User.objects.get(username=self.valid_data["username"]) + self.client.force_login(user) + # Verifica se o usuário está autenticado após o registro + self.assertTrue(self.client.session["_auth_user_id"]) From fd390995b7b64e9e27e9f60ee5e4bc239772ccf5 Mon Sep 17 00:00:00 2001 From: jpcfarias Date: Sun, 19 Nov 2023 21:44:57 -0300 Subject: [PATCH 04/28] docs(change-web-to-django): installation guide changed --- docs/source/installation.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/installation.rst b/docs/source/installation.rst index b5272ba..cf17078 100644 --- a/docs/source/installation.rst +++ b/docs/source/installation.rst @@ -141,7 +141,7 @@ executará as migrações. Faça isso com o seguinte comando: .. code-block:: bash - $ docker compose run --rm web python manage.py migrate + $ docker compose run --rm django python manage.py migrate .. hint:: @@ -221,10 +221,10 @@ seguinte comando: .. code-block:: bash - $ docker compose run --rm web python manage.py createsuperuser + $ docker compose run --rm django python manage.py createsuperuser E para criar migrações do banco de dados, use o seguinte comando: .. code-block:: bash - $ docker compose run --rm web python manage.py makemigrations + $ docker compose run --rm django python manage.py makemigrations From f693761974c32be56199a9555a9cd7c1823c693e Mon Sep 17 00:00:00 2001 From: jpcfarias Date: Sun, 19 Nov 2023 22:35:35 -0300 Subject: [PATCH 05/28] docs(doc-sprint4): Add sprint4 documentation --- docs/source/scrum/sprints/sprint-4.rst | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 docs/source/scrum/sprints/sprint-4.rst diff --git a/docs/source/scrum/sprints/sprint-4.rst b/docs/source/scrum/sprints/sprint-4.rst new file mode 100644 index 0000000..7ece615 --- /dev/null +++ b/docs/source/scrum/sprints/sprint-4.rst @@ -0,0 +1,30 @@ +Sprint 4 +======== + +:bdg-info:`19/11/2023` + +Resumo +------ + +Nesta sprint, a equipe de desenvolvimento começou a trabalhar na segunda release. As principais atividades foram o início do desenvolvimento da parte de submissões e a estilização da página de login para melhor acessibilidade do usuário. + + +Changelog +---------- + +- `Criar app de submissões (#66) `_ +- `App inicial de submissões (PR) (#77) `_ +- `Adicionar validadores em todas as páginas de admin (PR) (#76) `_ +- `Estilizar página de login (#63) `_ +- `Estilizar página de login (PR) (#75) `_ +- `Adicionar documentação da Sprint 03 (#62) `_ +- `Adicionar Documentação da Sprint 03 (PR) (#73) `_ +- `Retirar nome de ex-integrante do grupo (#72) `_ +- `Remover Nome de ex-Integrante (PR) (#74) `_ +- `Adicionar Documentação da Sprint 02 (#67) `_ +- `Adicionar documentação da Sprint 02 (PR) (#70) `_ +- `Renomear o app apps.problems para apps.tasks (#31) `_ +- `Rename apps.problems to apps.tasks (PR) (#61) `_ +- `Initial problems form development (PR) (#65) `_ +- `Add integrations with CI services (PR) (#59) `_ +- `Bump django from 4.2.5 to 4.2.7 (PR) (#58) `_ From cdbdb8ef897c3efbd8de89c39d4c964252651a4a Mon Sep 17 00:00:00 2001 From: jpcfarias Date: Sun, 19 Nov 2023 22:39:36 -0300 Subject: [PATCH 06/28] docs(doc-reuniao5): Add reuniao5 documentation --- docs/source/reunioes/atas/reuniao-05.rst | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 docs/source/reunioes/atas/reuniao-05.rst diff --git a/docs/source/reunioes/atas/reuniao-05.rst b/docs/source/reunioes/atas/reuniao-05.rst new file mode 100644 index 0000000..acd4e53 --- /dev/null +++ b/docs/source/reunioes/atas/reuniao-05.rst @@ -0,0 +1,9 @@ +Reunião 04 +========== + +:bdg-info:`13/11/2023` :bdg-warning:`Sprint 4` + +Resumo +------ + +Esta reunião teve como objetivos discutir o progresso, anunciar a saida de um integrante e possiveis duvidas From 777653ccc900d3ad563ae3bbfb6eb0a549d3fd45 Mon Sep 17 00:00:00 2001 From: jpcfarias Date: Sun, 19 Nov 2023 22:42:10 -0300 Subject: [PATCH 07/28] docs(doc-reuniao6): Add reuniao6 documentation --- docs/source/reunioes/atas/reuniao-06.rst | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 docs/source/reunioes/atas/reuniao-06.rst diff --git a/docs/source/reunioes/atas/reuniao-06.rst b/docs/source/reunioes/atas/reuniao-06.rst new file mode 100644 index 0000000..2abe5ec --- /dev/null +++ b/docs/source/reunioes/atas/reuniao-06.rst @@ -0,0 +1,9 @@ +Reunião 04 +========== + +:bdg-info:`16/11/2023` :bdg-warning:`Sprint 4` + +Resumo +------ + +Esta reunião teve como objetivos redistribuir as partes de cada integrante e a reduçao do prazo para entrega das issues From 3b6dff5dbb5a91847d2136e3fb70033658d64205 Mon Sep 17 00:00:00 2001 From: jpcfarias Date: Sun, 19 Nov 2023 22:47:24 -0300 Subject: [PATCH 08/28] docs(doc-reuniao7): Add reuniao7 documentation and fix other doc archives --- docs/source/reunioes/atas/reuniao-05.rst | 4 ++-- docs/source/reunioes/atas/reuniao-06.rst | 6 +++--- docs/source/reunioes/atas/reuniao-07.rst | 9 +++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 docs/source/reunioes/atas/reuniao-07.rst diff --git a/docs/source/reunioes/atas/reuniao-05.rst b/docs/source/reunioes/atas/reuniao-05.rst index acd4e53..1408114 100644 --- a/docs/source/reunioes/atas/reuniao-05.rst +++ b/docs/source/reunioes/atas/reuniao-05.rst @@ -1,9 +1,9 @@ Reunião 04 ========== -:bdg-info:`13/11/2023` :bdg-warning:`Sprint 4` +:bdg-info:`25/10/2023` :bdg-warning:`Sprint 3` Resumo ------ -Esta reunião teve como objetivos discutir o progresso, anunciar a saida de um integrante e possiveis duvidas +Esta reunião teve como objetivos nivelar o nivel de conhecimento dos integrantes e retirada de duvidas. diff --git a/docs/source/reunioes/atas/reuniao-06.rst b/docs/source/reunioes/atas/reuniao-06.rst index 2abe5ec..23737d4 100644 --- a/docs/source/reunioes/atas/reuniao-06.rst +++ b/docs/source/reunioes/atas/reuniao-06.rst @@ -1,9 +1,9 @@ -Reunião 04 +Reunião 06 ========== -:bdg-info:`16/11/2023` :bdg-warning:`Sprint 4` +:bdg-info:`13/11/2023` :bdg-warning:`Sprint 4` Resumo ------ -Esta reunião teve como objetivos redistribuir as partes de cada integrante e a reduçao do prazo para entrega das issues +Esta reunião teve como objetivos discutir o progresso, anunciar a saida de um integrante. diff --git a/docs/source/reunioes/atas/reuniao-07.rst b/docs/source/reunioes/atas/reuniao-07.rst new file mode 100644 index 0000000..b6a9241 --- /dev/null +++ b/docs/source/reunioes/atas/reuniao-07.rst @@ -0,0 +1,9 @@ +Reunião 07 +========== + +:bdg-info:`16/11/2023` :bdg-warning:`Sprint 4` + +Resumo +------ + +Esta reunião teve como objetivos redistribuir as partes de cada integrante e a reduçao do prazo para entrega das issues. From 4e9b6dfc5217b0eb0ffef0e8ae9ed48a9166de5a Mon Sep 17 00:00:00 2001 From: LuizaMaluf Date: Mon, 20 Nov 2023 12:31:37 -0300 Subject: [PATCH 09/28] fix(automatic-login): requested changes done --- apps/users/tests.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/apps/users/tests.py b/apps/users/tests.py index 24dd7d4..4e8d3fe 100644 --- a/apps/users/tests.py +++ b/apps/users/tests.py @@ -108,17 +108,12 @@ def test_register_view_get(self) -> None: def test_post_valid_data(self) -> None: response = self.client.post( - self.url, data=self.valid_data, folloe=True + self.url, data=self.valid_data, follow=True ) - # Verifica se a página foi redirecionada - # para a página inicial após o registro - self.assertRedirects(response, reverse("home")) - # Verifica se o usuário foi criado no banco de dados - self.assertTrue( - User.objects.filter(username=self.valid_data["username"]).exists() - ) - # Autentica manualmente o usuário + user = User.objects.get(username=self.valid_data["username"]) + + self.assertRedirects(response, reverse("home")) + self.assertIsNotNone(user) self.client.force_login(user) - # Verifica se o usuário está autenticado após o registro self.assertTrue(self.client.session["_auth_user_id"]) From 5813de6c62b073616aa144b4a7b6519a5e580789 Mon Sep 17 00:00:00 2001 From: kyomi Date: Tue, 21 Nov 2023 16:37:34 -0300 Subject: [PATCH 10/28] feat(heroku): initial Heroku configuration file --- Procfile | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Procfile diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..70859a6 --- /dev/null +++ b/Procfile @@ -0,0 +1,2 @@ +release: python manage.py migrate +web: gunicorn server.wsgi From a440737f511a1550ee9d20c387ab5c6a2e254b4a Mon Sep 17 00:00:00 2001 From: jpcfarias Date: Tue, 21 Nov 2023 16:47:03 -0300 Subject: [PATCH 11/28] docs(fix-writing): alter reuniao-5, sprint-4 and intro archives --- docs/source/reunioes/atas/reuniao-05.rst | 3 ++- docs/source/reunioes/intro.rst | 3 +++ docs/source/scrum/intro.rst | 1 + docs/source/scrum/sprints/sprint-4.rst | 4 +++- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/source/reunioes/atas/reuniao-05.rst b/docs/source/reunioes/atas/reuniao-05.rst index 1408114..04cbb3d 100644 --- a/docs/source/reunioes/atas/reuniao-05.rst +++ b/docs/source/reunioes/atas/reuniao-05.rst @@ -6,4 +6,5 @@ Reunião 04 Resumo ------ -Esta reunião teve como objetivos nivelar o nivel de conhecimento dos integrantes e retirada de duvidas. +Esta reunião teve como objetivos nivelar o nivel de conhecimento dos integrantes e retirada +de duvidas. diff --git a/docs/source/reunioes/intro.rst b/docs/source/reunioes/intro.rst index 8015d37..55d95cf 100644 --- a/docs/source/reunioes/intro.rst +++ b/docs/source/reunioes/intro.rst @@ -25,3 +25,6 @@ Atas atas/reuniao-02 atas/reuniao-03 atas/reuniao-04 + atas/reuniao-05 + atas/reuniao-06 + atas/reuniao-07 diff --git a/docs/source/scrum/intro.rst b/docs/source/scrum/intro.rst index d1065cc..3011151 100644 --- a/docs/source/scrum/intro.rst +++ b/docs/source/scrum/intro.rst @@ -23,3 +23,4 @@ Sprints sprints/sprint-1 sprints/sprint-2 sprints/sprint-3 + sprints/sprint-4 diff --git a/docs/source/scrum/sprints/sprint-4.rst b/docs/source/scrum/sprints/sprint-4.rst index 7ece615..37c6daf 100644 --- a/docs/source/scrum/sprints/sprint-4.rst +++ b/docs/source/scrum/sprints/sprint-4.rst @@ -6,7 +6,9 @@ Sprint 4 Resumo ------ -Nesta sprint, a equipe de desenvolvimento começou a trabalhar na segunda release. As principais atividades foram o início do desenvolvimento da parte de submissões e a estilização da página de login para melhor acessibilidade do usuário. +Nesta sprint, a equipe de desenvolvimento começou a trabalhar na segunda release. As +principais atividades foram o início do desenvolvimento da parte de submissões e a +estilização da página de login para melhor acessibilidade do usuário. Changelog From 805acebb34100a5c2ac65033055c2b80c8f63608 Mon Sep 17 00:00:00 2001 From: kyomi Date: Tue, 21 Nov 2023 17:05:52 -0300 Subject: [PATCH 12/28] feat(heroku): add a configuration file for review apps feat(heroku): add necessary config variables to the review apps fix(heroku): disable static collection on Heroku environment fix(heroku): install `gunicorn` tool to run the application on Heroku fix(heroku): set the correct default for `DJANGO_SETTINGS_MODULE` environment variable fix(heroku): allow any Heroku host on `ALLOWED_HOSTS` --- app.json | 17 +++++++++++++++++ poetry.lock | 22 +++++++++++++++++++++- pyproject.toml | 1 + server/settings/development.py | 1 + server/wsgi.py | 2 +- 5 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 app.json diff --git a/app.json b/app.json new file mode 100644 index 0000000..b14e765 --- /dev/null +++ b/app.json @@ -0,0 +1,17 @@ +{ + "repository": "https://github.com/unb-mds/2023-2-Squad06", + "addons": ["heroku-postgresql:mini", "papertrail:choklad"], + "buildpacks": [ + { + "url": "https://github.com/moneymeets/python-poetry-buildpack.git" + }, + { + "url": "heroku/python" + } + ], + "env": { + "PYTHON_RUNTIME_VERSION": "3.11.5", + "POETRY_VERSION": "1.6.1", + "DISABLE_COLLECTSTATIC": "1" + } +} diff --git a/poetry.lock b/poetry.lock index f4f727a..a37fc6f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -550,6 +550,26 @@ mccabe = ">=0.7.0,<0.8.0" pycodestyle = ">=2.11.0,<2.12.0" pyflakes = ">=3.1.0,<3.2.0" +[[package]] +name = "gunicorn" +version = "21.2.0" +description = "WSGI HTTP Server for UNIX" +optional = false +python-versions = ">=3.5" +files = [ + {file = "gunicorn-21.2.0-py3-none-any.whl", hash = "sha256:3213aa5e8c24949e792bcacfc176fef362e7aac80b76c56f6b5122bf350722f0"}, + {file = "gunicorn-21.2.0.tar.gz", hash = "sha256:88ec8bff1d634f98e61b9f65bc4bf3cd918a90806c6f5c48bc5603849ec81033"}, +] + +[package.dependencies] +packaging = "*" + +[package.extras] +eventlet = ["eventlet (>=0.24.1)"] +gevent = ["gevent (>=1.4.0)"] +setproctitle = ["setproctitle"] +tornado = ["tornado (>=0.2)"] + [[package]] name = "identify" version = "2.5.32" @@ -1355,4 +1375,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "c59191f6dccb24ff1dac0ad0d8c6cfd50a6271edd71da7ecb1f00f875e8b8a22" +content-hash = "bd3c564777df73446edad5c1f128a4d19007769e1497db81c89a4af8755ffdb3" diff --git a/pyproject.toml b/pyproject.toml index cd9663d..340f6e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,6 +15,7 @@ django-guardian = "^2.4.0" django-bootstrap-v5 = "^1.0.11" django-crispy-forms = "^2.1" crispy-bootstrap5 = "^2023.10" +gunicorn = "^21.2.0" [tool.poetry.group.dev.dependencies] pre-commit = "^3.5.0" diff --git a/server/settings/development.py b/server/settings/development.py index d0cc532..8e568b0 100644 --- a/server/settings/development.py +++ b/server/settings/development.py @@ -4,6 +4,7 @@ "localhost", "0.0.0.0", "127.0.0.1", + ".herokuapp.com", ] # In development, we don't need a secure password hasher. We can use diff --git a/server/wsgi.py b/server/wsgi.py index aa9ff36..e670c6d 100644 --- a/server/wsgi.py +++ b/server/wsgi.py @@ -2,6 +2,6 @@ from django.core.wsgi import get_wsgi_application -environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings") +environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings.development") application = get_wsgi_application() From c7a3997a394039c86298bea9a5fe82d078ab68d0 Mon Sep 17 00:00:00 2001 From: kyomi Date: Tue, 21 Nov 2023 19:59:31 -0300 Subject: [PATCH 13/28] fix(heroku): serve static files correctly on Heroku --- app.json | 3 +-- poetry.lock | 16 +++++++++++++++- pyproject.toml | 1 + server/settings/base.py | 9 +++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app.json b/app.json index b14e765..7e89f83 100644 --- a/app.json +++ b/app.json @@ -11,7 +11,6 @@ ], "env": { "PYTHON_RUNTIME_VERSION": "3.11.5", - "POETRY_VERSION": "1.6.1", - "DISABLE_COLLECTSTATIC": "1" + "POETRY_VERSION": "1.6.1" } } diff --git a/poetry.lock b/poetry.lock index a37fc6f..5331828 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1357,6 +1357,20 @@ files = [ {file = "wcwidth-0.2.10.tar.gz", hash = "sha256:390c7454101092a6a5e43baad8f83de615463af459201709556b6e4b1c861f97"}, ] +[[package]] +name = "whitenoise" +version = "6.6.0" +description = "Radically simplified static file serving for WSGI applications" +optional = false +python-versions = ">=3.8" +files = [ + {file = "whitenoise-6.6.0-py3-none-any.whl", hash = "sha256:b1f9db9bf67dc183484d760b99f4080185633136a273a03f6436034a41064146"}, + {file = "whitenoise-6.6.0.tar.gz", hash = "sha256:8998f7370973447fac1e8ef6e8ded2c5209a7b1f67c1012866dbcd09681c3251"}, +] + +[package.extras] +brotli = ["Brotli"] + [[package]] name = "zipp" version = "3.17.0" @@ -1375,4 +1389,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "bd3c564777df73446edad5c1f128a4d19007769e1497db81c89a4af8755ffdb3" +content-hash = "ee0f61a49b3dc68037a41f78dc055adedc1f97f4b8e1afd1ace1924a17f209a1" diff --git a/pyproject.toml b/pyproject.toml index 340f6e2..21942bb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,7 @@ django-bootstrap-v5 = "^1.0.11" django-crispy-forms = "^2.1" crispy-bootstrap5 = "^2023.10" gunicorn = "^21.2.0" +whitenoise = "^6.6.0" [tool.poetry.group.dev.dependencies] pre-commit = "^3.5.0" diff --git a/server/settings/base.py b/server/settings/base.py index 8f47102..179eda8 100644 --- a/server/settings/base.py +++ b/server/settings/base.py @@ -30,6 +30,7 @@ MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", + "whitenoise.middleware.WhiteNoiseMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", @@ -130,6 +131,14 @@ STATIC_URL = "/static/" +STATIC_ROOT = BASE_DIR / "static" + +STORAGES = { + "staticfiles": { + "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", + }, +} + #################### # Authentication # #################### From 35f9949c1cfd4b292f53ed18552d7a5d5cc8eedc Mon Sep 17 00:00:00 2001 From: kyomi Date: Tue, 21 Nov 2023 23:14:23 -0300 Subject: [PATCH 14/28] feat: allow our custom domain host --- server/settings/development.py | 1 + 1 file changed, 1 insertion(+) diff --git a/server/settings/development.py b/server/settings/development.py index 8e568b0..91061cf 100644 --- a/server/settings/development.py +++ b/server/settings/development.py @@ -5,6 +5,7 @@ "0.0.0.0", "127.0.0.1", ".herokuapp.com", + "develop.squad06.com", ] # In development, we don't need a secure password hasher. We can use From eacca7bf98055a7cc32b185cf4482999ca3e72d6 Mon Sep 17 00:00:00 2001 From: MMcLovin Date: Fri, 17 Nov 2023 14:19:12 -0300 Subject: [PATCH 15/28] feat: moves DOCTYPE to page's first line --- templates/base.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/base.html b/templates/base.html index acd146e..ed8f6d2 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,3 +1,5 @@ + + {% load static i18n %} {% load bootstrap5 %} @@ -11,7 +13,6 @@ {% get_current_language as LANGUAGE_CODE %} - From 054f37f27a6891b6c66992477c30c93b40920873 Mon Sep 17 00:00:00 2001 From: MMcLovin <122990047+MMcLovin@users.noreply.github.com> Date: Fri, 17 Nov 2023 14:23:16 -0300 Subject: [PATCH 16/28] feat: adds katex typesetting library Katex is used for rendering LATEX expressions in HTML --- templates/tasks/detail.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/tasks/detail.html b/templates/tasks/detail.html index 9ab07fc..7cdff8e 100644 --- a/templates/tasks/detail.html +++ b/templates/tasks/detail.html @@ -3,6 +3,9 @@ {% block title %}{{ task.title }}{% endblock title %} {% block content %} + + + -
{% block content %}{% endblock content %}
-
diff --git a/templates/tasks/detail.html b/templates/tasks/detail.html index 7cdff8e..9ab07fc 100644 --- a/templates/tasks/detail.html +++ b/templates/tasks/detail.html @@ -3,9 +3,6 @@ {% block title %}{{ task.title }}{% endblock title %} {% block content %} - - -

From 726f42116240ed223a314ca519da863fabdf7cef Mon Sep 17 00:00:00 2001 From: LuizaMaluf Date: Fri, 17 Nov 2023 19:33:32 -0300 Subject: [PATCH 18/28] fix(automatic-login): authentication done --- apps/users/views.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/users/views.py b/apps/users/views.py index 012556e..5695a9a 100644 --- a/apps/users/views.py +++ b/apps/users/views.py @@ -1,3 +1,4 @@ +from django.contrib.auth import login from django.http import HttpRequest, HttpResponse from django.shortcuts import redirect, render from django.views import View @@ -15,7 +16,14 @@ def get(self, request: HttpRequest) -> HttpResponse: def post(self, request: HttpRequest) -> HttpResponse: form = CreateUserForm(self.request.POST) if form.is_valid(): - form.save() - return redirect("login") + user = form.save() + + login( + request, + user, + backend="django.contrib.auth.backends.ModelBackend", + ) + + return redirect("home") return render(request, self.template_name, {"form": form}) From 3bdde58cf028606cea4685d89071ff7b816c9008 Mon Sep 17 00:00:00 2001 From: kyomi Date: Fri, 17 Nov 2023 22:09:16 -0300 Subject: [PATCH 19/28] docs(apps/users): document the login authentication backend --- apps/users/views.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/users/views.py b/apps/users/views.py index 5695a9a..adabd04 100644 --- a/apps/users/views.py +++ b/apps/users/views.py @@ -18,12 +18,10 @@ def post(self, request: HttpRequest) -> HttpResponse: if form.is_valid(): user = form.save() - login( - request, - user, - backend="django.contrib.auth.backends.ModelBackend", - ) - + # Since we have multiple authentication backends, we need to + # specify which one we want to use. In this case, we want to + # use the :class:`ModelBackend`, which is the default one. + login(request, user, "django.contrib.auth.backends.ModelBackend") return redirect("home") return render(request, self.template_name, {"form": form}) From 5eebb10668094fb149ef2d9e1a6a6adb5ebac99d Mon Sep 17 00:00:00 2001 From: LuizaMaluf Date: Sun, 19 Nov 2023 11:40:48 -0300 Subject: [PATCH 20/28] fix(automatic-login): tests --- .pre-commit-config.yaml | 2 +- apps/users/tests.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c443555..e216ee5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,7 +33,7 @@ repos: hooks: - id: flake8 - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.5.1 + rev: v1.6.1 hooks: - id: mypy additional_dependencies: diff --git a/apps/users/tests.py b/apps/users/tests.py index b509386..24dd7d4 100644 --- a/apps/users/tests.py +++ b/apps/users/tests.py @@ -1,7 +1,9 @@ from django.test import TestCase +from django.urls import reverse from django.utils.translation import gettext as _ from apps.users.admin import UserAdmin +from apps.users.forms import CreateUserForm from apps.users.models import User @@ -86,3 +88,37 @@ def test_add_fieldsets(self) -> None: ) self.assertEqual(UserAdmin.add_fieldsets, expected_add_fieldsets) + + +class RegisterViewTest(TestCase): + def setUp(self) -> None: + self.url = reverse("users:register") + self.valid_data = { + "username": "testuser", + "email": "test@example.com", + "password1": "TestPassword123", + "password2": "TestPassword123", + } + + def test_register_view_get(self) -> None: + response = self.client.get(self.url) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, "registration/register.html") + self.assertIsInstance(response.context["form"], CreateUserForm) + + def test_post_valid_data(self) -> None: + response = self.client.post( + self.url, data=self.valid_data, folloe=True + ) + # Verifica se a página foi redirecionada + # para a página inicial após o registro + self.assertRedirects(response, reverse("home")) + # Verifica se o usuário foi criado no banco de dados + self.assertTrue( + User.objects.filter(username=self.valid_data["username"]).exists() + ) + # Autentica manualmente o usuário + user = User.objects.get(username=self.valid_data["username"]) + self.client.force_login(user) + # Verifica se o usuário está autenticado após o registro + self.assertTrue(self.client.session["_auth_user_id"]) From 991da916b22f9c11435ad8dd6cabc975022dc10e Mon Sep 17 00:00:00 2001 From: LuizaMaluf Date: Mon, 20 Nov 2023 12:31:37 -0300 Subject: [PATCH 21/28] fix(automatic-login): requested changes done --- apps/users/tests.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/apps/users/tests.py b/apps/users/tests.py index 24dd7d4..4e8d3fe 100644 --- a/apps/users/tests.py +++ b/apps/users/tests.py @@ -108,17 +108,12 @@ def test_register_view_get(self) -> None: def test_post_valid_data(self) -> None: response = self.client.post( - self.url, data=self.valid_data, folloe=True + self.url, data=self.valid_data, follow=True ) - # Verifica se a página foi redirecionada - # para a página inicial após o registro - self.assertRedirects(response, reverse("home")) - # Verifica se o usuário foi criado no banco de dados - self.assertTrue( - User.objects.filter(username=self.valid_data["username"]).exists() - ) - # Autentica manualmente o usuário + user = User.objects.get(username=self.valid_data["username"]) + + self.assertRedirects(response, reverse("home")) + self.assertIsNotNone(user) self.client.force_login(user) - # Verifica se o usuário está autenticado após o registro self.assertTrue(self.client.session["_auth_user_id"]) From aa26baa195a7806e78be9e61154dd382e590cb75 Mon Sep 17 00:00:00 2001 From: kyomi Date: Tue, 21 Nov 2023 16:37:34 -0300 Subject: [PATCH 22/28] feat(heroku): initial Heroku configuration file --- Procfile | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Procfile diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..70859a6 --- /dev/null +++ b/Procfile @@ -0,0 +1,2 @@ +release: python manage.py migrate +web: gunicorn server.wsgi From e023570ec825ce208e7f954c1b784b75ded844b6 Mon Sep 17 00:00:00 2001 From: kyomi Date: Tue, 21 Nov 2023 17:05:52 -0300 Subject: [PATCH 23/28] feat(heroku): add a configuration file for review apps feat(heroku): add necessary config variables to the review apps fix(heroku): disable static collection on Heroku environment fix(heroku): install `gunicorn` tool to run the application on Heroku fix(heroku): set the correct default for `DJANGO_SETTINGS_MODULE` environment variable fix(heroku): allow any Heroku host on `ALLOWED_HOSTS` --- app.json | 17 +++++++++++++++++ poetry.lock | 22 +++++++++++++++++++++- pyproject.toml | 1 + server/settings/development.py | 1 + server/wsgi.py | 2 +- 5 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 app.json diff --git a/app.json b/app.json new file mode 100644 index 0000000..b14e765 --- /dev/null +++ b/app.json @@ -0,0 +1,17 @@ +{ + "repository": "https://github.com/unb-mds/2023-2-Squad06", + "addons": ["heroku-postgresql:mini", "papertrail:choklad"], + "buildpacks": [ + { + "url": "https://github.com/moneymeets/python-poetry-buildpack.git" + }, + { + "url": "heroku/python" + } + ], + "env": { + "PYTHON_RUNTIME_VERSION": "3.11.5", + "POETRY_VERSION": "1.6.1", + "DISABLE_COLLECTSTATIC": "1" + } +} diff --git a/poetry.lock b/poetry.lock index f4f727a..a37fc6f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -550,6 +550,26 @@ mccabe = ">=0.7.0,<0.8.0" pycodestyle = ">=2.11.0,<2.12.0" pyflakes = ">=3.1.0,<3.2.0" +[[package]] +name = "gunicorn" +version = "21.2.0" +description = "WSGI HTTP Server for UNIX" +optional = false +python-versions = ">=3.5" +files = [ + {file = "gunicorn-21.2.0-py3-none-any.whl", hash = "sha256:3213aa5e8c24949e792bcacfc176fef362e7aac80b76c56f6b5122bf350722f0"}, + {file = "gunicorn-21.2.0.tar.gz", hash = "sha256:88ec8bff1d634f98e61b9f65bc4bf3cd918a90806c6f5c48bc5603849ec81033"}, +] + +[package.dependencies] +packaging = "*" + +[package.extras] +eventlet = ["eventlet (>=0.24.1)"] +gevent = ["gevent (>=1.4.0)"] +setproctitle = ["setproctitle"] +tornado = ["tornado (>=0.2)"] + [[package]] name = "identify" version = "2.5.32" @@ -1355,4 +1375,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "c59191f6dccb24ff1dac0ad0d8c6cfd50a6271edd71da7ecb1f00f875e8b8a22" +content-hash = "bd3c564777df73446edad5c1f128a4d19007769e1497db81c89a4af8755ffdb3" diff --git a/pyproject.toml b/pyproject.toml index cd9663d..340f6e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,6 +15,7 @@ django-guardian = "^2.4.0" django-bootstrap-v5 = "^1.0.11" django-crispy-forms = "^2.1" crispy-bootstrap5 = "^2023.10" +gunicorn = "^21.2.0" [tool.poetry.group.dev.dependencies] pre-commit = "^3.5.0" diff --git a/server/settings/development.py b/server/settings/development.py index d0cc532..8e568b0 100644 --- a/server/settings/development.py +++ b/server/settings/development.py @@ -4,6 +4,7 @@ "localhost", "0.0.0.0", "127.0.0.1", + ".herokuapp.com", ] # In development, we don't need a secure password hasher. We can use diff --git a/server/wsgi.py b/server/wsgi.py index aa9ff36..e670c6d 100644 --- a/server/wsgi.py +++ b/server/wsgi.py @@ -2,6 +2,6 @@ from django.core.wsgi import get_wsgi_application -environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings") +environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings.development") application = get_wsgi_application() From 8092dca8e7209eb135c69fa0e60afab9c49b4a4d Mon Sep 17 00:00:00 2001 From: kyomi Date: Tue, 21 Nov 2023 19:59:31 -0300 Subject: [PATCH 24/28] fix(heroku): serve static files correctly on Heroku --- app.json | 3 +-- poetry.lock | 16 +++++++++++++++- pyproject.toml | 1 + server/settings/base.py | 9 +++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app.json b/app.json index b14e765..7e89f83 100644 --- a/app.json +++ b/app.json @@ -11,7 +11,6 @@ ], "env": { "PYTHON_RUNTIME_VERSION": "3.11.5", - "POETRY_VERSION": "1.6.1", - "DISABLE_COLLECTSTATIC": "1" + "POETRY_VERSION": "1.6.1" } } diff --git a/poetry.lock b/poetry.lock index a37fc6f..5331828 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1357,6 +1357,20 @@ files = [ {file = "wcwidth-0.2.10.tar.gz", hash = "sha256:390c7454101092a6a5e43baad8f83de615463af459201709556b6e4b1c861f97"}, ] +[[package]] +name = "whitenoise" +version = "6.6.0" +description = "Radically simplified static file serving for WSGI applications" +optional = false +python-versions = ">=3.8" +files = [ + {file = "whitenoise-6.6.0-py3-none-any.whl", hash = "sha256:b1f9db9bf67dc183484d760b99f4080185633136a273a03f6436034a41064146"}, + {file = "whitenoise-6.6.0.tar.gz", hash = "sha256:8998f7370973447fac1e8ef6e8ded2c5209a7b1f67c1012866dbcd09681c3251"}, +] + +[package.extras] +brotli = ["Brotli"] + [[package]] name = "zipp" version = "3.17.0" @@ -1375,4 +1389,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "bd3c564777df73446edad5c1f128a4d19007769e1497db81c89a4af8755ffdb3" +content-hash = "ee0f61a49b3dc68037a41f78dc055adedc1f97f4b8e1afd1ace1924a17f209a1" diff --git a/pyproject.toml b/pyproject.toml index 340f6e2..21942bb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,7 @@ django-bootstrap-v5 = "^1.0.11" django-crispy-forms = "^2.1" crispy-bootstrap5 = "^2023.10" gunicorn = "^21.2.0" +whitenoise = "^6.6.0" [tool.poetry.group.dev.dependencies] pre-commit = "^3.5.0" diff --git a/server/settings/base.py b/server/settings/base.py index 8f47102..179eda8 100644 --- a/server/settings/base.py +++ b/server/settings/base.py @@ -30,6 +30,7 @@ MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", + "whitenoise.middleware.WhiteNoiseMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", @@ -130,6 +131,14 @@ STATIC_URL = "/static/" +STATIC_ROOT = BASE_DIR / "static" + +STORAGES = { + "staticfiles": { + "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", + }, +} + #################### # Authentication # #################### From dbbd3ad6a700e64c429ed36fb067b53cf34c6ba0 Mon Sep 17 00:00:00 2001 From: kyomi Date: Tue, 21 Nov 2023 23:14:23 -0300 Subject: [PATCH 25/28] feat: allow our custom domain host --- server/settings/development.py | 1 + 1 file changed, 1 insertion(+) diff --git a/server/settings/development.py b/server/settings/development.py index 8e568b0..91061cf 100644 --- a/server/settings/development.py +++ b/server/settings/development.py @@ -5,6 +5,7 @@ "0.0.0.0", "127.0.0.1", ".herokuapp.com", + "develop.squad06.com", ] # In development, we don't need a secure password hasher. We can use From 129e79f27ca3b39578ab55d3c058e0f236a8a915 Mon Sep 17 00:00:00 2001 From: kyomi Date: Tue, 21 Nov 2023 23:43:30 -0300 Subject: [PATCH 26/28] docs(reunioes/atas): fix typo and reduce line length to 80 characters --- docs/source/reunioes/atas/reuniao-07.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/reunioes/atas/reuniao-07.rst b/docs/source/reunioes/atas/reuniao-07.rst index b6a9241..8aabad8 100644 --- a/docs/source/reunioes/atas/reuniao-07.rst +++ b/docs/source/reunioes/atas/reuniao-07.rst @@ -6,4 +6,5 @@ Reunião 07 Resumo ------ -Esta reunião teve como objetivos redistribuir as partes de cada integrante e a reduçao do prazo para entrega das issues. +Esta reunião teve como objetivos redistribuir as partes de cada integrante e a +redução do prazo para entrega das issues. From 0807304e0b62e4385808ed9ed5a842c88285cb30 Mon Sep 17 00:00:00 2001 From: kyomi Date: Tue, 21 Nov 2023 23:44:29 -0300 Subject: [PATCH 27/28] docs(reunioes/atas): remove useless space between the badges --- docs/source/reunioes/atas/reuniao-04.rst | 2 +- docs/source/reunioes/atas/reuniao-05.rst | 2 +- docs/source/reunioes/atas/reuniao-06.rst | 2 +- docs/source/reunioes/atas/reuniao-07.rst | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/source/reunioes/atas/reuniao-04.rst b/docs/source/reunioes/atas/reuniao-04.rst index d790cff..d2d06f4 100644 --- a/docs/source/reunioes/atas/reuniao-04.rst +++ b/docs/source/reunioes/atas/reuniao-04.rst @@ -1,7 +1,7 @@ Reunião 04 ========== -:bdg-info:`18/10/2023` :bdg-warning:`Sprint 2` +:bdg-info:`18/10/2023` :bdg-warning:`Sprint 2` Resumo ------ diff --git a/docs/source/reunioes/atas/reuniao-05.rst b/docs/source/reunioes/atas/reuniao-05.rst index 04cbb3d..c4252d3 100644 --- a/docs/source/reunioes/atas/reuniao-05.rst +++ b/docs/source/reunioes/atas/reuniao-05.rst @@ -1,7 +1,7 @@ Reunião 04 ========== -:bdg-info:`25/10/2023` :bdg-warning:`Sprint 3` +:bdg-info:`25/10/2023` :bdg-warning:`Sprint 3` Resumo ------ diff --git a/docs/source/reunioes/atas/reuniao-06.rst b/docs/source/reunioes/atas/reuniao-06.rst index 23737d4..22d7624 100644 --- a/docs/source/reunioes/atas/reuniao-06.rst +++ b/docs/source/reunioes/atas/reuniao-06.rst @@ -1,7 +1,7 @@ Reunião 06 ========== -:bdg-info:`13/11/2023` :bdg-warning:`Sprint 4` +:bdg-info:`13/11/2023` :bdg-warning:`Sprint 4` Resumo ------ diff --git a/docs/source/reunioes/atas/reuniao-07.rst b/docs/source/reunioes/atas/reuniao-07.rst index 8aabad8..b1c5615 100644 --- a/docs/source/reunioes/atas/reuniao-07.rst +++ b/docs/source/reunioes/atas/reuniao-07.rst @@ -1,7 +1,7 @@ Reunião 07 ========== -:bdg-info:`16/11/2023` :bdg-warning:`Sprint 4` +:bdg-info:`16/11/2023` :bdg-warning:`Sprint 4` Resumo ------ From c4c9ed5e3014d2c237e704cc97e14ef1ad7f2aef Mon Sep 17 00:00:00 2001 From: kyomi Date: Tue, 21 Nov 2023 23:51:22 -0300 Subject: [PATCH 28/28] docs(reunioes/atas): set the line length do 80 characters --- docs/source/reunioes/atas/reuniao-06.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/reunioes/atas/reuniao-06.rst b/docs/source/reunioes/atas/reuniao-06.rst index 22d7624..134b718 100644 --- a/docs/source/reunioes/atas/reuniao-06.rst +++ b/docs/source/reunioes/atas/reuniao-06.rst @@ -6,4 +6,5 @@ Reunião 06 Resumo ------ -Esta reunião teve como objetivos discutir o progresso, anunciar a saida de um integrante. +Esta reunião teve como objetivos discutir o progresso, anunciar a saida de um +integrante.