mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-26 17:23:50 -04:00
Add callback_type column to service_callback_api table
Also add service_callback_type table with allowed types
This commit is contained in:
@@ -57,6 +57,10 @@ SMS_AUTH_TYPE = 'sms_auth'
|
|||||||
EMAIL_AUTH_TYPE = 'email_auth'
|
EMAIL_AUTH_TYPE = 'email_auth'
|
||||||
USER_AUTH_TYPE = [SMS_AUTH_TYPE, EMAIL_AUTH_TYPE]
|
USER_AUTH_TYPE = [SMS_AUTH_TYPE, EMAIL_AUTH_TYPE]
|
||||||
|
|
||||||
|
DELIVERY_STATUS_CALLBACK_TYPE = 'delivery_status'
|
||||||
|
COMPLAINT_CALLBACK_TYPE = 'complaint'
|
||||||
|
SERVICE_CALLBACK_TYPES = [DELIVERY_STATUS_CALLBACK_TYPE, COMPLAINT_CALLBACK_TYPE]
|
||||||
|
|
||||||
|
|
||||||
def filter_null_value_fields(obj):
|
def filter_null_value_fields(obj):
|
||||||
return dict(
|
return dict(
|
||||||
@@ -596,6 +600,7 @@ class ServiceCallbackApi(db.Model, Versioned):
|
|||||||
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, nullable=False, unique=True)
|
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, nullable=False, unique=True)
|
||||||
service = db.relationship('Service', backref='service_callback_api')
|
service = db.relationship('Service', backref='service_callback_api')
|
||||||
url = db.Column(db.String(), nullable=False)
|
url = db.Column(db.String(), nullable=False)
|
||||||
|
callback_type = db.Column(db.String(), db.ForeignKey('service_callback_type.name'), nullable=True)
|
||||||
_bearer_token = db.Column("bearer_token", db.String(), nullable=False)
|
_bearer_token = db.Column("bearer_token", db.String(), nullable=False)
|
||||||
created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow, nullable=False)
|
created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow, nullable=False)
|
||||||
updated_at = db.Column(db.DateTime, nullable=True)
|
updated_at = db.Column(db.DateTime, nullable=True)
|
||||||
@@ -624,6 +629,12 @@ class ServiceCallbackApi(db.Model, Versioned):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceCallbackType(db.Model):
|
||||||
|
__tablename__ = 'service_callback_type'
|
||||||
|
|
||||||
|
name = db.Column(db.String, primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
class ApiKey(db.Model, Versioned):
|
class ApiKey(db.Model, Versioned):
|
||||||
__tablename__ = 'api_keys'
|
__tablename__ = 'api_keys'
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ from app.errors import (
|
|||||||
)
|
)
|
||||||
from app.models import (
|
from app.models import (
|
||||||
ServiceInboundApi,
|
ServiceInboundApi,
|
||||||
ServiceCallbackApi
|
ServiceCallbackApi,
|
||||||
|
DELIVERY_STATUS_CALLBACK_TYPE,
|
||||||
)
|
)
|
||||||
from app.schema_validation import validate
|
from app.schema_validation import validate
|
||||||
from app.service.service_callback_api_schema import (
|
from app.service.service_callback_api_schema import (
|
||||||
@@ -88,6 +89,7 @@ def create_service_callback_api(service_id):
|
|||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
validate(data, create_service_callback_api_schema)
|
validate(data, create_service_callback_api_schema)
|
||||||
data["service_id"] = service_id
|
data["service_id"] = service_id
|
||||||
|
data["callback_type"] = DELIVERY_STATUS_CALLBACK_TYPE
|
||||||
callback_api = ServiceCallbackApi(**data)
|
callback_api = ServiceCallbackApi(**data)
|
||||||
try:
|
try:
|
||||||
save_service_callback_api(callback_api)
|
save_service_callback_api(callback_api)
|
||||||
|
|||||||
35
migrations/versions/0205_service_callback_type.py
Normal file
35
migrations/versions/0205_service_callback_type.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
"""
|
||||||
|
|
||||||
|
Revision ID: 0205_service_callback_type
|
||||||
|
Revises: 0204_service_data_retention
|
||||||
|
Create Date: 2018-07-17 15:51:10.776698
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
revision = '0205_service_callback_type'
|
||||||
|
down_revision = '0204_service_data_retention'
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table('service_callback_type',
|
||||||
|
sa.Column('name', sa.String(), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint('name')
|
||||||
|
)
|
||||||
|
op.execute("insert into service_callback_type values ('delivery_status'), ('complaint')")
|
||||||
|
op.add_column('service_callback_api', sa.Column('callback_type', sa.String(), nullable=True))
|
||||||
|
op.create_foreign_key("service_callback_api_type_fk", 'service_callback_api', 'service_callback_type', ['callback_type'], ['name'])
|
||||||
|
op.add_column('service_callback_api_history', sa.Column('callback_type', sa.String(), nullable=True))
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_column('service_callback_api_history', 'callback_type')
|
||||||
|
op.drop_constraint("service_callback_api_type_fk", 'service_callback_api', type_='foreignkey')
|
||||||
|
op.drop_column('service_callback_api', 'callback_type')
|
||||||
|
op.drop_table('service_callback_type')
|
||||||
|
# ### end Alembic commands ###
|
||||||
@@ -106,7 +106,8 @@ def notify_db_session(notify_db):
|
|||||||
"service_permission_types",
|
"service_permission_types",
|
||||||
"auth_type",
|
"auth_type",
|
||||||
"invite_status_type",
|
"invite_status_type",
|
||||||
"letter_rates"]:
|
"letter_rates",
|
||||||
|
"service_callback_type"]:
|
||||||
notify_db.engine.execute(tbl.delete())
|
notify_db.engine.execute(tbl.delete())
|
||||||
notify_db.session.commit()
|
notify_db.session.commit()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user