Deprecate node_access_view_all_nodes(). Move its functionality in NodeAccessControlHandlerInterface

Created on 10 March 2019, over 6 years ago
Updated 20 March 2025, 4 months ago

Problem/Motivation

Part of 🌱 [META] Remove all usages of drupal_static() & drupal_static_reset() Active effort to remove drupal_static() & drupal_static_reset() from node_access_view_all_nodes().

Proposed resolution

  • Move node_access_view_all_nodes() functionality to a new method NodeAccessControlHandlerInterface::viewAllNodes().
  • Deprecate node_access_view_all_nodes().
  • The cache reset is achieved via the existing method EntityAccessControlHandlerInterface::resetCache().

Remaining tasks

None.

User interface changes

None.

API changes

  • New method NodeAccessControlHandlerInterface::viewAllNodes().
  • node_access_view_all_nodes() is deprecated.

Data model changes

None.

Release notes snippet

N/A

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component

node system

Created by

πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Test will fail until πŸ› ModuleHandler::resetImplementations should reset $this->invokeMap Active is fixed.

  • πŸ‡¦πŸ‡ΊAustralia acbramley
  • The Needs Review Queue Bot β†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • πŸ‡¦πŸ‡ΊAustralia acbramley
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Can the CR also be updated that drupal_static_reset() with the node_grant key is deprecated.

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Done

  • Status changed to RTBC 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    LGTM

  • πŸ‡¬πŸ‡§United Kingdom catch

    One comment on the MR.

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Converted to use a memory cache

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Think we missed the 11.2 boat can those be updated to 11.3, reviewed again and closed the rest of the threads as answered.

    If you are another contributor eager to jump in, please allow the previous poster(s) at least 48 hours to respond to feedback first, so they have the opportunity to finish what they started!

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thanks! All feedback appears to be addressed

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Adding issue credit.

    As per @acbramley, I'm concerned that the focus of this issue is about the use of drupal_static and not the node access API. I think it is great to refactor out usages of drupal static - but this needs to be done with an eye to the resulting API. We have the following node access related functions left in node.module and we should have a plan for them:

    • node_access_grants
    • node_access_view_all_nodes
    • node_access_needs_rebuild
    • node_access_rebuild
    • _node_access_rebuild_batch_operation
    • _node_access_rebuild_batch_finished

    Are there issues for the other methods? It feels as though they split down into two groups:

    • node_access_grants and node_access_view_all_nodes
    • The *rebuild* ones

    Are there existing issues? I think not looking at 🌱 [meta] Deprecate node.module functions Active .

    I think we need to agree the API shape before doing this issue and once we've done that we should focus the issues on doing that and as a by product remove drupal_static usage where we can.

    I think that converting node_access_grants and node_access_view_all_nodes to a single service makes sense. I also think the service should be marked as @internal because it is API glue and if you want to affect this API you sure be implementing the hooks and not doing anything to this service.

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Added πŸ“Œ Deprecate node access rebuild functions Active and updated πŸ“Œ Deprecate node_access_grants() and move its functionality to NodeAccessControlHandler Active

    I think node_access_grants could live on the service that this provides, maybe with a new method name as per the IS in that issue to more accurately describe what it does (and so it's not so confusing with hook_node_grants)

    What do you think @alexpott?

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    @acbramley yes I think this issue could create a service for both of these methods in node.module. I've been trying to think if any of the existing node access services could be locations and I think I agree with the earlier posts - a separate service is a good idea. I considered node.grant_storage but I think this is not about storage and the new service needs to be injected into that one. I also considered cache_context.user.node_grants - or maybe making a new service that is also a cache context but that felt overly complex to. Therefore a new service with two public methods for each function we're replacing and marked @internal because it is not meant to be extended - the extension points are the node grant hooks.

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    How's that?

    The other method should be moved in the other issue

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    @acbramley I think we should widen the scope to include the other function here. Doing it piecemeal results in a less complete API for no real gain.

  • πŸ‡¦πŸ‡ΊAustralia acbramley
  • πŸ‡¦πŸ‡ΊAustralia acbramley
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Deprecated node_access_grants as well and added the note to the @internal tag.

    I think a good next step would be to flesh out πŸ“Œ Deprecate node_access_grants() and move its functionality to NodeAccessControlHandler Active . The first step should probably be to remove all/most of the grants functions from NodeAccessControlHandler, especially the ones that just proxy to the grant storage service. Like there's no reason hasViewAllNodesGrant or NodeRequirements::runtime needs to call a function on the access control handler...

    I also found some interesting stuff like NodeHooks1::nodeAccess which implements hook_ENTITY_TYPE_access for its own entity type πŸ€·β€β™‚οΈ There's no wonder why barely anyone understands this system fully (including myself)

  • @alexpott opened merge request.
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    So after refactoring node_access_view_all_nodes() into \Drupal\node\NodeGrantDatabaseStorage::checkAll() - see https://git.drupalcode.org/project/drupal/-/merge_requests/12586 - I think this issue can return to it's original intent - because there is no real API change. And then we can use πŸ“Œ Deprecate node_access_grants() and move its functionality to NodeAccessControlHandler Active to decide how to deal with node_access_grants() as part of an issue that is completely API focussed.

    @acbramley sorry it is taken a while to see through the API trees here but I think that the new MR points to a better place :)

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    One thing that is "interesting" is that node_access_view_all_nodes() is documented to return a bool. ATM in 11.x it only does this if there are no hook_node_grants implementations. Otherwise it returns a 0 or 1 integer because that's what Drupal::entityTypeManager()->getAccessControlHandler('node')->checkAllGrants($account) returns. With the new MR it will always return a 0 or 1. Boo to us and our lax return types. I think we should do a separate issue and CR to change \Drupal\node\NodeAccessControlHandlerInterface::checkAllGrants() and \Drupal\node\NodeGrantDatabaseStorageInterface::checkAll() to return a bool as this is a TRUE / FALSE access check and an integer is confusing.

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Added some notes on both MRs, I don't really think I like either now lol

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    @acbramley I've responded to your points on the new MR.

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    I guess we need someone else to weigh in, I don't feel this is much cleaner than my MR but it's hard when this whole system is a bowl of spaghetti in the first place.

    I'd appreciate if you could add any notes to πŸ“Œ Deprecate node_access_grants() and move its functionality to NodeAccessControlHandler Active on what you'd like to achieve there too since we've flip flopped a couple of times.

  • πŸ‡ΊπŸ‡ΈUnited States xjm

    Node access subsystem maintainer here.

    I haven't had a chance to review the MR in detail yet (will try to do so soon) but I strongly, strongly advise against making any API or behavior changes in this issue. The functionality of this and all the procedural functions in the node access system has a lot of edgecase behaviors that are fiddly and changing them even slightly can break access control behavior on sites with complicated implementations. We don't only have to worry about individual contrib modules; we have to worry about sites with multiple access control modules, or custom code that implements custom access control and/or integrates multiple access control modules, which is very common.

    The refactoring and eventual deprecation of the whole API is much more feasible now that D7 is EOL, but for scope management's sake and for the sake of not having surprise behavior changes or access bypasses on some weird edgecase sites, none of it should happen in this issue. This issue should only deprecate and move the code so we can get it out of the .module file.

    Thanks!

  • πŸ‡ΊπŸ‡ΈUnited States xjm
  • πŸ‡ΊπŸ‡ΈUnited States xjm
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    This is back to just node_access_view_all_nodes

  • πŸ‡¬πŸ‡§United Kingdom catch

    Adding πŸ› Statically cache node access grants Needs work as related issue, don't think it's relevant to this issue but it would be relevant to further refactoring to try to get rid of the circular/semi-circular dependencies.

  • πŸ‡ΊπŸ‡ΈUnited States xjm

    Followups followups ➑️ πŸ˜‡

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    alexpott β†’ changed the visibility of the branch 3038908-viewAllNodes to hidden.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Updated issue summary reflect the approach.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    @xjm I think we have all the follow-ups in place already. I found an existing issue for the return types - πŸ“Œ Change the return type of NodeGrantDatabaseStorageInterface::checkAll() and NodeAccessControlHandler::checkAllGrants() to a bool Active and the deprecation / moving about of node.module code has plenty of issues πŸ“Œ Deprecate node_access_grants() and move its functionality to NodeAccessControlHandler Active and 🌱 [meta] Deprecate node.module functions Active for example. Is there something else we need to put in place?

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Rebased, fixed a minor issue in the deprecation message and updated the CR a bit. I think this is good to go now. Agree that the follow ups we have in #63 cover plenty.

    The main API change is going from returning TRUE when there are no grant hook implementations to returning 1 (to match the return signature of checkAll). That will then change in 2863737 so I think that's fine for now. The deprecated function still returns what it used to.

    Leaving in NR since this is tagged for subsystem maintainer review which is not me.

  • The Needs Review Queue Bot β†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Rebased again.

  • πŸ‡ΊπŸ‡ΈUnited States xjm

    Re:

    Leaving in NR since this is tagged for subsystem maintainer review which is not me.

    If it's blocked on subsystem maintainers for an extended period in general it can also be escalated to framework managers, although in this case since a subsytem maintainer is also a release manager someone RTBCing it with the tag on is fine as well. Meanwhile though I'm also going to ping the other active maintainer for the subsystem since I still don't have time to look at this this week.

  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    From the node_access subsystem perspective, this seems fine.

    From a module developer perspective, it's also fine, as I consider node_access_view_all_nodes() to be an internal function and don't call it directly. Even if I did, there is an OO replacement I can use, and this code directs me to that.

  • πŸ‡ΊπŸ‡ΈUnited States xjm

    Untagging from #70; thanks Ken!

  • πŸ‡ΊπŸ‡ΈUnited States xjm

    Oh, belatedly confirming #63 -- @alexpott and I already discussed that in Slack last week but it looks like our consensus that the followups are covered did not make it back onto the issue. Thanks!

  • πŸ‡ΊπŸ‡ΈUnited States xjm

    And updated credits.

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Great, this is RTBC then

Production build 0.71.5 2024