mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 17:01:35 -05:00
don't create job if template has been archived
This commit is contained in:
@@ -16,7 +16,7 @@ from app.dao.services_dao import (
|
||||
|
||||
from app.dao.templates_dao import (dao_get_template_by_id)
|
||||
|
||||
from app.schemas import job_schema
|
||||
from app.schemas import job_schema, unarchived_template_schema
|
||||
|
||||
from app.celery.tasks import process_job
|
||||
|
||||
@@ -52,6 +52,12 @@ def create_job(service_id):
|
||||
"service": service_id
|
||||
})
|
||||
template = dao_get_template_by_id(data['template'])
|
||||
|
||||
errors = unarchived_template_schema.validate({'archived': template.archived})
|
||||
|
||||
if errors:
|
||||
return jsonify(result='error', message=errors), 400
|
||||
|
||||
data.update({"template_version": template.version})
|
||||
job, errors = job_schema.load(data)
|
||||
if errors:
|
||||
|
||||
@@ -381,6 +381,15 @@ class WeekAggregateNotificationStatisticsSchema(ma.Schema):
|
||||
_validate_positive_number(value)
|
||||
|
||||
|
||||
class UnarchivedTemplateSchema(BaseSchema):
|
||||
archived = fields.Boolean(required=True)
|
||||
|
||||
@validates_schema
|
||||
def validate_archived(self, data):
|
||||
if data['archived']:
|
||||
raise ValidationError('Template has been deleted', 'template')
|
||||
|
||||
|
||||
user_schema = UserSchema()
|
||||
user_schema_load_json = UserSchema(load_json=True)
|
||||
service_schema = ServiceSchema()
|
||||
@@ -413,3 +422,4 @@ from_to_date_schema = FromToDateSchema()
|
||||
provider_details_schema = ProviderDetailsSchema()
|
||||
week_aggregate_notification_statistics_schema = WeekAggregateNotificationStatisticsSchema()
|
||||
day_schema = DaySchema()
|
||||
unarchived_template_schema = UnarchivedTemplateSchema()
|
||||
|
||||
Reference in New Issue
Block a user