fix: attribute duplicated project to the user who duplicated it

duplicate() kept the original author in created_by. The project list
filters on created_by, so a non-admin user could not see the copy they
just made. Pass the caller through both duplication paths, the same way
import already does since #3017.
This commit is contained in:
YueGuobin committed 2026-11-05 19:22:27 +08:00
1 parent 7230e86c15
commit 517b0b0d85
4 files changed
+39 -5

No files matched your search

+21 -1
View File
@@ -936,9 +936,10 @@ async def test_duplicate(project, controller):
compute, "test", None, node_type="vmware", properties={"startup_config": "test.cfg"}
)
new_project = await project.duplicate(name="Hello")
new_project = await project.duplicate(name="Hello", user="user1")
assert new_project.id != project.id
assert new_project.name == "Hello"
assert new_project.created_by == "user1"
await new_project.open()
@@ -946,6 +947,25 @@ async def test_duplicate(project, controller):
assert list(new_project.nodes.values())[1].compute.id == "remote"
@pytest.mark.asyncio
async def test_duplicate_created_by(project, controller):
"""
The duplicated project is owned by the user who duplicated it (fast path)
"""
project.created_by = "alice"
project.dump()
new_project = await project.duplicate(name="Hello", user="bob")
assert new_project.created_by == "bob"
# the original project keeps its owner
assert project.created_by == "alice"
# without a user the original owner is kept (backward compatible)
new_project = await project.duplicate(name="Hello2")
assert new_project.created_by == "alice"
def test_snapshots(project):
"""
List the snapshots