Skip to content

fix(occ): make tables:add work - #3186

Draft
AndyScherzinger wants to merge 3 commits into
mainfrom
fix/occ-tables-add-user-id
Draft

AndyScherzinger wants to merge 3 commits into
mainfrom
fix/occ-tables-add-user-id

Conversation

@AndyScherzinger

Copy link
Copy Markdown
Member

occ tables:add has never worked. It fails on every invocation, and the three reasons stack on top of each other, so each commit here only becomes visible once the previous one is in place.

  1. The command passed the user id as the fourth argument to TableService::create(), where the signature has $description. The table was created with the user id as its description and with no owner, and preCheckUserId() then rejected the empty user.
  2. TableService::enhanceTable() is handed the user it enriches the table for, but asked the share, row, column and view services to resolve the user from the session instead. There is no session user on the command line, so getColumnsCount() threw an InternalError — which the surrounding catch (PermissionError) does not catch — and aborted the create. getColumnsCount() and getRowsCount() now take the same optional user id as the permission checks they delegate to; both still default to the session user, so nothing changes for existing callers.
  3. TableTemplateService::createColumn() returned null whenever there was no session user, so every template builder received a null column and died on the first getId() call. Template content is now created as the owner of the table it is applied to, which on the web is the session user anyway.

This is pre-existing on master, unrelated to any open pull request. It surfaced while reviewing the per-user archiving work, which is why it is split out here rather than carried along there.

Opened as a draft: it is a behaviour fix on paths the web UI also uses, so it deserves a maintainer's look at the widened getColumnsCount()/getRowsCount() signatures and at the template owner fallback before it goes in.

🖼️ Screenshots

🏚️ Before 🏡 After
Error occurred: PreCheck for userId failed, requested in OCA\Tables\Service\PermissionsService. the created table as JSON, with "ownership": "admin" and an empty "description"

Verified on a local Nextcloud instance: occ tables:add admin "…" with no template, with --template custom and with each of todo, members, weight, vacation-requests, customers and tutorial. All six templates now create their columns, rows and views.

🏁 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

The command handed the user id to create() as the fourth argument, which
is $description, so the table was created with the user id as its
description and with no owner at all. preCheckUserId() then rejected the
empty user, making every `occ tables:add` invocation fail.

Assisted-by: ClaudeCode:claude-opus-5
Signed-off-by: Andy Scherzinger <[email protected]>
enhanceTable() receives the user it enriches the table for, but asked the
share, row, column and view services to resolve the user from the session
instead. On the command line there is no session user, so counting the
columns threw an InternalError that escaped the PermissionError handler
and aborted the whole create.

getColumnsCount() and getRowsCount() gain an optional user id, matching
the permission checks they delegate to; both already defaulted to the
session user, so nothing changes for the existing callers.

Assisted-by: ClaudeCode:claude-opus-5
Signed-off-by: Andy Scherzinger <[email protected]>
createColumn() returned null whenever there was no session user, so from
the command line every template builder got a null column and died on the
first getId() call. The rows and views were created as the session user
for the same reason.

The owner of the table the template is applied to is the right actor, and
on the web it is the session user anyway, so the fallback only takes
effect where there is no session at all.

Assisted-by: ClaudeCode:claude-opus-5
Signed-off-by: Andy Scherzinger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants