Skip to content

feat(contexts): give applications a menu with its own API - #3135

Open
rubenvdlinde wants to merge 30 commits into
mainfrom
feat/noid/app-menu-model
Open

rubenvdlinde wants to merge 30 commits into
mainfrom
feat/noid/app-menu-model

Conversation

@rubenvdlinde

@rubenvdlinde rubenvdlinde commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Part of the stack on #3133. Implements the menu proposal on #3100: the model and the API. Export and import follow in #3138. This replaces the earlier version of this pull request, together with #3136 and #3137.

Size: 4932 lines: 1405 code, 1362 tests, 2157 generated OpenAPI and 8 version.

Agreed on #3100

  • No technical name on menu items. An export refers to an item's group by its position in the exported menu.
  • Three target columns (page_id, node_rel_id, url), of which at most one is set. The service enforces it; the rule is in the entity docblock.
  • Remnants: deleting a target removes its menu items in the same transaction; creating or changing an item checks its target in its own transaction; reading still leaves out an item whose target is missing, as a safety net. No background job.
  • Empty groups stay in the data. Editors see them, readers without manage access don't.
  • The routes sit under the application, like the other application routes: /api/2/contexts/{contextId}/menu.

What changes

  • A menu item opens at most one thing: a page of the application ({pageId}), a table or view of the application by its node relation ({nodeRelId}), or an http or https link ({url}). An item that opens nothing is a group. Groups are top-level and only groups hold items, so a menu is one level deep.
  • An item without a title shows the title of what it opens: the page, the table or view, or the link. The start page without a title shows the name of the application. The API returns both title (as stored) and displayTitle.
  • Every application gets one item, without a title, for its start page: a migration adds it to existing applications, and creating or importing an application adds it too. It can be moved and renamed, but deleting it or giving it another target gets a 400, unless another item also opens the start page. Adding an item never brings it back.
  • Cleanup: an item goes with its target, in the same transaction: when its page is deleted, when its table or view leaves the application (through the application's nodes, a scheme import, or because the table or view is deleted, also with its owner), and with the application. The items of a deleted group move to the top level.
  • At most 200 items per application.
  • The application response stays as it is on main. Permission checks and the application response don't load the menu.
  • Endpoints on api/2, with #[ApiRoute]:
    • GET /api/2/contexts/{contextId}/menu returns the menu as a flat list in display order, with parentId
    • POST /api/2/contexts/{contextId}/menu adds an item to the end: title, icon, description, target
    • PATCH /api/2/contexts/{contextId}/menu/{itemId} changes an item; a target replaces the previous one, a group that holds items can't get one, and the only item that opens the start page keeps that target
    • DELETE /api/2/contexts/{contextId}/menu/{itemId} deletes an item; the only item that opens the start page gets a 400
    • PUT /api/2/contexts/{contextId}/menu/order takes items: [{id, parentId}] in display order. It lists every item exactly once, a parent is a top-level group listed before its items, and it saves all of it or nothing ("changed in between, reload"). It returns the whole menu, and saves the order in one query.
  • Versions: GET /menu returns an ETag, and the order save needs it in If-Match. A stale version gives a 409, a missing If-Match a 400. Response bodies don't change.
  • Permissions: reading needs read access, changes need manage access, checked once through the item's application. Outsiders and items of another application get a 404, also when the item is reached through an application the user does manage, readers who try a change a 403, a target outside the application a 400. #[RequirePermission] covers every endpoint, and the service checks manage rights on the application for every write itself, so the route's check is not the only guard (the fixed node type for the route attribute is fix(middleware): let a route fix the node type to an application #3415). Readers who can't manage the application don't see items that open a table or view the application gives them no read permission on.
  • Titles, descriptions, icons and links go through the same shared helpers as pages and widgets (TextHelper for text and icons): blanks at either end, including no-break and zero width spaces, are trimmed. A menu link accepts the scheme in any case (HTTPS://…); link cells are unchanged.
  • Page messages change with the move of the checks into the shared helpers: A page has an unknown icon: X becomes The icon of a page must be the name of an icon., and A page description has at most 2000 characters. becomes The description of a page must be a text of at most 2000 characters. A page icon is trimmed by TextHelper::trim() instead of trim(), so an icon wrapped in no-break or zero width spaces is accepted.
  • Link cells and widget icons are not changed here; those two input fixes are fix: accept upper-case link schemes and trim widget icons #3416.
  • Rate limits with #[UserRateLimit]: 20 a minute on every menu write.
  • The app version goes to 3.0.0-dev.3 (main is at 3.0.0-dev.1, feat(pages): let widgets sit in the tabs of a tabs widget #3212 takes 3.0.0-dev.2).

How it was tested

After the reviews, including the review of 30 November, with PostgreSQL:

  • MenuServiceTest against the database: the start page item of a new application, title fallback for every kind of target, invalid items (data provider), at most one target, empty groups hidden from readers, the 200-item cap, PATCH semantics, a group with items can't get a target, order and grouping, deleting a group, invalid orders that save nothing (data provider), cleanup with the page, the node and the application, a dangling item left out, only managers change the menu (the four writes as a reader, data provider), an item not found through another application, the only start page item can't be deleted or pointed elsewhere and can be deleted when another item opens the start page, and a reader doesn't see items of a table or view with permissions 0
  • MenuControllerTest: arguments passed on and every error mapped to its status (data providers); a PermissionError is a 403 on every write, a BadRequestError a 400 on delete too
  • the full unit suite on this branch: 917 tests
  • psalm and php-cs-fixer, clean; OpenAPI regenerated and in step with the code

By hand on a test instance (Nextcloud 34, PostgreSQL), through the API, 18 checks, all as expected. These were done before the fixes of 30 November; the checks on a live instance below were done after them:

  • a new application has one item, for its start page; GET /api/2/menu is gone (404)
  • add a group, a link, the table (titled after it) and a page item whose title is only no-break and zero width spaces, which counts as no title; a target outside the application gives a 400
  • change an item, and put the link in the group with an order
  • an item changed or deleted through another application the user manages: 404
  • a reader reads the menu and gets a 403 on add and change; someone outside the application gets a 404
  • deleting the group moves its item to the top; deleting a page removes its item

How it was tested on a live instance

On Nextcloud 34 with PostgreSQL, with an owner, a reader and an outside user, through the API. A new application has one item, for its start page, and GET /menu returns an ETag. The only start page item cannot be deleted or pointed elsewhere (400); it can be renamed and moved into a group. With a second start page item either one can be deleted, and adding an item never brings a deleted one back, also in an application that has no items. A reader gets 403 on add, change, delete and order (with a fresh ETag), also with ?context=table and ?context=0 while owning a table with the application's id, and the menu stays the same; an outside user gets 404. Items on a table added with permissions 0, with and without a title, are shown to the owner; the reader sees neither item and not the table's title. HTTPS://nextcloud.com is accepted as a menu link, the 201st item is refused, and an order save without If-Match gives 400 and with a stale one 409. Link cells and widget icons behave as on main. In the browser the application opens on its start page for the owner and for the reader.

🖼️ Screenshots

Backend only, no UI changes.

🏁 Checklist

  • ⛑️ Tests (unit and/or integration) are included or not needed
  • 🔙 Backport requests are created or not needed: /backport to stableX.X
  • 📅 Milestone is set
  • 🌸 PR title is meaningful (if it should be in the changelog: is it meaningful to users?)

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@rubenvdlinde
rubenvdlinde added this pull request to stack #3139 October 22, 2026 11:42
@rubenvdlinde
rubenvdlinde force-pushed the feat/noid/app-menu-model branch from 9847aa9 to 5825db2 Compare October 22, 2026 13:25
@rubenvdlinde
rubenvdlinde force-pushed the feat/noid/app-menu-model branch from 5825db2 to 9e81a78 Compare October 23, 2026 08:05
@rubenvdlinde
rubenvdlinde force-pushed the feat/noid/app-menu-model branch 2 times, most recently from 7e236cc to c7a6e95 Compare October 26, 2026 09:24
@rubenvdlinde
rubenvdlinde marked this pull request as ready for review October 26, 2026 09:25
Comment thread lib/Db/ContextMapper.php Resolved
Comment thread lib/Service/ContextService.php Resolved
Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
@rubenvdlinde

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review. All of it is addressed, and the branch is rebased onto current main, with the conflicts resolved and OpenAPI regenerated.

  • Readers changing the menu: MenuService::create, update, delete and saveOrder now check canManageContext on the application themselves and throw PermissionError (403) when it fails, whatever the route attribute read from the request. testOnlyAManagerChangesTheMenu in MenuServiceTest runs all four writes as a reader through a data provider and checks that the menu is unchanged; MenuControllerTest checks the 403 mapping. Commit 4cd9616. The middleware fix is a separate PR, fix(middleware): let a route fix the node type to an application #3415: RequirePermission accepts type: 'context', which the request cannot override, and the existing application routes use it. Once that lands, the menu routes will move to it too.
  • Link cells and widget icons: both behaviour changes are out of this PR (13ea9d5). Link cells compare the scheme with case again and widget icons are no longer trimmed. They are now fix: accept upper-case link schemes and trim widget icons #3416, with their own tests.
  • Icon trimming: IconHelper::optional now trims through TextHelper::trim(), so no-break and zero-width spaces around a page or menu item icon are dropped, as the description says (7dfcfd4).
  • Page messages: these come from moving the checks into the shared helpers, so they stay. The description now lists them.
  • Description: I corrected the version (3.0.0-dev.3), the test list and the start-page behaviour, and added the checks on a live instance (Nextcloud 34, PostgreSQL), which replay your reproductions, ?context=table included.

cc @blizzz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants