mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Allow services to add puntuation to or change the case of their name
Changed the '/service/unique' endpoint to optionally accept the service_id parameter. It now doesn't matter if a user tries to change the capitalization or add punctuation to their own service name. But there should still be an error if a user tries to change the punctuation or capitalization of another service. service_id needs to be allowed to be None until notifications-admin is updated to always pass in the service_id.
This commit is contained in:
@@ -673,15 +673,24 @@ def get_organisation_for_service(service_id):
|
||||
|
||||
@service_blueprint.route('/unique', methods=["GET"])
|
||||
def is_service_name_unique():
|
||||
name, email_from = check_request_args(request)
|
||||
service_id, name, email_from = check_request_args(request)
|
||||
|
||||
name_exists = Service.query.filter_by(name=name).first()
|
||||
email_from_exists = Service.query.filter_by(email_from=email_from).first()
|
||||
|
||||
if service_id:
|
||||
email_from_exists = Service.query.filter(
|
||||
Service.email_from == email_from,
|
||||
Service.id != service_id
|
||||
).first()
|
||||
else:
|
||||
email_from_exists = Service.query.filter_by(email_from=email_from).first()
|
||||
|
||||
result = not (name_exists or email_from_exists)
|
||||
return jsonify(result=result), 200
|
||||
|
||||
|
||||
def check_request_args(request):
|
||||
service_id = request.args.get('service_id')
|
||||
name = request.args.get('name', None)
|
||||
email_from = request.args.get('email_from', None)
|
||||
errors = []
|
||||
@@ -691,4 +700,4 @@ def check_request_args(request):
|
||||
errors.append({'email_from': ["Can't be empty"]})
|
||||
if errors:
|
||||
raise InvalidRequest(errors, status_code=400)
|
||||
return name, email_from
|
||||
return service_id, name, email_from
|
||||
|
||||
Reference in New Issue
Block a user