Thanks for this excellent module. Your effort is much appreciated . it accomplishes a missing feature of PBT

While trying this module I got fetal error

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 72 bytes) in /home/project/www/modules/permissions_by_entity/src/EventSubscriber/PermissionsByEntityKernelEventSubscriber.php on line 83

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ron.du created an issue. See original summary.

rackberg’s picture

Hello ron.du,

thank you very much for your great feedback. And thank you also for the bug report!

It seems that the fatal error occurs when permissions_by_entity tries to throw the AccessDeniedHttpException.
Currently I have not enough information to reproduce this issue on my local machine.

In order to help you with this issue I need a little bit more information about how the entity is configured you are trying to protect.
Which type of entity are you trying to protect?
Which php version do you use?

Helrunar’s picture

Status: Active » Postponed (maintainer needs more info)
ron.du’s picture

Status: Postponed (maintainer needs more info) » Active

It actually work with paragraphs types entities

But error occurs when I used it with node entity ( Like Normal PBT )

Php version : 5.5.12

apache 2.4

drupal : 8.3.2

Node type : article with a taxonomy field ( configured for PBT ) and PBE enabled

To reproduce the error :

step 1 : Clean drupal installation with PBT and PBE

step 2 : Taxonomy terms configured for PBT ( I created 2 term " free" for No restriction , "Paid" for registered user only

Step 3 : Add term reference to basic page .

Step 4 : Create a basic page and select " Paid " term which is restricted to registered user only

Step 5 : visit that page from another browser as anonymous user .

ron.du’s picture

Is there any update?

Thankyou

rackberg’s picture

Hey ron.du,

sorry for the long delay.

Yes we are able to reproduce the error you've described.

I was on vacation away from home the last week until today and could not work on this issue to fix it.

Now that I'm back, I will create a fix as soon as possible and inform you.

Thank you for your patience.

ron.du’s picture

Thanks Rackberg , I highly appreciate your effort . Seems I was going to ruin your vacation LOL. i am glad that you could reproduce the issue .

Also this module does not work for other entities like " Media Entity ".

As well as multiple entity referenced in same node also does not work . for example different paragraph type( restricted by terms) on same node does not work for restricted roles ( example anonymous user or any user who does not have permission to view that entity )

Regards
Ron

rackberg’s picture

Status: Active » Needs review
FileSize
2.14 KB

This patch should prevent circular calls that in the end caused the memory limit exhaustion.

I've added a simple "blacklist" that gets filled by access checking the entity and all of it's fields that contain a reference to other entities.
If a content entity has been checked, it will be added to the blacklist in order to avoid re-checking it. This should also increase the performance while loading a page.

Hope this patch solves the issue you found ron.du.

I would appreciate if the patch gets reviewed before I merge it into the current dev branch.

ron.du’s picture

Status: Needs review » Needs work

Thanks Rackberg. Unfortunately this page did not worked for me. Still PBE creating access denied loop for Node and lead to 500 error until allowed memory exhausted .

for multiple paragraphs type still has same error . Should i Open new issue for multiple paragraphs issue ?

EDITED WITH MORE INFO:

When permissions-by-entity module enabled then permissions-by-term module breaks as described earlier.

here is the apache error log

[Thu Jun 08 01:26:03.456428 2017] [fcgid:warn] [pid 3526] [client xxx:51063] mod_fcgid: stderr: PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /home/example.com/public_html/project/web/modules/contrib/permissions_by_entity/src/EventSubscriber/PermissionsByEntityKernelEventSubscriber.php on line 87

Drupal error messages in the screenshot

https://qsnapnet.com/snaps/xpel5bzqjhdgf1o

Thankyou

Regards
RON

rackberg’s picture

Hey Ron,

thank you for testing the patch.
Did the patch apply correctly to the current version you've installed of PBE or where there any conflicts trying to apply the patch?

Regards
Rackberg

rackberg’s picture

Status: Needs work » Needs review
FileSize
2.72 KB

Hi Ron,

I've created another patch.

I hope this solves your issue.
Waiting for feedback.

Thank you very much.

Regards
Rackberg

ron.du’s picture

Thanks Rackberg . yes patch applied correctly . I will test 2nd patch and will let you know soon

Regards
Ron

ron.du’s picture

Hello Rackberg I have applied latest patch through composer in a newly installed drupal. It did not fix the node access and memory issue.

Though last patch Improved Multiple type paragraphs access in a single node. I will create issue separately for this.

Back to current issue . To make sure i have installed fresh drupal again without any additionl module installed ( like paragraphs)

Step1 : fresh drupal with Permission_by_terms enabled . at this point node access with term work as expected.

Step 2 : enable Permissions_by_entity . Now node access broken . for restricted content non-allowed user see the 500 error and memory issue occured as previously mentioned error.

FYI : # current php version is 7.0 with fcgi .
# latest patch improved Multiple paragraphs type with term access to them . ( i will post detail issue for multiple parapgrphs as i guess these 2 issue might be different )

Regards
RON

rackberg’s picture

Hello Ron,

Doing some research I found out that the native php function in_array() I use can have troubles when used in nested recursive function calls.
Causing a "nesting level too deep" fatal error.

So this approach is to replace the in_array() function with a custom one.
Maybe this patch solves your problem?

Best,
Rackberg

  • rackberg committed 9ada225 on 2880568-fix
    Issue #2880568 by rackberg, ron.du: Fatal error
    

  • rackberg committed 2de3708 on 2880568-fatal-error-fix
    Issue #2880568 by rackberg, ron.du: Added checked entity cache.
    
rackberg’s picture

Hey Ron,

I am now using branches instead of patches to fix errors.

Please checkout Branch "2880568-fatal-error-fix". It would be again really nice if you check if this fixes the problem.

I've locally tested the fix using the informations you described at post #13.

Regards,
Rackberg

  • rackberg committed 2de3708 on 8.x-1.x
    Issue #2880568 by rackberg, ron.du: Added checked entity cache.
    
ron.du’s picture

Thanks Rackberg for you great work :) . I just tested with new branch and seems " permissions_by_term" for node working as expected without breaking it .

SO it works . Very soon I am going to test with paragraphs and other entities .

This is now should be mark as fixed .

Thank you again for your nice work . I hope lots of people will love this module

Regards
RON

ron.du’s picture

Status: Needs review » Reviewed & tested by the community
rackberg’s picture

Status: Reviewed & tested by the community » Fixed

Hey Ron,

I have to thank you, for waiting so long and testing my patches.

I've merged the fix into the dev release branch.

Hope to hear again from you soon.

Regards
Rackberg

rackberg’s picture

Status: Fixed » Closed (fixed)