mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 14:08:47 -04:00
Add choose_postage service permission and add postage to Template
This commit is contained in:
@@ -257,6 +257,7 @@ LETTERS_AS_PDF = 'letters_as_pdf'
|
|||||||
PRECOMPILED_LETTER = 'precompiled_letter'
|
PRECOMPILED_LETTER = 'precompiled_letter'
|
||||||
UPLOAD_DOCUMENT = 'upload_document'
|
UPLOAD_DOCUMENT = 'upload_document'
|
||||||
EDIT_FOLDERS = 'edit_folders'
|
EDIT_FOLDERS = 'edit_folders'
|
||||||
|
CHOOSE_POSTAGE = 'choose_postage'
|
||||||
|
|
||||||
SERVICE_PERMISSION_TYPES = [
|
SERVICE_PERMISSION_TYPES = [
|
||||||
EMAIL_TYPE,
|
EMAIL_TYPE,
|
||||||
@@ -270,6 +271,7 @@ SERVICE_PERMISSION_TYPES = [
|
|||||||
PRECOMPILED_LETTER,
|
PRECOMPILED_LETTER,
|
||||||
UPLOAD_DOCUMENT,
|
UPLOAD_DOCUMENT,
|
||||||
EDIT_FOLDERS,
|
EDIT_FOLDERS,
|
||||||
|
CHOOSE_POSTAGE
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -762,6 +764,15 @@ class TemplateBase(db.Model):
|
|||||||
archived = db.Column(db.Boolean, nullable=False, default=False)
|
archived = db.Column(db.Boolean, nullable=False, default=False)
|
||||||
hidden = db.Column(db.Boolean, nullable=False, default=False)
|
hidden = db.Column(db.Boolean, nullable=False, default=False)
|
||||||
subject = db.Column(db.Text)
|
subject = db.Column(db.Text)
|
||||||
|
postage = db.Column(db.String, nullable=True)
|
||||||
|
CheckConstraint("""
|
||||||
|
CASE WHEN template_type = 'letter' THEN
|
||||||
|
postage in ('first', 'second') OR
|
||||||
|
postage is null
|
||||||
|
ELSE
|
||||||
|
postage is null
|
||||||
|
END
|
||||||
|
""")
|
||||||
|
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def service_id(cls):
|
def service_id(cls):
|
||||||
@@ -861,6 +872,7 @@ class TemplateBase(db.Model):
|
|||||||
}
|
}
|
||||||
for key in self._as_utils_template().placeholders
|
for key in self._as_utils_template().placeholders
|
||||||
},
|
},
|
||||||
|
"postage": self.postage,
|
||||||
}
|
}
|
||||||
|
|
||||||
return serialized
|
return serialized
|
||||||
|
|||||||
54
migrations/versions/0248_enable_choose_postage.py
Normal file
54
migrations/versions/0248_enable_choose_postage.py
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
"""
|
||||||
|
|
||||||
|
Revision ID: 0248_enable_choose_postage
|
||||||
|
Revises: 0247_another_letter_org
|
||||||
|
Create Date: 2018-12-14 12:09:31.375634
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
revision = '0248_enable_choose_postage'
|
||||||
|
down_revision = '0247_another_letter_org'
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.execute("INSERT INTO service_permission_types VALUES ('choose_postage')")
|
||||||
|
op.add_column('templates', sa.Column('postage', sa.String(), nullable=True))
|
||||||
|
op.add_column('templates_history', sa.Column('postage', sa.String(), nullable=True))
|
||||||
|
op.execute("""
|
||||||
|
ALTER TABLE templates ADD CONSTRAINT "chk_templates_postage_null"
|
||||||
|
CHECK (
|
||||||
|
CASE WHEN template_type = 'letter' THEN
|
||||||
|
postage in ('first', 'second') OR
|
||||||
|
postage is null
|
||||||
|
ELSE
|
||||||
|
postage is null
|
||||||
|
END
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
op.execute("""
|
||||||
|
ALTER TABLE templates_history ADD CONSTRAINT "chk_templates_history_postage_null"
|
||||||
|
CHECK (
|
||||||
|
CASE WHEN template_type = 'letter' THEN
|
||||||
|
postage in ('first', 'second') OR
|
||||||
|
postage is null
|
||||||
|
ELSE
|
||||||
|
postage is null
|
||||||
|
END
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_constraint('chk_templates_history_postage_null', 'templates_history', type_='check')
|
||||||
|
op.drop_constraint('chk_templates_postage_null', 'templates', type_='check')
|
||||||
|
op.drop_column('templates_history', 'postage')
|
||||||
|
op.drop_column('templates', 'postage')
|
||||||
|
op.execute("DELETE FROM service_permissions WHERE permission = 'choose_postage'")
|
||||||
|
op.execute("DELETE FROM service_permission_types WHERE name = 'choose_postage'")
|
||||||
|
# ### end Alembic commands ###
|
||||||
@@ -41,6 +41,7 @@ def test_get_template_by_id_returns_200(client, sample_service, tmp_type, expect
|
|||||||
"subject": expected_subject,
|
"subject": expected_subject,
|
||||||
'name': expected_name,
|
'name': expected_name,
|
||||||
'personalisation': {},
|
'personalisation': {},
|
||||||
|
'postage': None,
|
||||||
}
|
}
|
||||||
|
|
||||||
assert json_response == expected_response
|
assert json_response == expected_response
|
||||||
|
|||||||
Reference in New Issue
Block a user