mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Don't allow to set postage per template if no service permission
This commit is contained in:
@@ -31,7 +31,7 @@ from app.errors import (
|
||||
InvalidRequest
|
||||
)
|
||||
from app.letters.utils import get_letter_pdf
|
||||
from app.models import SMS_TYPE, Template
|
||||
from app.models import SMS_TYPE, Template, CHOOSE_POSTAGE
|
||||
from app.notifications.validators import service_has_permission, check_reply_to
|
||||
from app.schema_validation import validate
|
||||
from app.schemas import (template_schema, template_history_schema)
|
||||
@@ -78,6 +78,12 @@ def create_template(service_id):
|
||||
errors = {'template_type': [message]}
|
||||
raise InvalidRequest(errors, 403)
|
||||
|
||||
if new_template.postage:
|
||||
if not service_has_permission(CHOOSE_POSTAGE, fetched_service.permissions):
|
||||
message = "Setting postage on templates is not enabled for this service."
|
||||
errors = {'template_postage': [message]}
|
||||
raise InvalidRequest(errors, 403)
|
||||
|
||||
new_template.service = fetched_service
|
||||
|
||||
over_limit = _content_count_greater_than_limit(new_template.content, new_template.template_type)
|
||||
@@ -110,6 +116,12 @@ def update_template(service_id, template_id):
|
||||
if data.get('redact_personalisation') is True:
|
||||
return redact_template(fetched_template, data)
|
||||
|
||||
if data.get('postage'):
|
||||
if not service_has_permission(CHOOSE_POSTAGE, fetched_template.service.permissions):
|
||||
message = "Setting postage on templates is not enabled for this service."
|
||||
errors = {'template_postage': [message]}
|
||||
raise InvalidRequest(errors, 403)
|
||||
|
||||
if "reply_to" in data:
|
||||
check_reply_to(service_id, data.get("reply_to"), fetched_template.template_type)
|
||||
updated = dao_update_template_reply_to(template_id=template_id, reply_to=data.get("reply_to"))
|
||||
|
||||
@@ -17,7 +17,8 @@ post_create_template_schema = {
|
||||
"content": {"type": "string"},
|
||||
"subject": {"type": "string"},
|
||||
"created_by": uuid,
|
||||
"parent_folder_id": uuid
|
||||
"parent_folder_id": uuid,
|
||||
"postage": {"type": "string"},
|
||||
},
|
||||
"if": {
|
||||
"properties": {
|
||||
|
||||
Reference in New Issue
Block a user