mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-11 09:27:56 -04:00
Merge branch 'populate_provider_column' into firetext-inbound-sms-not-null-provider
This commit is contained in:
@@ -93,6 +93,7 @@ def register_blueprint(application):
|
||||
from app.organisation.rest import organisation_blueprint
|
||||
from app.dvla_organisation.rest import dvla_organisation_blueprint
|
||||
from app.delivery.rest import delivery_blueprint
|
||||
from app.inbound_sms.rest import inbound_sms as inbound_sms_blueprint
|
||||
from app.notifications.receive_notifications import receive_notifications_blueprint
|
||||
from app.notifications.notifications_ses_callback import ses_callback_blueprint
|
||||
from app.notifications.notifications_sms_callback import sms_callback_blueprint
|
||||
@@ -133,6 +134,9 @@ def register_blueprint(application):
|
||||
delivery_blueprint.before_request(requires_admin_auth)
|
||||
application.register_blueprint(delivery_blueprint)
|
||||
|
||||
inbound_sms_blueprint.before_request(requires_admin_auth)
|
||||
application.register_blueprint(inbound_sms_blueprint)
|
||||
|
||||
accept_invite.before_request(requires_admin_auth)
|
||||
application.register_blueprint(accept_invite, url_prefix='/invite')
|
||||
|
||||
|
||||
@@ -1,7 +1,30 @@
|
||||
from app import db
|
||||
from app.dao.dao_utils import transactional
|
||||
from app.models import InboundSms
|
||||
|
||||
|
||||
@transactional
|
||||
def dao_create_inbound_sms(inbound_sms):
|
||||
db.session.add(inbound_sms)
|
||||
|
||||
|
||||
def dao_get_inbound_sms_for_service(service_id, limit=None, user_number=None):
|
||||
q = InboundSms.query.filter(
|
||||
InboundSms.service_id == service_id
|
||||
).order_by(
|
||||
InboundSms.created_at.desc()
|
||||
)
|
||||
|
||||
if user_number:
|
||||
q = q.filter(InboundSms.user_number == user_number)
|
||||
|
||||
if limit:
|
||||
q = q.limit(limit)
|
||||
|
||||
return q.all()
|
||||
|
||||
|
||||
def dao_count_inbound_sms_for_service(service_id):
|
||||
return InboundSms.query.filter(
|
||||
InboundSms.service_id == service_id
|
||||
).count()
|
||||
|
||||
0
app/inbound_sms/__init__.py
Normal file
0
app/inbound_sms/__init__.py
Normal file
42
app/inbound_sms/rest.py
Normal file
42
app/inbound_sms/rest.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from flask import (
|
||||
Blueprint,
|
||||
jsonify,
|
||||
request
|
||||
)
|
||||
from notifications_utils.recipients import validate_and_format_phone_number
|
||||
|
||||
from app.dao.inbound_sms_dao import dao_get_inbound_sms_for_service, dao_count_inbound_sms_for_service
|
||||
from app.errors import register_errors
|
||||
|
||||
inbound_sms = Blueprint(
|
||||
'inbound_sms',
|
||||
__name__,
|
||||
url_prefix='/service/<service_id>/inbound-sms'
|
||||
)
|
||||
|
||||
register_errors(inbound_sms)
|
||||
|
||||
|
||||
@inbound_sms.route('')
|
||||
def get_inbound_sms_for_service(service_id):
|
||||
limit = request.args.get('limit')
|
||||
user_number = request.args.get('user_number')
|
||||
|
||||
if user_number:
|
||||
# we use this to normalise to an international phone number
|
||||
user_number = validate_and_format_phone_number(user_number, international=True)
|
||||
|
||||
results = dao_get_inbound_sms_for_service(service_id, limit, user_number)
|
||||
|
||||
return jsonify(data=[row.serialize() for row in results])
|
||||
|
||||
|
||||
@inbound_sms.route('/summary')
|
||||
def get_inbound_sms_summary_for_service(service_id):
|
||||
count = dao_count_inbound_sms_for_service(service_id)
|
||||
most_recent = dao_get_inbound_sms_for_service(service_id, limit=1)
|
||||
|
||||
return jsonify(
|
||||
count=count,
|
||||
most_recent=most_recent[0].created_at.isoformat() if most_recent else None
|
||||
)
|
||||
@@ -671,7 +671,6 @@ NOTIFICATION_STATUS_TYPES_BILLABLE = [
|
||||
NOTIFICATION_PERMANENT_FAILURE,
|
||||
]
|
||||
|
||||
|
||||
NOTIFICATION_STATUS_TYPES = [
|
||||
NOTIFICATION_CREATED,
|
||||
NOTIFICATION_SENDING,
|
||||
@@ -1176,3 +1175,32 @@ class InboundSms(db.Model):
|
||||
@content.setter
|
||||
def content(self, content):
|
||||
self._content = encryption.encrypt(content)
|
||||
|
||||
def serialize(self):
|
||||
return {
|
||||
'id': str(self.id),
|
||||
'created_at': self.created_at.isoformat(),
|
||||
'service_id': str(self.service_id),
|
||||
'notify_number': self.notify_number,
|
||||
'user_number': self.user_number,
|
||||
'content': self.content,
|
||||
'provider_date': self.provider_date and self.provider_date.isoformat(),
|
||||
'provider_reference': self.provider_reference
|
||||
}
|
||||
|
||||
|
||||
class LetterRate(db.Model):
|
||||
__tablename__ = 'letter_rates'
|
||||
|
||||
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
valid_from = valid_from = db.Column(db.DateTime, nullable=False)
|
||||
|
||||
|
||||
class LetterRateDetail(db.Model):
|
||||
__tablename__ = 'letter_rate_details'
|
||||
|
||||
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
letter_rate_id = db.Column(UUID(as_uuid=True), db.ForeignKey('letter_rates.id'), index=True, nullable=False)
|
||||
letter_rate = db.relationship('LetterRate', backref='letter_rates')
|
||||
page_total = db.Column(db.Integer, nullable=False)
|
||||
rate = db.Column(db.Numeric(), nullable=False)
|
||||
|
||||
@@ -2,7 +2,7 @@ from urllib.parse import unquote
|
||||
|
||||
import iso8601
|
||||
from flask import jsonify, Blueprint, current_app, request
|
||||
from notifications_utils.recipients import normalise_phone_number
|
||||
from notifications_utils.recipients import validate_and_format_phone_number
|
||||
|
||||
from app import statsd_client, firetext_client, mmg_client
|
||||
from app.dao.services_dao import dao_fetch_services_by_sms_sender
|
||||
@@ -38,7 +38,7 @@ def receive_mmg_sms():
|
||||
# succesfully
|
||||
return 'RECEIVED', 200
|
||||
|
||||
statsd_client.incr('inbound.mmg.succesful')
|
||||
statsd_client.incr('inbound.mmg.successful')
|
||||
|
||||
service = potential_services[0]
|
||||
|
||||
@@ -65,7 +65,7 @@ def format_mmg_datetime(date):
|
||||
|
||||
def create_inbound_mmg_sms_object(service, json):
|
||||
message = format_mmg_message(json['Message'])
|
||||
user_number = normalise_phone_number(json['MSISDN'])
|
||||
user_number = validate_and_format_phone_number(json['MSISDN'], international=True)
|
||||
|
||||
provider_date = json.get('DateRecieved')
|
||||
if provider_date:
|
||||
@@ -100,7 +100,7 @@ def receive_firetext_sms():
|
||||
|
||||
service = potential_services[0]
|
||||
|
||||
user_number = normalise_phone_number(post_data['source'])
|
||||
user_number = validate_and_format_phone_number(post_data['source'], international=True)
|
||||
message = post_data['message']
|
||||
timestamp = post_data['time']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user