Use the default \Drupal\Core\Entity\EntityAccessControlHandler for the JavaScriptComponent, AssetLibrary and PageRegion config entity types, aka all XB config entity types that do not need to be available to all XB users.
So that's basically just:
diff --git a/src/Entity/PageRegion.php b/src/Entity/PageRegion.php
index e384258ed..773f4d2ee 100644
--- a/src/Entity/PageRegion.php
+++ b/src/Entity/PageRegion.php
@@ -23,7 +23,7 @@ use Drupal\experience_builder\Plugin\Field\FieldType\ComponentTreeItemInstantiat
* label_singular = @Translation("page region"),
* label_plural = @Translation("page region"),
* label_collection = @Translation("Page region"),
- * admin_permission = "access administration pages",
+ * admin_permission = "administer page template",
* entity_keys = {
* "id" = "id",
* "status" = "status",
diff --git a/src/Entity/Pattern.php b/src/Entity/Pattern.php
index 12e61d717..fb23d7895 100644
--- a/src/Entity/Pattern.php
+++ b/src/Entity/Pattern.php
@@ -22,7 +22,7 @@ use Drupal\experience_builder\Plugin\Field\FieldType\ComponentTreeItemInstantiat
* label_singular = @Translation("pattern"),
* label_plural = @Translation("patterns"),
* label_collection = @Translation("Patterns"),
- * admin_permission = "access administration pages",
+ * admin_permission = "administer patterns",
* entity_keys = {
* "id" = "id",
* "label" = "label",
Comments
Comment #2
wim leersWithout this, we need to grant anonymous users the
administer code componentspermission for them to be visible 😅Comment #3
penyaskitoComment #5
wim leersSolid start, thanks! Posted a first round of feedback 😊
Comment #6
penyaskitoJS Components is mostly ready. Would love another review before starting with asset libraries as they should be basically the same.
Comment #7
wim leersVery much on the right track! 🤩 Lots of suggestions, but loving where this is going! 👏🙏
Comment #8
penyaskitoI need to check cypress failures (if I get to run them...) but phpunit is passing and this is ready for another round of reviews.
Comment #9
tedbowupdated the summary based on @lauriii comment https://git.drupalcode.org/project/experience_builder/-/merge_requests/7...
I assumed a single permission for both asset libraries and code components but asked for clarification here https://git.drupalcode.org/project/experience_builder/-/merge_requests/7...
Comment #10
tedbowComment #11
penyaskitoComment #12
wim leersThanks for the clarifications, @lauriii and @tedbow! 🙏👍
I made a few further clarifications — do you agree?
Comment #13
wim leersI'm terribly sorry, @penyaskito, but turns out that pretty much everything you've done on this issue/MR turns out to be unnecessary now that @lauriii has provided precise product requirements 🫣😅
But … I'm pretty sure this issue has helped @lauriii arrive at those clear conclusions!
AFAICT given the refined product requirements for XB permissions (see the new meta: #3452581: [META] XB Permissions) means that this issue can just:
\Drupal\Core\Entity\EntityAccessControlHandlerfor theComponentandPatternconfig entity types, aka all XB config entity types that provide the basic building blocks for the XB UI. These must respect theadmin_permission, except that viewing must always be allowed.For now, simply require the user to be authenticated (i.e. vary by the
user.roles:authenticated) cache context).\Drupal\Core\Entity\EntityAccessControlHandlerfor theJavaScriptComponent,AssetLibraryandPageRegionconfig entity types, aka all XB config entity types that do not need to be available to all XB users.So that's basically just:
testCannotDeleteWhenThereAreDependents()work also remains relevant.Comment #14
wim leers@lauriii to confirm
Impact: there is one more permission, which would be required to access the
/admin/structure/component/statusUI. Please either confirm you agree, or propose an alternative.Impact: without this relaxation, the
administer patternsandadminister componentspermissions would be required for a regular Content Creator to be able to use XB at all.In fact, it could be implemented more simply still:
route requirement to the
experience_builder.api.config.listroute.Comment #15
wim leersComment #16
wim leersComment #17
wim leersComment #18
lauriiiThis seems too granular for now. Could we use
administer themespermission for this? It might make sense to even move this under "Appearance" but that's off-topic for this issue 🤔Seems fine to allow viewing these to be tied to whatever parent context (e.g.,
access content).Comment #19
wim leersSure, that's fine.
@lauriii to confirm
That's a trivial move: instead of being listed at
/admin/structure, add 2 new tabs at/admin/appearance. It'd also allow us to clean up the long obsolete UI label.Impact:
(Patch that implements this attached.)
There is no parent context when using the XB UI and fetching the list of
ComponentandPatternconfig entities. The XB UI just fetches them regardless of which thing you're editing, no matter if it's aPageorNodecontent entity, or aContentTypeTemplateconfig entity (once #3455629: [PP-1] [META] 7. Content Templates — aka "default layouts" — affects the tree+props data model is implemented).Impact: Either:
ComponentandPatternconfig entities are retrieved context-free from the server to populate the choices available in the client.ComponentandPatternconfig entitiesThis means that for now, it's oddly using different access checks to fetch the same data, but in the future it'd make it trivial to add context-aware (specifically, component tree host-aware) filtering logic.
Note too that this would cause worse front-end performance.
IMHO the context-free choice is the simplest, sanest choice for now.
Comment #20
lauriiiCould we add a new tab called "Components" and then add the two tabs under it?
Let's implement this based on the context-free proposal for now. We can add more complex permissions to the components later.
Comment #21
wim leers#20: ACK, context-free it is 👍 That means you've +1'd the
_user_is_logged_inproposal.Sure! :)
Comment #22
penyaskitoCreated #3516609: Move components listing to Appearance for #19, confirmed in #20.
Comment #23
wim leersThat works too :)
Comment #24
penyaskitoReady for another round of reviews.
Comment #25
wim leersManaged to do a partial review, will review the rest later today :)
Comment #26
penyaskitoComment #27
effulgentsia commentedComment #28
wim leersLooking great! 😄 I think we're in the final stretch here now :)
Comment #29
wim leersComment #30
wim leersTantalizingly close! 😄
Comment #32
penyaskitoGranting credit to @larowlan for previous reviews now that I can.
NR again, maybe last time? 😁
Comment #33
wim leersLooking great now! 😄 But … all PHPUnit CI jobs were failing. It seems to have been a CI infra issue with the DB. Rerunning those CI jobs, feel free to merge if they pass :)
(Please merge using the d.o "merge" button, not the GitLab one. That ensures the proper commit message is applied.)
Comment #34
penyaskitoNeeds review for https://git.drupalcode.org/project/experience_builder/-/merge_requests/7....
I'm pretty sure that's a good fix, but want to be sure that we aren't just hiding another issue, as might be related to #3517031: ComponentTreeHydrated prevents serialization.
Assigning to larowlan for that.
The trace of the test failure was:
The normalization is trying to load the anonymous user from the db, and the users table doesn't exist.
Comment #35
penyaskitoBack to RTBC then 🎉
Comment #37
wim leersThis unblocked #3516648: Update `ExperienceBuilderController` to pass current user's XB high-level permissions to the client!
Comment #38
nagwani commentedComment #39
larowlanFollow up #3519168: Handle components provided by ComponentSources EXPLICITLY disappearing — enables deleting JS components that are in use