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

Ready: Cors #451

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
582dfde
Enable CORS for React application
ethanstrominger Oct 16, 2024
dd3fc1c
Partially working, some code commented out
ethanstrominger Nov 26, 2024
4627e3f
Handle jwt decode error,
ethanstrominger Nov 26, 2024
2553707
WIP
ethanstrominger Nov 28, 2024
0c52805
Small changes
ethanstrominger Nov 30, 2024
e94bfd6
Resolve views.py conflict
ethanstrominger Nov 30, 2024
83082c8
Merge branch 'main' of https://github.com/hackforla/peopledepot into …
ethanstrominger Nov 30, 2024
884e8d4
Change post to patch
ethanstrominger Nov 30, 2024
319ae56
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 30, 2024
72f72dc
Changes to support React
ethanstrominger Nov 30, 2024
e1de3dc
Changes for CORS so REACT works
ethanstrominger Nov 30, 2024
3e96aaf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 30, 2024
1c31653
Add blank line
ethanstrominger Nov 30, 2024
dd4036b
Merge branch 'cors' of https://github.com/ethanstrominger/peopledepot…
ethanstrominger Nov 30, 2024
6b233c9
Revert changes to files related to /login local
ethanstrominger Dec 1, 2024
698a3eb
Merge branch 'cors' of https://github.com/ethanstrominger/peopledepot…
ethanstrominger Dec 1, 2024
dc5b878
Remove /login API implementation
ethanstrominger Dec 1, 2024
dddcb7c
Restore jwt.py
ethanstrominger Dec 1, 2024
ace3579
Restore update-table.md
ethanstrominger Dec 1, 2024
368e92a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 1, 2024
6d69f40
Restore jwt.py
ethanstrominger Dec 1, 2024
f6e880f
Merge branch 'cors' of https://github.com/ethanstrominger/peopledepot…
ethanstrominger Dec 1, 2024
ac7bb08
Remove duplicate env variable in .env.docker-example
ethanstrominger Dec 1, 2024
9cc11eb
Restore docker-compose.yml
ethanstrominger Dec 1, 2024
ddfe984
Remove unused import
ethanstrominger Dec 1, 2024
ed177de
pre-commit and update-table.md
ethanstrominger Dec 1, 2024
1909194
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 1, 2024
8e1f7db
Try to fix update-table.md hanging space
ethanstrominger Dec 1, 2024
c18fe5d
Merge branch 'cors' of https://github.com/ethanstrominger/peopledepot…
ethanstrominger Dec 1, 2024
8d9bd82
Squashed commit of the following:
ethanstrominger Dec 19, 2024
8a73893
Merge branch 'cors' of https://github.com/ethanstrominger/peopledepot…
ethanstrominger Dec 19, 2024
2924fb9
Squashed commit of the following:
ethanstrominger Dec 19, 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
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/update-table.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: Update Table
about: Describe this issue template's purpose here.
about: Describe the purpose of the template here.
title: 'Update Table: [TABLE NAME]'
labels: 'feature: update table, good first issue, milestone: missing, role: back end,
size: 0.25pt, stakeholder: missing'
Expand All @@ -25,7 +25,7 @@ Current name in code | Updated Name | Updated Type (may already be this type)

