Repository navigation
feat(contexts): give applications a menu with its own API - #3135
rubenvdlinde wants to merge 23 commits into
Conversation
9847aa9 to
5825db2
Compare
5825db2 to
9e81a78
Compare
7e236cc to
c7a6e95
Compare
| return null; | ||
| } | ||
|
|
||
| $table = $schema->createTable(self::TABLE); |
There was a problem hiding this comment.
Done. The proposal is on #3100 and blizzz has answered it. This PR is rebuilt on that proposal: one table, tables_contexts_menu_item, created by a single migration.
| $table->addColumn('icon', Types::STRING, ['notnull' => false, 'length' => 64]); | ||
| $table->addColumn('description', Types::TEXT, ['notnull' => false]); | ||
| $table->addColumn('target_type', Types::STRING, ['notnull' => true, 'length' => 16]); | ||
| $table->addColumn('target_id', Types::INTEGER, ['notnull' => false]); |
There was a problem hiding this comment.
Could menu items use node_rel_id, like widgets? Then removing a table can also remove its menu item
There was a problem hiding this comment.
Yes. A table or view item now points at its node_rel_id. When the table or view leaves the application, its items are removed in the same transaction as its widget sources.
| } | ||
|
|
||
| return $this->formatResultRows($r, $userId); | ||
| return $this->formatResultRows($r, $userId, $this->menuItemMapper->findByContextIds([$contextId])); |
There was a problem hiding this comment.
Permission checks use findById(), so each check now runs this menu query for no reason. Maybe should be conditional
There was a problem hiding this comment.
Thanks, that query is gone. The menu is no longer loaded with the application. It has its own endpoint, GET /api/2/menu?contextId=, so findById() and the permission checks don't touch it at all.
| // Deleting the application first takes the write lock before anything is read, so on | ||
| // SQLite a concurrent write fails this transaction at once and the retry runs it again. | ||
| $this->atomicRetry(function () use ($context): void { | ||
| $this->contextMapper->delete($context); | ||
| $this->shareService->deleteAllForContext($context); | ||
| $this->menuItemMapper->deleteAllByContextId($context->getId()); |
There was a problem hiding this comment.
should this be in a different PR?
There was a problem hiding this comment.
Yes. That change came out of this PR. All that's left in ContextService is what the menu needs: a new application gets one item for its start page, and deleting an application or one of its tables or views removes the items that open it.
c7a6e95 to
8574da7
Compare
9af2352 to
7d89fa5
Compare
7d89fa5 to
aa0c7e3
Compare
f8caaaa to
e311b8c
Compare
e311b8c to
7d1eec4
Compare
|
On the points from the review summary: #3211 and #3212 already use dev.1 and dev.2 and land before the menu, so the menu is now 2.5.0-dev.3 and its migration runs on instances that are on either of them. They're one helper now that takes the noun, used by pages, widgets and menu items, so the rule and the message live in one place. The chunk size is a cc @blizzz |
An application gets a menu of items. An item opens at most one thing: a
page of the application, a table or view of the application by its node
relation, or an http or https link. 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.
An item has no technical name of its own. A menu holds at most 200
items.
The menu has its own endpoints on api/2: GET /menu?contextId= returns the
menu as a flat list in display order, POST /menu adds an item to the
end, PATCH and DELETE /menu/{itemId} change or delete one item, and
PUT /menu/order saves the order and grouping of the whole menu in one
transaction. Reading needs read access to the application and changes
need manage access, checked once through the item's application.
Outsiders get a 404, readers who try a change a 403 and a target outside
the application a 400. Create is limited to 20 a minute per user, a
change or an order to 60.
Of the three target columns (page, node relation, link) at most one is
set, which the service enforces. Creating or changing an item checks its
target in the transaction that saves it. Empty groups stay in the menu;
readers without manage access don't see them.
A new application gets one item, without a title, for its start page.
An item goes when its target goes, in the same transaction: with its
page, when its table or view leaves the application or is deleted, and
with the application. The items of a deleted group move to the top
level. An item whose target is gone anyway is left out when the menu is
read. Applications that exist today have no items and open their start
page.
Co-authored-by: remko48 <remko@conduction.nl>
Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
- menu item titles and descriptions follow TextHelper, like pages and widgets, so one rule and one pair of limits covers all three - the migration step sorts after the steps of #2476 and of the grid pages stack - tests follow the page service, which no longer checks permissions itself Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
A menu item could be added to an application while it was deleted and stay behind, and the menu's rules were checked on reads another write could change. Creating, changing, deleting and ordering items now lock the application as their first statement, which on SQLite also takes the write lock first. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
Existing applications get the start page item from the migration, an imported application gets it with its pages, and an item added to a menu without any item comes after it. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
…one order An application loses its menu last, just before its own row, and both node removals delete widget sources, page contents, menu items and then the relation. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
…helper Pages, widgets and menu items name what a text belongs to and share the rule and the message. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
A menu link is parsed with parse_url(), needs a host and a scheme link cells allow, so internationalized domains, non-ASCII paths and hosts with an underscore work. Both compare the scheme without case. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
…controller The controller turns them into MenuTarget and MenuOrderEntry and answers 400 for a wrong shape, including an object where a list is expected, so the service only checks what depends on the application. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
GET, the order save and the item lookup use one rule, so an item whose table or view cannot be found is left out of all of them and a menu saved as GET returned it goes through. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
…ttributes The service no longer checks manage permissions a second time, loads the application once per request, and the order save answers from the items it saved. A controller test checks the permission attribute of every route. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
GET /menu sends the version of the order and grouping as ETag, and the order save takes it back as If-Match. The save compares it under the application lock, so a stale list gets 409 whatever changed in between, and the answer carries the new ETag. The response body keeps its shape. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
…checked create() and update() lock the node relation of their target right after the application, so a removal of that table or view either ends first and the item is refused, or waits and takes the item with it. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
…plication clearParent() filters on the application, so it uses its index, and it only runs when the deleted item is a group. The mapper chunks with a named constant. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
The order save runs one UPDATE for each item whose position or group changed, and nothing for an unchanged order. The redundant checks for updated fields are gone, as the mapper skips an unchanged entity itself. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
destroy() gets the limit the other writes have, and the order save and the item update go from 60 to 20 per minute. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
create() and update() take the TablesMenuTarget union the response uses,
so a typed client passes {pageId}, {nodeRelId} or {url} as it is. The
spec also gains the ETag and If-Match of the menu order and its 409.
Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
…or Psalm Psalm refused the menu and order responses because the ETag passed to the constructor typed the headers as required while the documented union makes them optional; the header is now added to the response. The node relation a menu item opens is read into a local before it is locked, so its type is an int. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
… the menu item mapper The test of a write to a page of an application that is gone built the page service without the menu item mapper it now takes, and checks that no menu item is touched either. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
7d1eec4 to
52f43fc
Compare
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: 3374 lines: 915 code, 434 tests, 2017 generated OpenAPI and 8 version.
Agreed on #3100
page_id,node_rel_id,url), of which at most one is set. The service enforces it; the rule is in the entity docblock./api/2/contexts/{contextId}/menu.What changes
{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.title(as stored) anddisplayTitle.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.#[ApiRoute]:GET /api/2/contexts/{contextId}/menureturns the menu as a flat list in display order, withparentIdPOST /api/2/contexts/{contextId}/menuadds an item to the end:title,icon,description,targetPATCH /api/2/contexts/{contextId}/menu/{itemId}changes an item; a target replaces the previous one, a group that holds items can't get oneDELETE /api/2/contexts/{contextId}/menu/{itemId}deletes an itemPUT /api/2/contexts/{contextId}/menu/ordertakesitems: [{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.GET /menureturns anETag, and the order save needs it inIf-Match. A stale version gives a 409, a missingIf-Matcha 400. Response bodies don't change.#[RequirePermission]covers every endpoint.TextHelperfor text): blanks at either end, including no-break and zero width spaces, are trimmed.#[UserRateLimit]: 20 a minute on every menu write.2.5.0-dev.3.How it was tested
After the reviews, on Nextcloud 34 with PostgreSQL:
MenuServiceTestagainst 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 (data provider), and an item not found through another applicationMenuControllerTest: arguments passed on and every error mapped to its status (data providers)php-cs-fixer, clean; OpenAPI regenerated and in step with the codeBy hand on a test instance (Nextcloud 34, PostgreSQL), through the API, 18 checks, all as expected:
GET /api/2/menuis gone (404)🖼️ Screenshots
Backend only, no UI changes.
🏁 Checklist
/backport to stableX.X🤖 AI (if applicable)