mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-26 09:13:40 -04:00
Merge pull request #3537 from alphagov/existing-marshmallow-changes
Fix existing marshmallow schemas and remove unused code
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
from datetime import date, datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
from flask_marshmallow.fields import fields
|
from flask_marshmallow.fields import fields
|
||||||
@@ -40,16 +40,6 @@ def _validate_datetime_not_more_than_96_hours_in_future(dte, msg="Date cannot be
|
|||||||
raise ValidationError(msg)
|
raise ValidationError(msg)
|
||||||
|
|
||||||
|
|
||||||
def _validate_not_in_past(dte, msg="Date cannot be in the past"):
|
|
||||||
if dte < date.today():
|
|
||||||
raise ValidationError(msg)
|
|
||||||
|
|
||||||
|
|
||||||
def _validate_datetime_not_in_future(dte, msg="Date cannot be in the future"):
|
|
||||||
if dte > datetime.utcnow():
|
|
||||||
raise ValidationError(msg)
|
|
||||||
|
|
||||||
|
|
||||||
def _validate_datetime_not_in_past(dte, msg="Date cannot be in the past"):
|
def _validate_datetime_not_in_past(dte, msg="Date cannot be in the past"):
|
||||||
if dte < datetime.utcnow():
|
if dte < datetime.utcnow():
|
||||||
raise ValidationError(msg)
|
raise ValidationError(msg)
|
||||||
@@ -115,8 +105,6 @@ class UserSchema(BaseSchema):
|
|||||||
"created_at",
|
"created_at",
|
||||||
"email_access_validated_at",
|
"email_access_validated_at",
|
||||||
"updated_at",
|
"updated_at",
|
||||||
"user_to_organisation",
|
|
||||||
"user_to_service",
|
|
||||||
"verify_codes",
|
"verify_codes",
|
||||||
)
|
)
|
||||||
strict = True
|
strict = True
|
||||||
@@ -157,7 +145,6 @@ class UserUpdateAttributeSchema(BaseSchema):
|
|||||||
'platform_admin',
|
'platform_admin',
|
||||||
'state',
|
'state',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
'user_to_service',
|
|
||||||
'verify_codes',
|
'verify_codes',
|
||||||
)
|
)
|
||||||
strict = True
|
strict = True
|
||||||
@@ -193,7 +180,6 @@ class UserUpdatePasswordSchema(BaseSchema):
|
|||||||
|
|
||||||
class Meta(BaseSchema.Meta):
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.User
|
model = models.User
|
||||||
only = ('password')
|
|
||||||
strict = True
|
strict = True
|
||||||
|
|
||||||
@validates_schema(pass_original=True)
|
@validates_schema(pass_original=True)
|
||||||
@@ -208,7 +194,6 @@ class ProviderDetailsSchema(BaseSchema):
|
|||||||
|
|
||||||
class Meta(BaseSchema.Meta):
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.ProviderDetails
|
model = models.ProviderDetails
|
||||||
exclude = ("provider_stats",)
|
|
||||||
strict = True
|
strict = True
|
||||||
|
|
||||||
|
|
||||||
@@ -217,7 +202,6 @@ class ProviderDetailsHistorySchema(BaseSchema):
|
|||||||
|
|
||||||
class Meta(BaseSchema.Meta):
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.ProviderDetailsHistory
|
model = models.ProviderDetailsHistory
|
||||||
exclude = ("provider_stats",)
|
|
||||||
strict = True
|
strict = True
|
||||||
|
|
||||||
|
|
||||||
@@ -267,15 +251,11 @@ class ServiceSchema(BaseSchema, UUIDsAsStringsMixin):
|
|||||||
'jobs',
|
'jobs',
|
||||||
'letter_contacts',
|
'letter_contacts',
|
||||||
'letter_logo_filename',
|
'letter_logo_filename',
|
||||||
'old_id',
|
|
||||||
'reply_to_email_addresses',
|
'reply_to_email_addresses',
|
||||||
'returned_letters',
|
'returned_letters',
|
||||||
'service_broadcast_provider_restriction',
|
'service_broadcast_provider_restriction',
|
||||||
'service_broadcast_settings',
|
'service_broadcast_settings',
|
||||||
'service_notification_stats',
|
|
||||||
'service_provider_stats',
|
|
||||||
'service_sms_senders',
|
'service_sms_senders',
|
||||||
'template_statistics',
|
|
||||||
'templates',
|
'templates',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
'users',
|
'users',
|
||||||
@@ -327,20 +307,12 @@ class DetailedServiceSchema(BaseSchema):
|
|||||||
'inbound_number',
|
'inbound_number',
|
||||||
'inbound_sms',
|
'inbound_sms',
|
||||||
'jobs',
|
'jobs',
|
||||||
'letter_contact_block',
|
|
||||||
'letter_logo_filename',
|
|
||||||
'message_limit',
|
'message_limit',
|
||||||
'monthly_billing',
|
|
||||||
'permissions',
|
'permissions',
|
||||||
'rate_limit',
|
'rate_limit',
|
||||||
'reply_to_email_address',
|
|
||||||
'reply_to_email_addresses',
|
'reply_to_email_addresses',
|
||||||
'returned_letters',
|
'returned_letters',
|
||||||
'service_notification_stats',
|
|
||||||
'service_provider_stats',
|
|
||||||
'service_sms_senders',
|
'service_sms_senders',
|
||||||
'sms_sender',
|
|
||||||
'template_statistics',
|
|
||||||
'templates',
|
'templates',
|
||||||
'users',
|
'users',
|
||||||
'version',
|
'version',
|
||||||
@@ -368,7 +340,7 @@ class BaseTemplateSchema(BaseSchema):
|
|||||||
|
|
||||||
class Meta(BaseSchema.Meta):
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.Template
|
model = models.Template
|
||||||
exclude = ("service_id", "jobs", "service_letter_contact_id", "broadcast_messages")
|
exclude = ("service_id", "jobs", "service_letter_contact_id")
|
||||||
strict = True
|
strict = True
|
||||||
|
|
||||||
|
|
||||||
@@ -434,6 +406,7 @@ class TemplateHistorySchema(BaseSchema):
|
|||||||
|
|
||||||
class Meta(BaseSchema.Meta):
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.TemplateHistory
|
model = models.TemplateHistory
|
||||||
|
exclude = ('broadcast_messages',)
|
||||||
|
|
||||||
|
|
||||||
class ApiKeySchema(BaseSchema):
|
class ApiKeySchema(BaseSchema):
|
||||||
@@ -530,7 +503,7 @@ class NotificationWithTemplateSchema(BaseSchema):
|
|||||||
class Meta(BaseSchema.Meta):
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.Notification
|
model = models.Notification
|
||||||
strict = True
|
strict = True
|
||||||
exclude = ('_personalisation', 'scheduled_notification')
|
exclude = ('_personalisation',)
|
||||||
|
|
||||||
template = fields.Nested(
|
template = fields.Nested(
|
||||||
TemplateSchema,
|
TemplateSchema,
|
||||||
@@ -593,6 +566,9 @@ class NotificationWithPersonalisationSchema(NotificationWithTemplateSchema):
|
|||||||
'service',
|
'service',
|
||||||
'template_history',
|
'template_history',
|
||||||
)
|
)
|
||||||
|
# Overwrite the `NotificationWithTemplateSchema` base class to not exclude `_personalisation`, which
|
||||||
|
# isn't a defined field for this class
|
||||||
|
exclude = ()
|
||||||
|
|
||||||
@pre_dump
|
@pre_dump
|
||||||
def handle_personalisation_property(self, in_data):
|
def handle_personalisation_property(self, in_data):
|
||||||
@@ -739,7 +715,7 @@ class UnarchivedTemplateSchema(BaseSchema):
|
|||||||
# should not be used on its own for dumping - only for loading
|
# should not be used on its own for dumping - only for loading
|
||||||
create_user_schema = UserSchema()
|
create_user_schema = UserSchema()
|
||||||
user_update_schema_load_json = UserUpdateAttributeSchema(load_json=True, partial=True)
|
user_update_schema_load_json = UserUpdateAttributeSchema(load_json=True, partial=True)
|
||||||
user_update_password_schema_load_json = UserUpdatePasswordSchema(load_json=True, partial=True)
|
user_update_password_schema_load_json = UserUpdatePasswordSchema(only=('_password',), load_json=True, partial=True)
|
||||||
service_schema = ServiceSchema()
|
service_schema = ServiceSchema()
|
||||||
detailed_service_schema = DetailedServiceSchema()
|
detailed_service_schema = DetailedServiceSchema()
|
||||||
template_schema = TemplateSchema()
|
template_schema = TemplateSchema()
|
||||||
|
|||||||
Reference in New Issue
Block a user