Skip to content

Commit

Permalink
Merge pull request #186 from ISPP-G5/develop
Browse files Browse the repository at this point in the history
S3
  • Loading branch information
pabpercab1 authored Apr 22, 2024
2 parents 84faabe + 9116b89 commit 8d68828
Show file tree
Hide file tree
Showing 63 changed files with 6,678 additions and 478 deletions.
32 changes: 32 additions & 0 deletions .gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# .gcloudignore

.gcloudignore

# Ignore local .env file
.env

# If you would like to upload your .git directory, .gitignore file, or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore
.github
info.yml
README.md

# Python pycache:
__pycache__/

# Ignore collected static and media files
mediafiles/
staticfiles/

# Ignore the local DB
db.sqlite3

# Ignored by the build system
/setup.cfg
venv/

# Ignore IDE files
.vscode/
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,8 @@ nexong/migrations/*
nexong/migrations

# Server files
files/
files/
staticfiles/

# GCP credentials
gcpCredentials.json
15 changes: 15 additions & 0 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
runtime: python311
env: standard
entrypoint: gunicorn -b :$PORT src.wsgi:application

handlers:
- url: /static
static_dir: staticfiles/
- url: /media
static_dir: mediafiles/
- url: /.*
script: auto
secure: always

runtime_config:
python_version: 3
2 changes: 2 additions & 0 deletions nexong/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
admin.site.register(Partner)
admin.site.register(Volunteer)
admin.site.register(StudentEvaluation)
admin.site.register(Schedule)
admin.site.register(Terms)
94 changes: 69 additions & 25 deletions nexong/api/Authentication/authSerializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from rest_framework.serializers import ModelSerializer
from rest_framework.serializers import Serializer
from djoser.serializers import UserCreateSerializer
from nexong.api.helpers.serializerValidators import has_numbers


class LogoutAndBlacklistSerializer(Serializer):
Expand Down Expand Up @@ -33,21 +34,57 @@ def validate_id_number(self, data):
class CreateUserSerializer(UserCreateSerializer):
class Meta(UserCreateSerializer.Meta):
model = User
fields = ["email", "first_name", "last_name", "id_number", "phone", "password"]
fields = [
"email",
"first_name",
"last_name",
"id_number",
"phone",
"password",
"role",
"family",
"partner",
"volunteer",
"education_center",
"educator",
"is_agreed",
]

def validate_first_name(self, data):
if not data:
raise serializers.ValidationError("This field may not be blank.")
if has_numbers(data):
raise serializers.ValidationError("First name cannot contain numbers")
return data

def validate_last_name(self, data):
if not data:
raise serializers.ValidationError("This field may not be blank.")
if has_numbers(data):
raise serializers.ValidationError("Last name cannot contain numbers")
return data

def validate_id_number(self, data):
if not data:
raise serializers.ValidationError("This field may not be blank.")
else:
pattern = r"^\d{8}[A-Z]$"
if not re.match(pattern, data):
raise serializers.ValidationError(
"The id_number does not match the expected pattern."
)
return data

def validate_is_agreed(self, data):
is_agreed = data
if is_agreed == False:
raise serializers.ValidationError("User must accept terms and conditions.")
return data

def validate_role(self, data):
role = data
if role == "ADMIN":
raise serializers.ValidationError("You cannot create admin users")
return data


Expand All @@ -66,30 +103,37 @@ class Meta:

def validate(self, data):
validation_error = {}
if data["role"] == "EDUCADOR" and data["educator"] is None:
validation_error["educator"] = 'Given role "EDUCADOR", this cannot be null.'
elif data["role"] == "VOLUNTARIO" and data["volunteer"] is None:
validation_error[
"volunteer"
] = 'Given role "VOLUNTARIO", this cannot be null.'
elif data["role"] == "FAMILIA" and data["family"] is None:
validation_error["family"] = 'Given role "FAMILIA", this cannot be null.'
elif data["role"] == "SOCIO" and data["partner"] is None:
validation_error["partner"] = 'Given role "SOCIO", this cannot be null.'
elif data["role"] == "VOLUNTARIO_SOCIO" and (
data["volunteer"] is None or data["partner"] is None
):
validation_error[
"volunteer"
] = 'Given role "VOLUNTARIO", this cannot be null.'
validation_error["partner"] = 'Given role "SOCIO", this cannot be null.'

id_number = data["id_number"]
pattern = r"^\d{8}[A-Z]$"
if not re.match(pattern, id_number):
validation_error[
"id_number"
] = "The id_number does not match the expected pattern."
if "role" in data:
if data["role"] == "EDUCADOR" and data["educator"] is None:
validation_error[
"educator"
] = 'Given role "EDUCADOR", this cannot be null.'
elif data["role"] == "ADMIN":
validation_error["role"] = "You cannot create an ADMIN role"
elif data["role"] == "VOLUNTARIO" and data["volunteer"] is None:
validation_error[
"volunteer"
] = 'Given role "VOLUNTARIO", this cannot be null.'
elif data["role"] == "FAMILIA" and data["family"] is None:
validation_error[
"family"
] = 'Given role "FAMILIA", this cannot be null.'
elif data["role"] == "SOCIO" and data["partner"] is None:
validation_error["partner"] = 'Given role "SOCIO", this cannot be null.'
elif data["role"] == "VOLUNTARIO_SOCIO" and (
data["volunteer"] is None or data["partner"] is None
):
validation_error[
"volunteer"
] = 'Given role "VOLUNTARIO", this cannot be null.'
validation_error["partner"] = 'Given role "SOCIO", this cannot be null.'
if "id_number" in data:
id_number = data["id_number"]
pattern = r"^\d{8}[A-Z]$"
if not re.match(pattern, id_number):
validation_error[
"id_number"
] = "The id_number does not match the expected pattern."
if validation_error:
raise serializers.ValidationError(validation_error)

Expand Down
Loading

0 comments on commit 8d68828

Please sign in to comment.