- [ ] Add the following items in the code
Name | Type
-- | --
-- | --
[Replace with ADD TABLE]
- [ ] Write a test for the new relationships this model will have with other models (e.g., creating a user and assigning them a set of permissions on a project) if any.
- [ ] Update API end point
Expand All @@ -41,7 +41,7 @@ Name | Type
- 1.01.01 [/app/core/models.py](https://github.com/hackforla/peopledepot/blob/main/app/core/models.py)
- 1.01.02 [/app/core/admin.py](https://github.com/hackforla/peopledepot/blob/main/app/core/admin.py)
- 1.01.03 [/app/core/api/serializers.py](https://github.com/hackforla/peopledepot/blob/main/app/core/api/serializers.py)
- 1.01.04
- 1.01.04
- 1.02 [People Depot Resources wiki page](https://github.com/hackforla/peopledepot/wiki/Resources-and-Links) for links
- ERD
- Table and Field Definitions
Expand Down
20 changes: 2 additions & 18 deletions app/.env.docker-example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ DJANGO_SUPERUSER_USERNAME=admin1111
[email protected]
DJANGO_SUPERUSER_PASSWORD=admin

CORS_ALLOWED_ORIGINS="http://localhost:3000 https://your-production-server.com"

# postgres settings for docker
SQL_ENGINE=django.db.backends.postgresql
SQL_DATABASE=people_depot_dev
Expand All @@ -15,24 +17,6 @@ SQL_HOST=db
SQL_PORT=5432
DATABASE=postgres

# postgres settings for local development
# SQL_ENGINE=django.db.backends.postgresql
# SQL_DATABASE=postgres
# SQL_USER=
# SQL_PASSWORD=
# SQL_HOST=localhost
# SQL_PORT=5432
# DATABASE=postgres

# sqlite settings for local development
# SQL_ENGINE=
# SQL_DATABASE=
# SQL_USER=
# SQL_PASSWORD=
# SQL_HOST=
# SQL_PORT=
# DATABASE=

COGNITO_DOMAIN=peopledepot
COGNITO_AWS_REGION=us-west-2
COGNITO_USER_POOL=us-west-2_Fn4rkZpuB
Expand Down
2 changes: 1 addition & 1 deletion app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN \
--mount=type=cache,target=/var/cache/apk \
--mount=type=cache,target=/etc/apk/cache \
apk add \
'graphviz=~9.0'
'graphviz=~12.2'

# install font for graphviz
COPY Roboto-Regular.ttf /root/.fonts/
Expand Down
17 changes: 17 additions & 0 deletions app/core/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from rest_framework.mixins import RetrieveModelMixin
from rest_framework.permissions import IsAuthenticated
from rest_framework.permissions import IsAuthenticatedOrReadOnly
from rest_framework.response import Response

from ..models import Affiliate
from ..models import Affiliation
Expand Down Expand Up @@ -67,6 +68,22 @@ def get(self, request, *args, **kwargs):
"""
return self.retrieve(request, *args, **kwargs)

def patch(self, request, *args, **kwargs):
"""
Update the profile of the current logged-in user.
"""
user = self.get_object() # Get the logged-in user
serializer = self.serializer_class(user, data=request.data, partial=True)

if serializer.is_valid():
# Save the updated user data
serializer.save()
return Response({"data": serializer.data}) # Return the updated user data

return Response(
serializer.errors, status=400
) # Return validation errors if invalid data


@extend_schema_view(
list=extend_schema(
Expand Down
20 changes: 18 additions & 2 deletions app/peopledepot/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
# Application definition

INSTALLED_APPS = [
"corsheaders",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
Expand All @@ -70,6 +71,7 @@
# 3rd party
"django_extensions",
"rest_framework",
"rest_framework.authtoken",
"drf_spectacular",
"phonenumber_field",
"timezone_field",
Expand All @@ -79,7 +81,21 @@
"data",
]

# Allow specific origins (like your React dev and production URLs)
CORS_ALLOWED_ORIGINS = os.getenv("CORS_ALLOWED_ORIGINS").split(" ")

# Optional: Allow credentials (for cookies or tokens)
CORS_ALLOW_CREDENTIALS = True

# Optional: Control which headers are allowed
CORS_ALLOW_HEADERS = [
"Authorization",
"Content-Type",
]


MIDDLEWARE = [
"corsheaders.middleware.CorsMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
Expand Down Expand Up @@ -183,8 +199,8 @@
}

JWT_AUTH = {
"JWT_PAYLOAD_GET_USERNAME_HANDLER": "core.utils.jwt.get_username_from_payload_handler",
"JWT_DECODE_HANDLER": "core.utils.jwt.cognito_jwt_decode_handler",
"JWT_PAYLOAD_GET_USERNAME_HANDLER": "core.utils.jwt_handler.get_username_from_payload_handler",
"JWT_DECODE_HANDLER": "core.utils.jwt_handler.cognito_jwt_decode_handler",
"JWT_PUBLIC_KEY": rsa_keys,
"JWT_ALGORITHM": "RS256",
"JWT_AUDIENCE": COGNITO_AUDIENCE,
Expand Down
1 change: 1 addition & 0 deletions app/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ django==4.2.11
# djangorestframework
# drf-jwt
# drf-spectacular
django-cors-headers==4.5.0
django-extensions==3.2.3
django-linear-migrations==2.12.0
django-phonenumber-field==7.3.0
Expand Down