Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updateLink versioned extension regression on dev/build #8110

Closed
2 tasks done
dhensby opened this issue May 30, 2018 · 1 comment
Closed
2 tasks done

updateLink versioned extension regression on dev/build #8110

dhensby opened this issue May 30, 2018 · 1 comment

Comments

@dhensby
Copy link
Contributor

dhensby commented May 30, 2018

Affected Version

3.x-dev

Description

When running a dev/build via the browser on an empty database (or specifically without any ErrorPage records when using the CMS module) the user is logged out and sent back to /Security/login?BackURL=%2Fpage-not-found%2F%3Fstage%3DStage

Expected behaviour: for dev/build to complete successfully.

I've narrowed this down to the following:

  1. DevelopmentAdmin::init() calls Versioned::reading_stage('Stage'); (
    // Backwards compat: Default to "draft" stage, which is important
    // for tasks like dev/build which call DataObject->requireDefaultRecords(),
    // but also for other administrative tasks which have assumptions about the default stage.
    Versioned::reading_stage('Stage');
    )
  2. VersionedStateExtension::updateLink() appends stage=Stage to links when the object was queried from the draft stage (
    public function updateLink(&$link)
    {
    // Skip if link already contains reading mode
    if ($this->hasVersionedQuery($link)) {
    return;
    }
    // Skip if current mode matches default mode
    // See LeftAndMain::init() for example of this being overridden.
    $readingMode = $this->getReadingmode();
    if ($readingMode === Versioned::get_default_reading_mode()) {
    return;
    }
    // Determine if query args are supported for the current mode
    $queryargs = VersionedReadingMode::toQueryString($readingMode);
    if (!$queryargs) {
    return;
    }
    // Decorate
    $link = Controller::join_links(
    $link,
    '?' . http_build_query($queryargs)
    );
    }
    ), this means switching stages after the object has been fetched (and possibly published) won't fix the problem and ?stage=Stage will still be appended to the URL.
  3. ErrorPage::requireDefaultRecords() uses Director::test() to "statically publish" the error pages it generates (https://github.com/silverstripe/silverstripe-cms/blob/12826b2ace76808d29b5017e1f445514b7fcf62a/code/model/ErrorPage.php#L116)
  4. VersionedRequestFilter::preRequest() takes outputting responses into it's own hands instead of returning a boolean response
  5. VersionedRequestFilter::preRequest() saves the dummy session from Director::test() which causes the current session to be invalidated and the user logged out

Steps to Reproduce

  1. Create a vanilla 3.x-dev site or delete the error pages from the CMS
  2. Go to dev/build in the browser

Potential fix

I've fixed this locally by wrapping the ErrorPage::requireDefaultRecords() logic in Versioned::reading_stage(Versioned::LIVE); which fixes the specific error, but I feel this only resolves part of the issue.

Another fix could be to strip the ?stage query param from $page->Link() in ErrorPage::requireDefaultRecords()


I've opened this against framework instead of CMS because most of the root issues are in framework and the PR to framework caused this regression

PRs:

@tractorcow
Copy link
Contributor

I've fixed this with the suggested adjustment, but also reset the "default" stage to draft in dev/build in order to prevent other links being generated with querystring args. This is the same approach we used in LeftAndMain to prevent stage args in the CMS.

tractorcow pushed a commit to open-sausages/silverstripe-framework that referenced this issue Jun 1, 2018
tractorcow pushed a commit to open-sausages/silverstripe-cms that referenced this issue Jun 4, 2018
tractorcow pushed a commit to open-sausages/silverstripe-framework that referenced this issue Jun 4, 2018
tractorcow pushed a commit to open-sausages/silverstripe-cms that referenced this issue Jun 4, 2018
tractorcow pushed a commit to open-sausages/silverstripe-framework that referenced this issue Jun 5, 2018
maxime-rainville pushed a commit to silverstripe/silverstripe-cms that referenced this issue Jun 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants