Repository navigation
Description
Problem
The editor's Rename (#623) keeps a file in its own folder: a new name holding / or \ is refused (new_file_name in src/server/handlers/common.rs). So the web UI has no way to move a recipe or menu to another folder, except the workaround #622 described for renaming: create a new file at Desserts/Pancakes, paste the text, delete the old one. That loses the title and step pictures, breaks every @./Breakfast/Pancakes{} in other recipes and menus, and leaves the shopping list on the old path.
Proposal: the Rename dialog moves too
Same button, same dialog, same endpoint.
- The field takes a path, like the New form does ("Use folder/recipe-name format"). It opens holding the file's path in the collection without its extension, for example
Breakfast/Pancakes. Change the last part to rename the file, or the folder part to move it. A file at the root opens with just its name, and a name with no folder moves a file to the root. - The dialog says so. The title becomes "Rename or move", and the hint says that pictures and references follow the file, and that a missing folder is created, as New creates one.
POST /api/recipe_rename/{*path}takes an optionalfolderbesidename, relative to the collection root (""is the root):{ "name": "Pancakes", "folder": "Desserts" }. Withoutfolderthe file stays where it is, so today's clients keep working, andnamestill never holds a separator. The answer stays the same (path,references_*,shopping_list_stale), and the editor goes on to/edit/<new path>as it does after a rename.
What a move adds to a rename
Every rule of #622/#623 stays: nothing is overwritten, only the .cook / .menu file and its own pictures move, no hidden files or links are followed, a name that would reach another file is refused, only exact references are rewritten and the rest are reported, autosave cannot recreate the old file, and the shopping list is reported but never rewritten. On top of that, a move has to handle:
- The destination folder. It must resolve inside the recipe directory the way New checks it (
canonical_or_nearest,create_recipedeletes a pre-existing directory when the parent resolves outside the recipe folder through a symlink #549), and it can never be hidden. It is created only once every other check has passed. If the move then fails, the move removes the folders it created, and only those. - Clashes in the destination, not the source. The file name, each picture (
Pasta.2.jpgthere is the title picture ofPasta.2.cook), and the.cook-before-.menurule: movingWeek.cooknext toWeek.menuwould take over every@./…/Week{}. - Another file system. A folder that is a mount point (a NAS share, say) cannot take a
rename(2). Refuse with a clear message instead of copying and deleting. - References to the file change more than their last segment.
./resolves from the collection root and../from the writer's folder (cookcli_core::resolve_reference), so@./Breakfast/Pancakes{}becomes@./Desserts/Pancakes{}, and@../Breakfast/Pancakes{}written inLunch/becomes@../Desserts/Pancakes{}. Each reference keeps the form it was written in. Todayrename::rewrite_referencesonly swaps the last segment ("A rename stays in the file's own folder…",src/server/rename.rs). - References the moved file makes. A
./reference still reaches the same file. A../reference now starts from the new folder, so it has to be rewritten to keep reaching the same file, or reported like any other reference that cannot be rewritten exactly. A rename never had to look at these. - The activity line says
moved Breakfast/Pancakes.cook to Desserts/Pancakes.cook.
Not in a first version
- Moving a whole folder, or several files at once from the listing page.
- A folder picker or drag and drop. A typed path matches New and needs no new control. A
<datalist>of existing folders on the same field could come later.
Implementation sketch
- Handler (
src/server/handlers/recipe_rename.rs):RenameRequest { name, folder: Option<String> }. Resolve and check the destination folder before anything moves. Run the picture, name and menu-shadowing checks against the destination folder's files, and remove only the folders the move created when it is undone. Same route, so/api/recipe_renamekeepsCapability::EditRecipesinauth::middleware. - References (
src/server/rename.rs):Targetgains the destination folder, andrewrite_referencesreplaces the whole name, keeping its./or../form. A second pass rewrites the moved file's own../references from its new folder. - Editor (
templates/edit.html): open the field with the path, split it at the last/on submit, and update the title and hint.rename-title,rename-labelandrename-hintchange in everylocales/*/common.ftl. - Docs: regenerate
docs/api.md. - Tests: unit tests for the rewrite (
./and../forms, written from the source folder, the destination folder, another folder and the root, and the moved file's own../references). Intests/recipe_rename_api_test.rs: a name or picture clash in the destination, menu shadowing, a missing folder created and cleaned up on failure, and refusals for a hidden destination or one outside the recipe directory. Expected paths use the platform separator. A move case intests/e2e/editor-rename.spec.ts.
Activity