mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Add endpoint to allow org team members to be removed
This is similar to the corresponding endpoint for services. However, it is a little simpler since we don't need to worry about always having at least one team member for an organisation. The new dao function added, `dao_remove_user_from_organisation`, is also simpler than `dao_remove_user_from_service` since we don't have any organisation permissions to deal with.
This commit is contained in:
@@ -137,3 +137,8 @@ def dao_add_user_to_organisation(organisation_id, user_id):
|
||||
user.organisations.append(organisation)
|
||||
db.session.add(organisation)
|
||||
return user
|
||||
|
||||
|
||||
@autocommit
|
||||
def dao_remove_user_from_organisation(organisation, user):
|
||||
organisation.users.remove(user)
|
||||
|
||||
@@ -15,10 +15,12 @@ from app.dao.organisation_dao import (
|
||||
dao_get_organisation_services,
|
||||
dao_get_organisations,
|
||||
dao_get_users_for_organisation,
|
||||
dao_remove_user_from_organisation,
|
||||
dao_update_organisation,
|
||||
)
|
||||
from app.dao.services_dao import dao_fetch_service_by_id
|
||||
from app.dao.templates_dao import dao_get_template_by_id
|
||||
from app.dao.users_dao import get_user_by_id
|
||||
from app.errors import InvalidRequest, register_errors
|
||||
from app.models import KEY_TYPE_NORMAL, Organisation
|
||||
from app.notifications.process_notifications import (
|
||||
@@ -152,6 +154,20 @@ def add_user_to_organisation(organisation_id, user_id):
|
||||
return jsonify(data=new_org_user.serialize())
|
||||
|
||||
|
||||
@organisation_blueprint.route('/<uuid:organisation_id>/users/<uuid:user_id>', methods=['DELETE'])
|
||||
def remove_user_from_organisation(organisation_id, user_id):
|
||||
organisation = dao_get_organisation_by_id(organisation_id)
|
||||
user = get_user_by_id(user_id=user_id)
|
||||
|
||||
if user not in organisation.users:
|
||||
error = 'User not found'
|
||||
raise InvalidRequest(error, status_code=404)
|
||||
|
||||
dao_remove_user_from_organisation(organisation, user)
|
||||
|
||||
return {}, 204
|
||||
|
||||
|
||||
@organisation_blueprint.route('/<uuid:organisation_id>/users', methods=['GET'])
|
||||
def get_organisation_users(organisation_id):
|
||||
org_users = dao_get_users_for_organisation(organisation_id)
|
||||
|
||||
Reference in New Issue
Block a user