add org invite template to db

This commit is contained in:
Leo Hemsted
2018-02-16 14:42:03 +00:00
committed by Rebecca Law
parent a2a1c5e9af
commit 5b71d2f36e
5 changed files with 84 additions and 9 deletions

View File

@@ -188,7 +188,7 @@ def delete_invitations():
deleted_invites = delete_invitations_created_more_than_two_days_ago()
deleted_invites += delete_org_invitations_created_more_than_two_days_ago()
current_app.logger.info(
"Delete job started {} finished {} deleted {} invitations".format(start, datetime.utcnow(), deleted)
"Delete job started {} finished {} deleted {} invitations".format(start, datetime.utcnow(), deleted_invites)
)
except SQLAlchemyError:
current_app.logger.exception("Failed to delete invitations")

View File

@@ -149,6 +149,7 @@ class Config(object):
ALREADY_REGISTERED_EMAIL_TEMPLATE_ID = '0880fbb1-a0c6-46f0-9a8e-36c986381ceb'
CHANGE_EMAIL_CONFIRMATION_TEMPLATE_ID = 'eb4d9930-87ab-4aef-9bce-786762687884'
SERVICE_NOW_LIVE_TEMPLATE_ID = '618185c6-3636-49cd-b7d2-6f6f5eb3bdde'
ORGANISATION_INVITATION_EMAIL_TEMPLATE_ID = '203566f0-d835-47c5-aa06-932439c86573'
BROKER_URL = 'sqs://'
BROKER_TRANSPORT_OPTIONS = {

View File

@@ -225,13 +225,7 @@ organisation_to_service = db.Table(
'organisation_to_service',
db.Model.metadata,
# service_id is a primary key as you can only have one organisation per service
db.Column(
'service_id',
UUID(as_uuid=True),
db.ForeignKey('services.id'),
primary_key=True,
unique=True,
nullable=False),
db.Column('service_id', UUID(as_uuid=True), db.ForeignKey('services.id'), primary_key=True, nullable=False),
db.Column('organisation_id', UUID(as_uuid=True), db.ForeignKey('organisation.id'), nullable=False),
)

View File

@@ -12,7 +12,7 @@ from app.dao.invited_org_user_dao import (
get_invited_org_users_for_organisation
)
from app.dao.templates_dao import dao_get_template_by_id
from app.models import EMAIL_TYPE, KEY_TYPE_NORMAL, Service, InvitedOrganisationUser
from app.models import EMAIL_TYPE, KEY_TYPE_NORMAL, InvitedOrganisationUser
from app.notifications.process_notifications import persist_notification, send_notification_to_queue
from app.schemas import invited_org_user_schema
from app.errors import register_errors

View File

@@ -0,0 +1,80 @@
"""
Revision ID: 0167_add_org_invite_template
Revises: 0166_add_org_user_stuff
Create Date: 2018-02-16 14:16:43.618062
"""
from datetime import datetime
from alembic import op
from flask import current_app
revision = '0167_add_org_invite_template'
down_revision = '0166_add_org_user_stuff'
template_id = '203566f0-d835-47c5-aa06-932439c86573'
def upgrade():
template_insert = """
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject, created_by_id, version, process_type)
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}')
"""
template_history_insert = """
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject, created_by_id, version, process_type)
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}')
"""
template_content = '\n'.join([
"((user_name)) has invited you to collaborate on ((organisation_name)) on GOV.UK Notify.",
"",
"GOV.UK Notify makes it easy to keep people updated by helping you send text messages, emails and letters.",
"",
"Open this link to create an account on GOV.UK Notify:",
"((url))",
"",
"This invitation will stop working at midnight tomorrow. This is to keep ((organisation_name)) secure.",
])
template_name = "Notify organisation invitation email"
template_subject = '((user_name)) has invited you to collaborate on ((organisation_name)) on GOV.UK Notify'
op.execute(
template_history_insert.format(
template_id,
template_name,
'email',
datetime.utcnow(),
template_content,
current_app.config['NOTIFY_SERVICE_ID'],
template_subject,
current_app.config['NOTIFY_USER_ID'],
'normal'
)
)
op.execute(
template_insert.format(
template_id,
template_name,
'email',
datetime.utcnow(),
template_content,
current_app.config['NOTIFY_SERVICE_ID'],
template_subject,
current_app.config['NOTIFY_USER_ID'],
'normal'
)
)
# clean up constraints on org_to_service - service_id-org_id constraint is redundant
op.drop_constraint('organisation_to_service_service_id_organisation_id_key', 'organisation_to_service', type_='unique')
def downgrade():
op.execute("DELETE FROM templates_history WHERE id = '{}'".format(template_id))
op.execute("DELETE FROM templates WHERE id = '{}'".format(template_id))
op.create_unique_constraint('organisation_to_service_service_id_organisation_id_key', 'organisation_to_service', ['service_id', 'organisation_id'])