diff --git a/app/models.py b/app/models.py index e7d0c8443..b8e65b891 100644 --- a/app/models.py +++ b/app/models.py @@ -1814,3 +1814,16 @@ class FactNotificationStatus(db.Model): notification_count = db.Column(db.Integer(), nullable=False) created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow) updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow) + + +class Complaint(db.Model): + __tablename__ = 'complaints' + id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) + notification_id = db.Column(UUID(as_uuid=True), db.ForeignKey('notification_history.id'), + index=True, nullable=False) + service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), unique=False, index=True, nullable=False) + service = db.relationship(Service, backref=db.backref('complaints')) + ses_feedback_id = db.Column(db.Text, nullable=True) + complaint_type = db.Column(db.Text, nullable=True) + complaint_date = db.Column(db.DateTime, nullable=True) + created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow) diff --git a/app/notifications/notifications_ses_callback.py b/app/notifications/notifications_ses_callback.py index c3c9808c4..8650f8019 100644 --- a/app/notifications/notifications_ses_callback.py +++ b/app/notifications/notifications_ses_callback.py @@ -35,6 +35,8 @@ def process_ses_response(ses_request): if notification_type == 'Bounce': notification_type = determine_notification_bounce_type(notification_type, ses_message) elif notification_type == 'Complaint': + # Complaints are going to be stored in a table of it's own, + # this will no longer update the status of a notification as it does now. remove_emails_from_complaint(ses_message) current_app.logger.info("Complaint from SES: \n{}".format(ses_message)) return diff --git a/app/schemas.py b/app/schemas.py index b9d3b5abf..31b28c32a 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -235,6 +235,7 @@ class ServiceSchema(BaseSchema): 'monthly_billing', 'reply_to_email_addresses', 'letter_contacts', + 'complaints', ) strict = True diff --git a/migrations/versions/0196_complaints_table_.py b/migrations/versions/0196_complaints_table_.py new file mode 100644 index 000000000..45170864c --- /dev/null +++ b/migrations/versions/0196_complaints_table_.py @@ -0,0 +1,36 @@ +""" + +Revision ID: 0196_complaints_table +Revises: 0195_ft_notification_timestamps +Create Date: 2018-05-31 14:31:36.649544 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +revision = '0196_complaints_table' +down_revision = '0195_ft_notification_timestamps' + + +def upgrade(): + op.create_table('complaints', + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('notification_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('ses_feedback_id', sa.Text(), nullable=True), + sa.Column('complaint_type', sa.Text(), nullable=True), + sa.Column('complaint_date', sa.DateTime(), nullable=True), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.ForeignKeyConstraint(['notification_id'], ['notification_history.id'], ), + sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_complaints_notification_id'), 'complaints', ['notification_id'], unique=False) + op.create_index(op.f('ix_complaints_service_id'), 'complaints', ['service_id'], unique=False) + + +def downgrade(): + op.drop_index(op.f('ix_complaints_service_id'), table_name='complaints') + op.drop_index(op.f('ix_complaints_notification_id'), table_name='complaints') + op.drop_table('complaints')