mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
make user mobile num nullable if user has email_auth enabled
This commit is contained in:
@@ -4,6 +4,7 @@ from datetime import datetime
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from flask import (jsonify, request, Blueprint, current_app, abort)
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from app.config import QueueNames
|
||||
from app.dao.users_dao import (
|
||||
@@ -52,6 +53,19 @@ user_blueprint = Blueprint('user', __name__)
|
||||
register_errors(user_blueprint)
|
||||
|
||||
|
||||
@user_blueprint.errorhandler(IntegrityError)
|
||||
def handle_integrity_error(exc):
|
||||
"""
|
||||
Handle integrity errors caused by the auth type/mobile number check constraint
|
||||
"""
|
||||
if 'ck_users_mobile_or_email_auth' in str(exc):
|
||||
# we don't expect this to trip, so still log error
|
||||
current_app.logger.exception('Check constraint ck_users_mobile_or_email_auth triggered')
|
||||
return jsonify(result='error', message='Mobile number must be set if auth_type is set to sms_auth'), 400
|
||||
|
||||
raise
|
||||
|
||||
|
||||
@user_blueprint.route('', methods=['POST'])
|
||||
def create_user():
|
||||
user_to_create, errors = user_schema.load(request.get_json())
|
||||
|
||||
Reference in New Issue
Block a user