Fix deleting resource from resource pool. Ref #2293

This commit is contained in:
grossmj
2023-09-28 18:38:38 +10:00
parent 66b66cc3e1
commit a27db6b4eb
3 changed files with 26 additions and 3 deletions

View File

@ -183,7 +183,7 @@ async def create_ace(
route_path = re.sub(r"/{[\w:]+}", r"/\\w+", route_path)
if re.fullmatch(route_path, ace_create.path):
log.info("Creating ACE for route path", ace_create.path, route_path)
log.info(f"Creating ACE for route path {route_path}")
return await rbac_repo.create_ace(ace_create)
raise ControllerBadRequestError(f"Path '{ace_create.path}' doesn't match any existing endpoint")

View File

@ -191,6 +191,7 @@ async def add_resource_to_pool(
if not resource_pool:
raise ControllerNotFoundError(f"Resource pool '{resource_pool_id}' not found")
# TODO: consider if a resource can belong to multiple pools
resources = await pools_repo.get_pool_resources(resource_pool_id)
for resource in resources:
if resource.resource_id == resource_id:
@ -198,8 +199,13 @@ async def add_resource_to_pool(
# we only support projects in resource pools for now
project = Controller.instance().get_project(str(resource_id))
resource_create = schemas.ResourceCreate(resource_id=resource_id, resource_type="project", name=project.name)
resource = await pools_repo.create_resource(resource_create)
resource = await pools_repo.get_resource(resource_id)
if not resource:
# the resource is not in the database yet, create it
resource_create = schemas.ResourceCreate(resource_id=resource_id, resource_type="project", name=project.name)
resource = await pools_repo.create_resource(resource_create)
await pools_repo.add_resource_to_pool(resource_pool_id, resource)
@ -226,3 +232,8 @@ async def remove_resource_from_pool(
resource_pool = await pools_repo.remove_resource_from_pool(resource_pool_id, resource)
if not resource_pool:
raise ControllerNotFoundError(f"Resource pool '{resource_pool_id}' not found")
# TODO: consider if a resource can belong to multiple pools
success = await pools_repo.delete_resource(resource.resource_id)
if not success:
raise ControllerError(f"Resource '{resource_id}' could not be deleted")