Issue Bug Closed

#103611Use WorkspaceRestriction in BackendUtility only if workspace is loaded

Sven Wappler 04/11/24, 15:28 updated 07/31/24, 09:18

Description

The function getRecordLocalization throws an error, because WorkspaceRestriction:class is called, even workspace module isn’t loaded. Please add a check before.

            $queryBuilder->getRestrictions()
                ->removeAll()
                ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
                ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, static::getBackendUserAuthentication()->workspace));

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 2

  1. Garvin Hicking commented and changed status New Needs Feedback 07/12/24, 08:04

    Hi Sven,

    for reference, this has also been discussed on Slack:

    https://typo3.slack.com/archives/C025BQLFA/p1720711083726809
    https://typo3.slack.com/archives/C025BQLFA/p1720713925738489
    https://typo3.slack.com/archives/C025BQLFA/p1720705380157669

    It seems that getRecordLocalization runs into this error is called from a context where a valid BE_USER object is missing.

    Could you tell in which case you get the error specifically, ideally a stacktrace?

    If it’s done within CLI Context, please ensure to create/initialize the BE_USER before using functionality that accesses getRecordLocalization (i.e. if you use the DataHandler).

    In “normal” backend context, the Backend Bootstrap should already take care of initializing the BE_USER. If you get the error there, could you tell in which case this happens?

    Now for the most problematic use case: If you use this method in the Frontend (FE) context, this is behaviour the Core does not want to promote. So while the Workspace-Restriction could be gated with a check here, possible future other side errors can easily happen, because you would using BE functionality in a context that is not meant for it. In FE context, retrieval of records should probably better be done with custom QueryBuilder methods, or the PageRepository or Extbase models or the Core might need to create a new interface for this (i.e. via ContentBlocks, if you’re accessing tt_content data). But also for that use case, maybe we could discuss the goals here to see what is the best route to take.

    TL;DR: Just adding a check on “is the workspace extension installed” would hide a symptom, but not the root cause of a problematic utilization of BE methods.

    Thanks for your time!

  2. Garvin Hicking commented and changed category status Needs Feedback Closed 07/31/24, 09:18

    Closing for now due to lack of feedback. Feel free to get in touch if we can elaborate more on this!