fix(rename): refresh Folder.name on webhook-driven directory rename
handle_directory_rename updated Folder.path but left Folder.name as
the old leaf basename. Path is load-bearing; name is purely display,
but a stale name shows wrong text in the sidebar tree until the next
manual refresh. Now sets folder.name = basename(new_prefix) on the
renamed folder itself; descendants keep their existing names because
the rename was on an ancestor (only their paths shift).
Same correctness as the existing PATCH /folders/{id} endpoint, which
also updates both name and path.
This commit is contained in:
@@ -641,9 +641,18 @@ async def handle_directory_rename(old_dirpath: str, new_dirpath: str) -> dict:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)).scalars().all()
|
)).scalars().all()
|
||||||
|
# Path is load-bearing (FKs join on it implicitly via filepath),
|
||||||
|
# name is purely display. The renamed folder itself gets its
|
||||||
|
# leaf basename refreshed too so the sidebar tree doesn't show
|
||||||
|
# stale text. Descendant folders keep their existing name
|
||||||
|
# because the rename was on the ancestor — only the path changes.
|
||||||
|
new_basename = os.path.basename(new_prefix)
|
||||||
for f in folders:
|
for f in folders:
|
||||||
f.path = new_prefix if f.path == old_prefix else \
|
if f.path == old_prefix:
|
||||||
new_prefix + f.path[len(old_prefix):]
|
f.path = new_prefix
|
||||||
|
f.name = new_basename
|
||||||
|
else:
|
||||||
|
f.path = new_prefix + f.path[len(old_prefix):]
|
||||||
|
|
||||||
source_roots = (await session.execute(
|
source_roots = (await session.execute(
|
||||||
select(SourceRoot).where(SourceRoot.path == old_prefix)
|
select(SourceRoot).where(SourceRoot.path == old_prefix)
|
||||||
|
|||||||
Reference in New Issue
Block a user