Overview

If the user cannot edit config (asset library, code components) the preview does not render. That is because the preview gets those config from auto-save which requires `edit` permission. The GET routes should use `.view`.

Proposed resolution

Example of our fix

    $collection->get('experience_builder.api.config.auto-save.get.js')
      ?->setRequirement('_entity_access', 'xb_config_entity.view');
    $collection->get('experience_builder.api.config.auto-save.get.css')
      ?->setRequirement('_entity_access', 'xb_config_entity.view');

User interface changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mglaman created an issue. See original summary.

effulgentsia’s picture

"view" as the entity operation makes sense, but I think if we do that, we need to also make sure that the access handler uses a permission like "view unpublished" or "view latest version" (see Content Moderation for reference) if the entity is the one that's in auto-save.

mglaman’s picture

The problematic entities were config entities which don't support revisions. Not the actual entity being edited itself. I don't know if this effects regular conponen config for SDCs

mglaman’s picture

Issue tags: +Needs tests

Flagging for tests. There must be existing tests that have missing coverage.

wim leers’s picture

Title: Users with lesser permissions cannot preview a page » [PP-1] Only users with "edit" operation access to code components can see previews with auto-saved code components
Component: … to be triaged » Internal HTTP API
Status: Active » Postponed
Related issues: +#3500386: Code Components should render with their auto-saved state (if any) when rendered in the XB UI, +#3529924: Add access check for using Experience Builder at all: if >=1 content entity type with an XB field can be created or edited., +#3508694: Permissions for XB config entity types

This title is very misleading 😅😬


This was introduced in #3500386: Code Components should render with their auto-saved state (if any) when rendered in the XB UI.

So I went to investigate how we agreed this was supposed to work: when should code components load their auto-saved vs live CSS+JS code? 🕵️

I wrote ~4 months ago at #3500386-35: Code Components should render with their auto-saved state (if any) when rendered in the XB UI:

should not only only apply to that route, but also only to users who have sufficient permissions: if they lack the administer code components permission, they should not be able to see draft (auto-saved) states of edited code components.
I think that can become a third MR here.

Which @effulgentsia disagreed with at #3500386-38: Code Components should render with their auto-saved state (if any) when rendered in the XB UI:

I don't think that's correct. If they have permission to use the code component within XB's page builder (if we don't yet have granular permissions for this, this is currently the same as if they have permission to use XB's page builder at all), then they should see what their component instance looks like in their content, using the draft state of the JS and CSS.

The underline (added by me) is what #3529924: Add access check for using Experience Builder at all: if >=1 content entity type with an XB field can be created or edited. is about to land! 🥳

We then agreed at #3500386-39: Code Components should render with their auto-saved state (if any) when rendered in the XB UI to do this in #3508694: Permissions for XB config entity types, but we never did — or rather: in #3508694 we did change the route requirement for the routes discussed here like so:

  requirements:
    _permission: 'administer code components'
    _xb_http_eligible_config_entity: 'TRUE'
    _entity_access: 'xb_config_entity.edit'

So … once #3529924: Add access check for using Experience Builder at all: if >=1 content entity type with an XB field can be created or edited. lands, this should become trivial to support :)

lauriii’s picture

Priority: Normal » Critical
Issue tags: +beta blocker
wim leers’s picture

Pushed solution. Test coverage should be trivial to add in \Drupal\Tests\experience_builder\Functional\AssetLibraryAttachmentTest::test().

Note that the MR will fail until #3529924: Add access check for using Experience Builder at all: if >=1 content entity type with an XB field can be created or edited.'s lands.

wim leers’s picture

Title: [PP-1] Only users with "edit" operation access to code components can see previews with auto-saved code components » Only users with "edit" operation access to code components can see previews with auto-saved code components
Status: Postponed » Needs work
thoward216’s picture

Assigned: Unassigned » thoward216
wim leers’s picture

Assigned: thoward216 » wim leers
Status: Needs work » Needs review

Test-only CI job failed 👍

Reviewing in-depth…

wim leers’s picture

Assigned: wim leers » thoward216
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

See https://git.drupalcode.org/project/experience_builder/-/merge_requests/1... — now you can review to see if it all makes (hopefully MUCH) more sense? 🤞

  • wim leers committed 2e5c7a4c on 0.x
    Issue #3533461 by wim leers, thoward216, mglaman, effulgentsia: Only...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.