Skip to content

Commit

Permalink
Add a duplicated project in the same resource pools as the original p…
Browse files Browse the repository at this point in the history
…roject if it is in any
  • Loading branch information
grossmj committed Nov 17, 2024
1 parent a7da814 commit e83e12b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion gns3server/api/routes/controller/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ async def import_project(
)
async def duplicate_project(
project_data: schemas.ProjectDuplicate,
project: Project = Depends(dep_project)
project: Project = Depends(dep_project),
pools_repo: ResourcePoolsRepository = Depends(get_repository(ResourcePoolsRepository))
) -> schemas.Project:
"""
Duplicate a project.
Expand All @@ -442,6 +443,15 @@ async def duplicate_project(
new_project = await project.duplicate(
name=project_data.name, reset_mac_addresses=reset_mac_addresses
)

# Add the new project in the same resource pools if the duplicated project is in any
pool_memberships = await pools_repo.get_resource_memberships(project.id)
if pool_memberships:
resource_create = schemas.ResourceCreate(resource_id=new_project.id, resource_type="project", name=new_project.name)
resource = await pools_repo.create_resource(resource_create)
for pool in pool_memberships:
await pools_repo.add_resource_to_pool(pool.resource_pool_id, resource)

return new_project.asdict()


Expand Down

0 comments on commit e83e12b

Please sign in to comment.