I experienced odd issues with content suddenly becoming un-viewable in the frontend. This content has a taxonomy term with permissions set against it, but for some reason these permissions were being cleared.

I tracked the issue down to saving a taxonomy term (not the one with the permissions assigned) - when doing this permissions_by_term_submit() updates associated node access with the permissions_by_term.node_access service.

The above service calls the NodeAccess class's rebuildByTid method. This method drops all node_access records associated with the term - but in the context of updating a term that is associated with a node but is not the term that determines permissions, all permissions are cleared but not rebuilt (as they're rebuilt in the context of the updated term, not the term providing permissions).

I have created a patch, which I will provide - the approach of the patch is to establish whether a) the term has any changed term permissions, or b) has existing term permissions, prior to updating the node access. If neither a or b is true, node access is not updated. This may not be the best approach but it works.

Comments

brynj created an issue. See original summary.

brynj’s picture

StatusFileSize
new1.95 KB

Do not use - contains debug info.

brynj’s picture

StatusFileSize
new1.93 KB
brynj’s picture

Status: Active » Needs review
brynj’s picture

Assigned: brynj » Unassigned
jepster_’s picture

Interesting. I will take a closer look on this issue asap.

brynj’s picture

Great, thanks. If you need any further information or clarification, just let me know.

I'm using this module in a large scale project, controlling lots of content types between 40 or so roles, and only discovered this issue quite late into development - because of its' relative obscurity.

jepster_’s picture

Status: Needs review » Postponed (maintainer needs more info)

Edited: yes, I could reproduce it. If you edit a related term, which has "no" permissions given, then just all related node access records are being dropped.

jepster_’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new3.36 KB

I have modified your code a bit. The main bug was, that if there was no permission granted by the currently edited taxonomy term, just all node access records for a specific node have been dropped. So I have modified NodeAccess::rebuildByTid() and shortened it. Because if there have been any permissions submitted by the taxonomy edit form, the term rebuild happened twice.

Your code has just checked, if NodeAccess::rebuildByTid() must be called. It has checked it also a bit too much. Looping the returned array from AccessStorage::saveTermPermissions() is enough to check if any term permissions changes happened.

Please check my patch and let me know if it is RTBC from your side.

jepster_’s picture

jepster_’s picture

StatusFileSize
new2.99 KB

Please check the updated patch.

jepster_’s picture

jepster_’s picture

StatusFileSize
new3.05 KB
brynj’s picture

Thanks Peter.

Yes, I was aware my rebuild checks might have been a bit overzealous - but given the original behaviour to always rebuild, I decided to play it safe by always rebuilding if permissions were present (whether changed or not), just in case of some edge case I might not be aware of. Good to know that's unnecessary.

I shall try your patch in the morning and report back.

brynj’s picture

I've reviewed your patch this morning, and I can confirm it works as intended in the context the reported issue. Thank you.

brynj’s picture

Status: Needs review » Fixed
jepster_’s picture

Thanks! I will publish an new patch version asap.

  • Peter Majmesku committed f6ea6a8 on 8.x-1.x
    Issue #2893811 by Peter Majmesku, brynj: Saving a term with no...
jepster_’s picture

Status: Fixed » Closed (fixed)

The fix is part of release 8.x-1.20. Thanks again for reporting and patch providing!

brynj’s picture

Glad to help, and thanks for the credit!