mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-24 17:31:34 -05:00
Merge pull request #955 from alphagov/add-service-permission-db-model
Add service permissions model + migration script
This commit is contained in:
@@ -31,6 +31,18 @@ from app import (
|
||||
from app.history_meta import Versioned
|
||||
from app.utils import get_utc_time_in_bst
|
||||
|
||||
SMS_TYPE = 'sms'
|
||||
EMAIL_TYPE = 'email'
|
||||
LETTER_TYPE = 'letter'
|
||||
|
||||
TEMPLATE_TYPES = [SMS_TYPE, EMAIL_TYPE, LETTER_TYPE]
|
||||
|
||||
template_types = db.Enum(*TEMPLATE_TYPES, name='template_type')
|
||||
|
||||
NORMAL = 'normal'
|
||||
PRIORITY = 'priority'
|
||||
TEMPLATE_PROCESS_TYPE = [NORMAL, PRIORITY]
|
||||
|
||||
|
||||
def filter_null_value_fields(obj):
|
||||
return dict(
|
||||
@@ -183,6 +195,30 @@ class Service(db.Model, Versioned):
|
||||
)
|
||||
|
||||
|
||||
INTERNATIONAL_SMS_TYPE = 'international_sms'
|
||||
INCOMING_SMS_TYPE = 'incoming_sms'
|
||||
|
||||
SERVICE_PERMISSION_TYPES = [EMAIL_TYPE, SMS_TYPE, LETTER_TYPE, INTERNATIONAL_SMS_TYPE, INCOMING_SMS_TYPE]
|
||||
|
||||
|
||||
class ServicePermissionTypes(db.Model):
|
||||
__tablename__ = 'service_permission_types'
|
||||
|
||||
name = db.Column(db.String(255), primary_key=True)
|
||||
|
||||
|
||||
class ServicePermission(db.Model):
|
||||
__tablename__ = "service_permissions"
|
||||
|
||||
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'),
|
||||
primary_key=True, index=True, nullable=False)
|
||||
service = db.relationship('Service')
|
||||
permission = db.Column(db.String(255), db.ForeignKey('service_permission_types.name'),
|
||||
index=True, primary_key=True, nullable=False)
|
||||
created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow, nullable=False)
|
||||
updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow)
|
||||
|
||||
|
||||
MOBILE_TYPE = 'mobile'
|
||||
EMAIL_TYPE = 'email'
|
||||
|
||||
@@ -293,19 +329,6 @@ class TemplateProcessTypes(db.Model):
|
||||
name = db.Column(db.String(255), primary_key=True)
|
||||
|
||||
|
||||
SMS_TYPE = 'sms'
|
||||
EMAIL_TYPE = 'email'
|
||||
LETTER_TYPE = 'letter'
|
||||
|
||||
TEMPLATE_TYPES = [SMS_TYPE, EMAIL_TYPE, LETTER_TYPE]
|
||||
|
||||
template_types = db.Enum(*TEMPLATE_TYPES, name='template_type')
|
||||
|
||||
NORMAL = 'normal'
|
||||
PRIORITY = 'priority'
|
||||
TEMPLATE_PROCESS_TYPE = [NORMAL, PRIORITY]
|
||||
|
||||
|
||||
class Template(db.Model):
|
||||
__tablename__ = 'templates'
|
||||
|
||||
|
||||
53
migrations/versions/0083_add_perm_types_and_svc_perm.py
Normal file
53
migrations/versions/0083_add_perm_types_and_svc_perm.py
Normal file
@@ -0,0 +1,53 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0083_add_perm_types_and_svc_perm
|
||||
Revises: 0082_add_go_live_template
|
||||
Create Date: 2017-05-12 11:29:32.664811
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '0083_add_perm_types_and_svc_perm'
|
||||
down_revision = '0082_add_go_live_template'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
service_permission_types = op.create_table('service_permission_types',
|
||||
sa.Column('name', sa.String(length=255), nullable=False),
|
||||
sa.PrimaryKeyConstraint('name'))
|
||||
|
||||
op.bulk_insert(service_permission_types,
|
||||
[
|
||||
{'name': x} for x in {
|
||||
'letter',
|
||||
'email',
|
||||
'sms',
|
||||
'international_sms',
|
||||
'incoming_sms'
|
||||
}
|
||||
])
|
||||
|
||||
op.create_table('service_permissions',
|
||||
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('permission', sa.String(length=255), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['permission'], ['service_permission_types.name'], ),
|
||||
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
|
||||
sa.PrimaryKeyConstraint('service_id', 'permission'))
|
||||
op.create_index(op.f('ix_service_permissions_permission'), 'service_permissions', ['permission'], unique=False)
|
||||
op.create_index(op.f('ix_service_permissions_service_id'), 'service_permissions', ['service_id'], unique=False)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index(op.f('ix_service_permissions_service_id'), table_name='service_permissions')
|
||||
op.drop_index(op.f('ix_service_permissions_permission'), table_name='service_permissions')
|
||||
op.drop_table('service_permissions')
|
||||
op.drop_table('service_permission_types')
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user