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

EZP-29144: Make websiteToolbarAction's Response cacheable #152

Merged

Conversation

jacek-foremski
Copy link
Contributor

JIRA issue: EZP-29144

Currently, the cache related to Website Toolbar doesn't take into the account if someone is an owner of the viewed Content Object. This means that if someone who doesn't have content/edit permissions access views this Content Object first, then the owner won't have an option to edit that Content Object using Website Toolbar.

The following PR: ezsystems/DemoBundle#194 fixes the issue in the Symfony stack by loading the Website Toolbar using ESI, so that it won't be cached alongside the rest of the page content ("Vary: X-User-Hash" is used there, which is wrong when we need to deal with Owner ( Self ) Policy Limitation).

This PR makes websiteToolbarAction's Response cacheable with "Vary: Cookie". I used the content cache parameters to determine the headers.

Copy link
Collaborator

@emodric emodric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than one comment, looks good.

{
$request = $this->getRequest();
$response = new Response();
if ($this->getParameter('content.view_cache') === true) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be injected through constructor instead fetching them through container?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is better. Fixed, thanks.

Copy link
Contributor

@andrerom andrerom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

besides comment/question, looks good.

// response as it can depend on user role for instance. X-User-Hash cannot
// be used since the website toolbar can have Owner( Self ) Policy Limitation.
if ($request->headers->has('Cookie')) {
$response->setVary('Cookie');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering if we should always set this even if there are no cookie, as otherwise the non varying cache will be set in varnish and used also by requests with cookies afaik.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check that to be sure and change it if needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On further taught: In practice it provably won't happen if eZ puts vary by user hash in request as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrerom from my tests it looks like eZ indeed puts vary by user hash in the request. But otherwise, vary by cookie would be needed. So I'll change that fragment to always set it, just to be on the safe side.

@@ -67,7 +82,7 @@ public function __construct(
*/
public function websiteToolbarAction($locationId, Request $request)
{
$response = new Response();
$response = $this->buildResponse();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we already have request as argument, maybe pass it on as argument is cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need request in buildResponse method anymore, so I'm just going to remove that.

Copy link
Contributor

@andrerom andrerom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 besides nitpick on DI

@andrerom andrerom merged commit ef6e9c8 into ezsystems:1.4 Jul 6, 2018
@jacek-foremski jacek-foremski deleted the EZP-29144_website_toolbar_cache_fix branch July 6, 2018 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants