Problem/Motivation

When loading terms using TermStorage::loadParents()/getChildren()/getTree() it should be easier to ignore the current user's access.

Proposed resolution

Add an optional access check parameter to these methods.

Remaining tasks

None.

User interface changes

None.

API changes

Added optional param, default behavior unchanged.

Data model changes

None.

Comments

catch created an issue. See original summary.

17chances’s picture

Status: Active » Needs work
StatusFileSize
new2.73 KB

Initial patch

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

jonathanshaw’s picture

VocabularyStorage::getTopLevelTids() has the same issue.

kapilv’s picture

Status: Needs work » Needs review
StatusFileSize
new2.85 KB
new2.4 KB

Hear a Rerolled patch.

Status: Needs review » Needs work

The last submitted patch, 9: 2938848-9.patch, failed testing. View results

renatog’s picture

Please could you update this:
Determine usage of access check in the further storage queries.
To:
Determine the usage of "access check" in the further storage queries.

ayushmishra206’s picture

StatusFileSize
new611 bytes
new2.85 KB

Made the change suggested in #11. Please review.

kapilv’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 12: 2938848-12.patch, failed testing. View results

nikitagupta’s picture

Status: Needs work » Needs review
StatusFileSize
new2.67 KB
catch’s picture

Why not add an optional $access_check parameter to each method (defaulting to TRUE)? Adding the property means it will still be very easy for someone to get this wrong I think. We can add optional parameters to this class within the constraints of the bc policy, shouldn't be a big problem.

jonathanshaw’s picture

Status: Needs review » Needs work

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Updating tags. The issue summary is not complete and if this is a bug it will require test cases.

mohit_aghera’s picture

StatusFileSize
new2.58 KB
new6.46 KB

Based on comment from #16, adding optional $access_check parameter.
I've included the kernel test to validate whether taxonomy_term_access_check query tag is added or not.
I think based on that we can identify whether access_check is added.

I haven't included interdiff considering it is different approach altogether.

Let's see how it goes 🤞

mohit_aghera’s picture

Status: Needs work » Needs review

The last submitted patch, 22: 2938848-22-test-only.patch, failed testing. View results

jonathanshaw’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

#8 can be a follow-up.

jonathanshaw’s picture

jonathanshaw’s picture

alexpott’s picture

Version: 9.5.x-dev » 10.1.x-dev
Category: Bug report » Task
+++ b/core/modules/taxonomy/src/TermStorageInterface.php
@@ -39,11 +39,13 @@ public function updateTermHierarchy(EntityInterface $term);
-  public function loadParents($tid);
+  public function loadParents($tid, $access_check = TRUE);

@@ -63,11 +65,13 @@ public function loadAllParents($tid);
-  public function loadChildren($tid, $vid = NULL);
+  public function loadChildren($tid, $vid = NULL, $access_check = TRUE);

Given this is an API addition we can only really make this change in 10.1.x. We can do this under the 1 to 1 interface to implementation rule. However, storage classes are interesting because we know that alternate DB implementations often have to implement them. Therefore I think we should go for Symfony's method of doing this... which is to do this:

public function loadChildren($tid, $vid = NULL /**, bool $access_check = TRUE **/);

on the interface but then implement it on the concrete class. That way we can given alternate implementations time to change the signature in Drupal 10 before enforcing it in Drupal 11.

I also think this should be a task - I've checked the issue comments and I've not seen any reasoning for it being a bug.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

We might need to disable a PHPCS rule... see \Drupal\Core\Database\StatementInterface::fetchObject for an example of where we have done something similar.

smustgrave’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new1.54 KB
new6.74 KB

Addressed point in #28 and #29

smustgrave’s picture

longwave’s picture

Re #28 I looked into contrib, and found that config_terms will indeed be broken if we change this under the 1:1 rule: it provides an alternative storage that extends ConfigEntityStorage but that implements TermStorageInterface, see https://git.drupalcode.org/project/config_terms/-/blob/8.x-1.x/src/TermS...

However, with the commented out parameter, how will we notify config_terms that it needs to change in future to accommodate this? Can the debug classloader help us here?

catch’s picture

DebugClassloader does have some support for this:

  self::$annotatedParameters[$class][$method-                 >name][$parameterName] = sprintf('The "%%s::%s()" method will require a new     "%s$%s" argument in the next major version of its %s "%s", not defining it is   deprecated.', $method->name, $parameterType ? $parameterType.' ' : '',          $parameterName, interface_exists($class) ? 'interface' : 'parent class',        $method->class);

I can't find any documentation for it though, so we'd probably need to reverse engineer from a Symfony example.

longwave’s picture

Ah, I remember where I've seen this before: we explicitly skip this in deprecation-ignore.txt:

%The "Drupal\\[^"]+" method will require a new "[^"]+" argument in the next major version of its interface "Drupal\\[^"]+", not defining it is deprecated%
smustgrave’s picture

Sorry dropped the ball here. So is any changes needed to the latest patch?

larowlan’s picture

I think the next steps here @smustgrave is to confirm that the debug classloader reports this as a deprecation when running tests for config terms module.

If it doesn't we'll need to revisit why we have that entry in deprecation-ignore.txt

smustgrave’s picture

I will admit I'm not sure how to go about doing that..

Should it be moved to NW then?

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work

Per #36.

I'm not sure how to do that though unfortunately.

partdigital’s picture

I've run into this issue as well while working on the Access policy contrib module

My use case:
In access policy I can define different access rules that allow me to dynamically add conditions via `hook_query_TAG_alter`
I've created a Node access policy with an access rule called "Compare node tags with tags on current user (with depth)". This allows me to restrict content by ensuring the tags on the node either match the tags on the user or are a child of one of the tags on the user.

This works fine for restricting view access. However, it does not work when I attempt to limit what tags are available in the entity reference field on the node edit form. It triggers an infinite loop.

This is because, in order to restrict taxonomy terms, I also add an access policy for those terms. This also invokes hook_query_TAG_alter() but it also calls TermStorage::loadTree()which also calls hook_query_TAG_alter()

This is a contrib module so including a core patch with the contrib module is really not feasible.

So I'm left with a few options:

  • Either create a new EntityReferenceSelection plugin just for that field. (Not ideal)
  • Or decorate `TermStorage` with a new loadTreeBypassAccess() method. (Also not ideal).

It would be great to get this in.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.