Skip to content

fix(text): allow building the card context without a user - #8666

Open
Masad791 wants to merge 1 commit into
nextcloud:mainfrom
Masad791:fix/text-context-without-user
Open

Masad791 wants to merge 1 commit into
nextcloud:mainfrom
Masad791:fix/text-context-without-user

Conversation

@Masad791

Copy link
Copy Markdown

Summary

Text dispatches RegisterContextEvent on every request, including the sync and save requests of a public share session. To handle it, the container builds RegisterTextContextEventListener, which builds TextContextProviderFactory. On a public share nobody is logged in, so the container passes null for $userId. The string type then throws:

TextContextProviderFactory::__construct(): Argument #5 ($userId) must be of type string, null given

The request fails with HTTP 500, and the Markdown preview stays on the loading screen. This happens with any Markdown file opened through a public share, not just Deck cards, which is why disabling Deck makes it go away.

This PR makes $userId nullable in TextContextProviderFactory and TextContextProvider, the same way CardService and PermissionService already take it. Nothing changes for logged-in users. The provider passes $userId to PermissionService::checkPermission(), which treats null as the current user. For an anonymous request that still means no permission, so the change doesn't give anonymous users access to cards.

The new TextContextProviderFactoryTest builds the factory with a null user and builds a card context from it. Without the change, the test fails with the same TypeError. I couldn't run the PHPUnit suite here without a Nextcloud server checkout, so the test will first run in CI. The changed files pass php -l.

Checklist

  • Code is properly formatted
  • Sign-off message is added to all commits
  • Tests (unit, integration, api and/or acceptance) are included
  • Documentation (manuals or wiki) has been updated or is not required

🤖 AI (if applicable)

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

Text dispatches RegisterContextEvent on every request, including the
public share session sync/save requests. Building the listener for it
constructs TextContextProviderFactory, and the container passes null as
userId when nobody is logged in, so the string type threw a TypeError and
public Markdown previews failed with HTTP 500 while Deck was enabled.

Accept a null userId in the factory and the provider, like CardService and
PermissionService already do.

Fixes nextcloud#8633

Signed-off-by: Muhammad Asad <140322913+Masad791@users.noreply.github.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Public Markdown previews fail with HTTP 500 when Deck is enabled: null userId in TextContextProviderFactory

1 participant