mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 14:08:47 -04:00
Merge pull request #1270 from alphagov/select-inbound-number-to-assign
Select an inbound number for a service
This commit is contained in:
@@ -31,3 +31,17 @@ def dao_set_inbound_number_active_flag(service_id, active):
|
||||
inbound_number.active = active
|
||||
|
||||
db.session.add(inbound_number)
|
||||
|
||||
|
||||
@transactional
|
||||
def dao_allocate_number_for_service(service_id, inbound_number_id):
|
||||
updated = InboundNumber.query.filter_by(
|
||||
id=inbound_number_id,
|
||||
active=True,
|
||||
service_id=None
|
||||
).update(
|
||||
{"service_id": service_id}
|
||||
)
|
||||
if not updated:
|
||||
raise Exception("Inbound number: {} is not available".format(inbound_number_id))
|
||||
return InboundNumber.query.get(inbound_number_id)
|
||||
|
||||
@@ -5,8 +5,8 @@ from app.dao.inbound_numbers_dao import (
|
||||
dao_get_inbound_number_for_service,
|
||||
dao_get_available_inbound_numbers,
|
||||
dao_set_inbound_number_to_service,
|
||||
dao_set_inbound_number_active_flag
|
||||
)
|
||||
dao_set_inbound_number_active_flag,
|
||||
dao_allocate_number_for_service)
|
||||
from app.dao.service_sms_sender_dao import insert_or_update_service_sms_sender
|
||||
from app.dao.services_dao import dao_fetch_service_by_id
|
||||
from app.errors import InvalidRequest, register_errors
|
||||
@@ -55,3 +55,20 @@ def post_allocate_inbound_number(service_id):
|
||||
def post_set_inbound_number_off(service_id):
|
||||
dao_set_inbound_number_active_flag(service_id, active=False)
|
||||
return jsonify(), 204
|
||||
|
||||
|
||||
@inbound_number_blueprint.route('<uuid:inbound_number_id>/service/<uuid:service_id>', methods=['POST'])
|
||||
def allocate_inbound_number_to_service(inbound_number_id, service_id):
|
||||
service = dao_fetch_service_by_id(service_id=service_id, only_active=True)
|
||||
updated_inbound_number = dao_allocate_number_for_service(service_id=service_id, inbound_number_id=inbound_number_id)
|
||||
insert_or_update_service_sms_sender(service=service,
|
||||
sms_sender=updated_inbound_number.number,
|
||||
inbound_number_id=inbound_number_id)
|
||||
return jsonify(), 204
|
||||
|
||||
|
||||
@inbound_number_blueprint.route('/available', methods=['GET'])
|
||||
def get_available_inbound_numbers():
|
||||
inbound_numbers = [i.serialize() for i in dao_get_available_inbound_numbers()]
|
||||
|
||||
return jsonify(data=inbound_numbers if inbound_numbers else [])
|
||||
|
||||
@@ -204,6 +204,7 @@ class Service(db.Model, Versioned):
|
||||
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=False)
|
||||
_reply_to_email_address = db.Column("reply_to_email_address", db.Text, index=False, unique=False, nullable=True)
|
||||
letter_contact_block = db.Column(db.Text, index=False, unique=False, nullable=True)
|
||||
# This column is now deprecated
|
||||
sms_sender = db.Column(db.String(11), nullable=False, default=lambda: current_app.config['FROM_NUMBER'])
|
||||
organisation_id = db.Column(UUID(as_uuid=True), db.ForeignKey('organisation.id'), index=True, nullable=True)
|
||||
organisation = db.relationship('Organisation')
|
||||
|
||||
Reference in New Issue
Block a user