mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-24 01:11:38 -05:00
Added endpoint for removing user from service, all tests passing.
This commit is contained in:
@@ -20,7 +20,8 @@ from app.dao.services_dao import (
|
||||
dao_create_service,
|
||||
dao_update_service,
|
||||
dao_fetch_all_services_by_user,
|
||||
dao_add_user_to_service
|
||||
dao_add_user_to_service,
|
||||
dao_remove_user_from_service
|
||||
)
|
||||
|
||||
from app.dao.users_dao import get_model_users
|
||||
@@ -159,6 +160,22 @@ def add_user_to_service(service_id, user_id):
|
||||
return jsonify(data=data), 201
|
||||
|
||||
|
||||
@service.route('/<uuid:service_id>/users/<user_id>', methods=['DELETE'])
|
||||
def remove_user_from_service(service_id, user_id):
|
||||
service = dao_fetch_service_by_id(service_id)
|
||||
user = get_model_users(user_id=user_id)
|
||||
if user not in service.users:
|
||||
return jsonify(
|
||||
result='error',
|
||||
message='User not found'), 404
|
||||
elif len(service.users) == 1:
|
||||
return jsonify(
|
||||
result='error',
|
||||
message='You cannot remove the only user for a service'), 400
|
||||
dao_remove_user_from_service(service, user)
|
||||
return jsonify({}), 204
|
||||
|
||||
|
||||
def _process_permissions(user, service, permission_groups):
|
||||
from app.permissions_utils import get_permissions_by_group
|
||||
from app.dao.permissions_dao import permission_dao
|
||||
|
||||
Reference in New Issue
Block a user