Closed (fixed)
Project:
Webform
Version:
8.x-5.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
30 Aug 2018 at 16:20 UTC
Updated:
3 Oct 2018 at 16:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
bucefal91 commented... Renaming the hook to its final name in the main description.
So here's the patch. It does:
WebformInterface::getAccessRulesInfo()which takes care of actually invoking the hooks, so whoever needs a clean shining set of$access_rulescan simply invoke that method.WebformEntitySettingsAccessFormso it becomes aware of additional access rules supplied through hook.$access_rulesa little more eager - because now we could receive a request like\Drupal::entityTypeManager()->getAccessControlHandler('webform')->access('my_new_access_rule_from_another_module');and the only way to resolve it is to consult the existing 'access' settings of a webform, i.e. to delegate it toWebform::checkAccessRules()WebformEntityAccessControlHandlerTest.I testify the following works:
TRUEorFALSEboth on Webform & WebformSubmission entity types. I.e.\Drupal::entityTypeManager()->getAccessControlHandler('webform')->access('my_new_access_rule_from_another_module');yieldsTRUEwhen it is supposed to per current access settings of the webform.. and so does\Drupal::entityTypeManager()->getAccessControlHandler('webform_submission')->access('my_new_access_rule_from_another_module');.As far as I can see, we are ready to commit this thing.
Comment #4
jrockowitz commentedThe static Webform::getAccessRulesInfo() feels awkard. Should the access rules related code even be in the Webform entity class?
Should all access rules related logic be moved to WebformEntityAccessControlHandler?
We would need to define a WebformEntityAccessControlHandlerInterface.
Or should we create a WebformEntityAccessRulesManager?
The WebformEntityAccessRulesManager could be injected into WebformEntityAccessControlHandler.
@bucefal91 What do you think? I am not able to find any similar patterns in core.
I am leaning toward a WebformEntityAccessRulesManager service.
Comment #5
bucefal91 commentedLet me first nail down the test failures (which I hope are nailed with this patch I am uploading). So I make sure it contains no bugs and then I'll get started with re-arranging the code so it looks&feels beautiful.
------------
I think WebformEntityAccessRulesManager service would be nice because both
WebformEntityAccessControlHandlerandWebformSubmissionAccessControlHandlerare using it, so packing it intoWebformEntityAccessControlHandlerwouldn't be appropriate (because it'd make submission access handler to "depend" on webform access handler).Ehm, then let me file another sub-task where I will introduce the rule manager. Then I'll return to this issue and will re-write the current patch to use the new rule manager. That way we'll keep the patches small
Comment #7
bucefal91 commentedLet's see this one.
Comment #9
bucefal91 commentedMy localhost tests timed out while running, so I guess I should leverage d.org CI infrastructure. I hope this time we are going to see 100% pass.
Jacob, I do not think it's worth the effort to review the patch yet for you as I am still going to introduce the access rule manager service and it will inevitably affect the patch from this issue. I'll ping you when I beleive I have all this stuff ready for your review :) Just don't want to disturb you away from your things.
Comment #11
bucefal91 commentedlet's see. I managed to introduce an infinite recursion with my last patch. :)
This one I am attaching is dirty, but I hope it does pass the tests. It's been a challenge for me... By fixing one test failure I introduce another and then it goes in circles. Since I am trying to amplify the access system it was a little bit difficult to amplify it without altering pre-existing behavior.
If this patch pass tests (which I hope it does), then I'll go to code the access rules manager. Once that one lands, I will rewrite this patch with heavy usage of the access rules manager and the "dirt" this patch contains will dissolve with smart use of access rules manager.
Comment #13
jrockowitz commentedI think this change is causing the problems because the 'test' operation is no longer being handled.
You might be tweaking too much in the WebformEntityAccessControlHandler.
Comment #14
bucefal91 commented"test" operation is part of the access rules, so it would be covered by this part of the condition
in_array($operation, $access_rules).I ran this failing test locally it and did pass. I see there were some recent commits related to "test_confirmation_none" webform (the spot where tests failed). Maybe it was just a case of bad luck.. when the tests started the commits landed and somehow interfered with normal test execution. Re-submitting for testing did get me green light.
Let me switch to the access rules manager now. I hope to have that one coded either today or tomorrow.
Comment #15
bucefal91 commentedActually since we've split the access logic between WebformEntityAccessControlHandler and WebformSubmissionAccessControlHandler, my latest patch here is obsolete. So it took me some time to analyze it and come up with a new one. I am attaching it to this comment.
If it passes tests, I believe it's ready for commit.
Comment #16
jrockowitz commentedOn /admin/structure/webform/manage/contact/access. I am getting the below error message
The array of test parameters in WebformEntityAccessControlHandlerTest ::providerCheckAccess should use a consistent formatting. Maybe all cache_contexts should be displayed on one line.
Comment #17
bucefal91 commentedHehe, the "say hi" was a dummy access rule that I introduced to be able to test the hook. I just forgot to remove it .
My local Drupal had disabled the error message for some reason, so I overlooked those warnings. I've fixed them in this patch + did the formatting for 'cache_contexts' array.
Comment #18
jrockowitz commentedThe last task is to write a change record where you can pretty much cut-n-paste the API documentation.
Comment #20
bucefal91 commentedI've put up the change record (in "draft" state) https://www.drupal.org/node/3000979 and committed the patch :)