Skip to content

Huh #1668

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

Closed
wants to merge 15 commits into from
Closed

Huh #1668

Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 15 additions & 11 deletions app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class Meta(BaseSchema.Meta):
)

@validates("permissions")
def validate_permissions(self, value):
def validate_permissions(self, value, **kwargs):
permissions = [v.permission for v in value]
for p in permissions:
if p not in {e for e in ServicePermissionType}:
Expand Down Expand Up @@ -451,11 +451,11 @@ class Meta(BaseSchema.Meta):


class JobSchema(BaseSchema):
created_by_user = fields.Nested(
UserSchema,
created_by_user = ma.Nested(
"UserSchema",
attribute="created_by",
data_key="created_by",
only=["id", "name"],
only=("id", "name"),
dump_only=True,
)
created_by = field_for(models.Job, "created_by", required=True, load_only=True)
Expand All @@ -467,8 +467,8 @@ class JobSchema(BaseSchema):
job_status = auto_field()

scheduled_for = FlexibleDateTime()
service_name = fields.Nested(
ServiceSchema,
service_name = ma.Nested(
"ServiceSchema",
attribute="service",
data_key="service_name",
only=["name"],
Expand Down Expand Up @@ -511,7 +511,7 @@ class SmsNotificationSchema(NotificationSchema):
to = fields.Str(required=True)

@validates("to")
def validate_to(self, value):
def validate_to(self, value, **kwargs):
try:
validate_phone_number(value, international=True)
except InvalidPhoneError as error:
Expand All @@ -528,7 +528,7 @@ class EmailNotificationSchema(NotificationSchema):
template = fields.Str(required=True)

@validates("to")
def validate_to(self, value):
def validate_to(self, value, **kwargs):
try:
validate_email_address(value)
except InvalidEmailError as e:
Expand All @@ -537,6 +537,7 @@ def validate_to(self, value):

class SmsTemplateNotificationSchema(SmsNotificationSchema):
template = fields.Str(required=True)

job = fields.String()


Expand All @@ -558,6 +559,7 @@ class Meta(BaseSchema.Meta):
],
dump_only=True,
)

job = fields.Nested(JobSchema, only=["id", "original_file_name"], dump_only=True)
created_by = fields.Nested(
UserSchema, only=["id", "name", "email_address"], dump_only=True
Expand Down Expand Up @@ -587,6 +589,8 @@ class NotificationWithPersonalisationSchema(NotificationWithTemplateSchema):
dump_only=True,
)

template_version = field_for(models.Notification, "template_version", required=False)

class Meta(NotificationWithTemplateSchema.Meta):
# mark as many fields as possible as required since this is a public api.
# WARNING: Does _not_ reference fields computed in handle_template_merge, such as
Expand Down Expand Up @@ -649,7 +653,7 @@ class Meta(BaseSchema.Meta):
model = models.InvitedUser

@validates("email_address")
def validate_to(self, value):
def validate_to(self, value, **kwargs):
try:
validate_email_address(value)
except InvalidEmailError as e:
Expand Down Expand Up @@ -719,11 +723,11 @@ def convert_schema_object_to_field(self, in_data, **kwargs):
return in_data

@validates("page")
def validate_page(self, value):
def validate_page(self, value, **kwargs):
_validate_positive_number(value)

@validates("page_size")
def validate_page_size(self, value):
def validate_page_size(self, value, **kwargs):
_validate_positive_number(value)


Expand Down
Loading
Loading