mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
Merge pull request #1539 from alphagov/update_template_schema
Update template schema to return the contact block
This commit is contained in:
@@ -582,6 +582,10 @@ class TemplateBase(db.Model):
|
||||
content = db.Column(db.Text, nullable=False)
|
||||
archived = db.Column(db.Boolean, nullable=False, default=False)
|
||||
subject = db.Column(db.Text)
|
||||
is_letter_contact_blank = db.Column(db.Boolean, nullable=False, default=False)
|
||||
|
||||
# if is_letter_contact = True then service_letter_contact must be null.
|
||||
CheckConstraint("Not(is_letter_contact_blank = True and service_letter_contact_id is not Null)")
|
||||
|
||||
@declared_attr
|
||||
def service_id(cls):
|
||||
|
||||
@@ -315,6 +315,9 @@ class BaseTemplateSchema(BaseSchema):
|
||||
reply_to = fields.Method("get_reply_to", allow_none=True)
|
||||
|
||||
def get_reply_to(self, template):
|
||||
if template.template_type == 'letter':
|
||||
text = template.get_reply_to_text()
|
||||
return text
|
||||
return template.reply_to
|
||||
|
||||
class Meta:
|
||||
|
||||
@@ -120,7 +120,6 @@ def get_template_by_id_and_service_id(service_id, template_id):
|
||||
def preview_template_by_id_and_service_id(service_id, template_id):
|
||||
fetched_template = dao_get_template_by_id_and_service_id(template_id=template_id, service_id=service_id)
|
||||
data = template_schema.dump(fetched_template).data
|
||||
|
||||
template_object = get_template_instance(data, values=request.args.to_dict())
|
||||
|
||||
if template_object.missing_data:
|
||||
|
||||
38
migrations/versions/0153_add_is_letter_contact_blank.py
Normal file
38
migrations/versions/0153_add_is_letter_contact_blank.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""
|
||||
|
||||
Revision ID: ea1c2f80a50e
|
||||
Revises: 0152_kill_service_free_fragments
|
||||
Create Date: 2018-01-04 10:27:01.014640
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision = '0153_add_is_letter_contact_blank'
|
||||
down_revision = '0152_kill_service_free_fragments'
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.add_column('templates', sa.Column('is_letter_contact_blank', sa.Boolean(), nullable=True))
|
||||
op.add_column('templates_history', sa.Column('is_letter_contact_blank', sa.Boolean(), nullable=True))
|
||||
op.execute("update templates set is_letter_contact_blank = false")
|
||||
op.execute("update templates_history set is_letter_contact_blank = false")
|
||||
op.alter_column("templates", "is_letter_contact_blank", nullable=False)
|
||||
op.alter_column("templates_history", "is_letter_contact_blank", nullable=False)
|
||||
|
||||
op.create_check_constraint(
|
||||
"ck_templates_contact_block_is_blank",
|
||||
"templates",
|
||||
"Not(is_letter_contact_blank = True and service_letter_contact_id is not Null)"
|
||||
)
|
||||
op.create_check_constraint(
|
||||
"ck_templates_history_contact_block_is_blank",
|
||||
"templates_history",
|
||||
"Not(is_letter_contact_blank = True and service_letter_contact_id is not Null)"
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column('templates_history', 'is_letter_contact_blank')
|
||||
op.drop_column('templates', 'is_letter_contact_blank')
|
||||
@@ -581,7 +581,7 @@ def test_create_a_template_with_reply_to(admin_request, sample_user):
|
||||
json_resp = admin_request.post('template.create_template', service_id=service.id, _data=data, _expected_status=201)
|
||||
|
||||
assert json_resp['data']['template_type'] == 'letter'
|
||||
assert json_resp['data']['reply_to'] == str(letter_contact.id)
|
||||
assert json_resp['data']['reply_to'] == str(letter_contact.contact_block)
|
||||
|
||||
template = Template.query.get(json_resp['data']['id'])
|
||||
from app.schemas import template_schema
|
||||
@@ -622,7 +622,8 @@ def test_get_template_reply_to(client, sample_letter_template):
|
||||
json_resp = json.loads(resp.get_data(as_text=True))
|
||||
|
||||
assert 'service_letter_contact_id' not in json_resp['data']
|
||||
assert json_resp['data']['reply_to'] == str(letter_contact.id)
|
||||
assert json_resp['data']['reply_to'] == letter_contact.contact_block
|
||||
assert not json_resp['data']['is_letter_contact_blank']
|
||||
|
||||
|
||||
def test_update_template_reply_to(client, sample_letter_template):
|
||||
|
||||
Reference in New Issue
Block a user