add postage to notification + noti_history

if it's a letter notification, postage must equal "first" or "second",
else it must equal null
This commit is contained in:
Leo Hemsted
2018-09-19 10:49:11 +01:00
parent 645da3f33d
commit 918e4b390f
6 changed files with 62 additions and 25 deletions

View File

@@ -87,7 +87,7 @@ def process_job(job_id):
if not service.active:
job.job_status = JOB_STATUS_CANCELLED
dao_update_job(job)
current_app.logger.warn(
current_app.logger.warning(
"Job {} has been cancelled, service {} is inactive".format(job_id, service.id))
return

View File

@@ -212,7 +212,7 @@ class EmailBranding(db.Model):
db.String(255),
db.ForeignKey('branding_type.name'),
index=True,
nullable=True,
nullable=False,
default=BRANDING_ORG
)
@@ -1182,6 +1182,9 @@ class Notification(db.Model):
reply_to_text = db.Column(db.String, nullable=True)
postage = db.Column(db.String, nullable=True)
CheckConstraint("notification_type != 'letter' or postage in ('first', 'second')")
__table_args__ = (
db.ForeignKeyConstraint(
['template_id', 'template_version'],
@@ -1373,7 +1376,8 @@ class Notification(db.Model):
).strftime(DATETIME_FORMAT)
if self.scheduled_notification
else None
)
),
"postage": self.postage
}
if self.notification_type == LETTER_TYPE:
@@ -1432,6 +1436,9 @@ class NotificationHistory(db.Model, HistoryModel):
created_by = db.relationship('User')
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), nullable=True)
postage = db.Column(db.String, nullable=True, default='second')
CheckConstraint("notification_type != 'letter' or postage in ('first', 'second')")
__table_args__ = (
db.ForeignKeyConstraint(
['template_id', 'template_version'],
@@ -1783,7 +1790,7 @@ class FactBilling(db.Model):
provider = db.Column(db.Text, nullable=True, primary_key=True)
rate_multiplier = db.Column(db.Integer(), nullable=True, primary_key=True)
international = db.Column(db.Boolean, nullable=False, primary_key=False)
rate = db.Column(db.Numeric(), nullable=True)
rate = db.Column(db.Numeric(), nullable=False)
billable_units = db.Column(db.Integer(), nullable=True)
notifications_sent = db.Column(db.Integer(), nullable=True)
created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)

View File

@@ -164,7 +164,7 @@ def send_user_2fa_code(user_id, code_type):
if count_user_verify_codes(user_to_send_to) >= current_app.config.get('MAX_VERIFY_CODE_COUNT'):
# Prevent more than `MAX_VERIFY_CODE_COUNT` active verify codes at a time
current_app.logger.warn('Too many verify codes created for user {}'.format(user_to_send_to.id))
current_app.logger.warning('Too many verify codes created for user {}'.format(user_to_send_to.id))
else:
data = request.get_json()
if code_type == SMS_TYPE: