Reset to alphabetical button is visible if users have access to edit all terms in a vocabulary, however reset route access is determined by whether the user has administer taxonomy.

This means users without administer taxonomy can see the button, but they receive access denied when clicked.

Problem (cause)

  • Reset route uses administer taxonomy permission. (See \Drupal\taxonomy\Entity\Routing\VocabularyRouteProvider::getResetPageRoute)
  • Button visibility on is determined by checking $term->access('update') on all terms. (See $change_weight_access)

Proposed solution

  1. Create a reset-all-weights operation for vocabularies.
  2. Check administer taxonomy before checking all terms.
  3. Move all existing $change_weight_access logic to operation access
  4. Change reset route permission to use _entity_access: 'vocabulary.reset-all-weights'
  5. Check vocabulary access before showing button.

Related concerns were raised in #1848686: Add a dedicated permission to access the term overview page (without 'administer taxonomy' permission)

CommentFileSizeAuthor
#93 2904504-77-93-interdiff.txt2.05 KBboromino
#93 2984504-93.patch6.33 KBboromino
#92 2984504-77-92-interdiff.txt1.64 KBboromino
#92 2984504-92.patch6.75 KBboromino
#81 afterpatch.jpg53.38 KBgaurav-mathur
#81 beforepatch.jpg12.67 KBgaurav-mathur
#80 After--patch-2984504-77.png214.66 KBManibharathi E R
#80 Before-Patch-2984504-77.png129.43 KBManibharathi E R
#77 2984504-72-77-interdiff.txt1.05 KBdarvanen
#77 2984504-77.patch6.99 KBdarvanen
#72 interdiff-55-72.txt1.19 KBdarvanen
#72 interdiff-70-72.txt800 bytesdarvanen
#72 2984504-72.patch7.08 KBdarvanen
#70 interdiff-55-70.txt1.17 KBdarvanen
#70 2984504-70.patch7.07 KBdarvanen
#64 2984504-55.patch6.97 KBdarvanen
#61 interdiff_55-61.txt638 bytesravi.shankar
#61 2984504-61.patch7.13 KBravi.shankar
#59 After Patch.png78.96 KBprasanth_kp
#59 Before.png38.23 KBprasanth_kp
#55 2984504-55.patch6.97 KBlpeidro
#55 2984504-55-tests-only.patch3.09 KBlpeidro
#54 2984504-54-tests-only.patch3.09 KBlpeidro
#54 2984504-54.patch6.97 KBlpeidro
#53 2984504-53-tests-only.patch3.09 KBlpeidro
#53 2984504-53.patch6.97 KBlpeidro
#52 2984504-52-tests-only.patch3.07 KBlpeidro
#52 2984504-52.patch6.89 KBlpeidro
#50 Captura de tela de 2022-03-21 12-14-04.png70.76 KBJohnny Santos
#50 Captura de tela de 2022-03-21 12-13-19.png79.05 KBJohnny Santos
#46 2984504-46.patch6.26 KBandregp
#46 2984504-46-tests-only.patch2.24 KBandregp
#46 interdiff_2984504_41-46.txt2.42 KBandregp
#41 2984504-41.patch7.7 KBidebr
#41 2984504-41-test-only.patch2.24 KBidebr
#41 interdiff-37-41.txt2.08 KBidebr
#37 2984504-37.patch8.28 KBidebr
#37 2984504-37-test-only.patch2.24 KBidebr
#37 interdiff-35-37.txt832 bytesidebr
#35 interdiff-2984504-28-35.txt2.12 KBmohit_aghera
#35 updated_files-2984504-35.patch8.29 KBmohit_aghera
#28 interdiff_23_28.txt2.71 KBanmolgoyal74
#28 updated_files-2984504-28.patch8.71 KBanmolgoyal74
#23 interdiff_22-23.txt2.55 KBmeghasharma
#23 updated_files-2984504-23.patch10.64 KBmeghasharma
#22 interdiff_20-22.txt4.64 KBsarvjeetsingh
#22 2984504-22.patch8.75 KBsarvjeetsingh
#20 2984504-20.patch8.96 KBayushmishra206
#11 2984504-11.patch8.62 KBidebr
#11 2984504-11-test-only.patch2.25 KBidebr
#11 interdiff-8-11.txt559 bytesidebr
#8 2984504-8.patch8.32 KBidebr
#8 2984504-8-test-only.patch2.25 KBidebr

Comments

dpi created an issue. See original summary.

dpi’s picture

Issue summary: View changes

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.

extexan’s picture

+1

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.

rosk0’s picture

Real issue, proposed solutions seams reasonable, would love to see this implemented.

idebr’s picture

idebr’s picture

Status: Active » Needs review
StatusFileSize
new2.25 KB
new8.32 KB

Attached patch implements a 'reset all weights' operation on the \Drupal\taxonomy\VocabularyAccessControlHandler::checkAccess() method and applies it to the Term overview form.

The last submitted patch, 8: 2984504-8-test-only.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 8: 2984504-8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

idebr’s picture

Status: Needs work » Needs review
StatusFileSize
new559 bytes
new2.25 KB
new8.62 KB

Fixed Drupal code style.

The last submitted patch, 11: 2984504-11-test-only.patch, failed testing. View results

tim-diels’s picture

This works for me. Good job!

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.

craigperks’s picture

This works for me also. Thank you!

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.

intrafusion’s picture

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

Patch applied without issue to 8.9.x and fixes the issue, do 3 reviews over 9 months count as reviewed?

Also as I believe this is a non-disruptive bug fix, this can be applied to all active versions.

dpi’s picture

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

9.1 is the target version, with optional backports.

jeroent’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
ayushmishra206’s picture

Status: Needs work » Needs review
StatusFileSize
new8.96 KB

Rerolled the patch for 9.1. Please review.

Status: Needs review » Needs work

The last submitted patch, 20: 2984504-20.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

sarvjeetsingh’s picture

Status: Needs work » Needs review
StatusFileSize
new8.75 KB
new4.64 KB

updated patch with fixed undefined variable error and coding standard errors.
please review.

meghasharma’s picture

StatusFileSize
new10.64 KB
new2.55 KB

I have reviewed the attached #22patch, Here are the results:
* Patch applied cleanly without any issues.
* After applying the patch,
saw some more coding standard errors in updated files

drupal_core % vendor/squizlabs/php_codesniffer/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml core/modules/taxonomy/src/Entity/Routing/VocabularyRouteProvider.php

FILE: /sample/drupal_core/core/modules/taxonomy/src/Entity/Routing/VocabularyRouteProvider.php
--------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------------------
 9 | ERROR | [x] Missing class doc comment
--------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------------------
Time: 166ms; Memory: 8MB

drupal_core % vendor/squizlabs/php_codesniffer/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml core/modules/taxonomy/src/Form/OverviewTerms.php

FILE: /sample/drupal_core/core/modules/taxonomy/src/Form/OverviewTerms.php
------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
------------------------------------------------------------------------------------------------
 535 | WARNING | Line exceeds 80 characters; contains 90 characters
 540 | WARNING | Line exceeds 80 characters; contains 96 characters
------------------------------------------------------------------------------------------------

Time: 123ms; Memory: 12MB

drupal_core % vendor/squizlabs/php_codesniffer/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml core/modules/taxonomy/tests/src/Functional/VocabularyPermissionsTest.php

FILE: /sample/drupal_core/core/modules/taxonomy/tests/src/Functional/VocabularyPermissionsTest.php
------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
------------------------------------------------------------------------------------------------------------------------
 26 | ERROR   | [x] Missing function doc comment
 39 | WARNING | [x] There must be no blank line following an inline comment
------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------

Time: 97ms; Memory: 10MB

updated patch with fixed above coding standard errors.
please review.

kapilv’s picture

Issue tags: -Needs reroll
jeroent’s picture

Status: Needs review » Reviewed & tested by the community

Patch #23 is working for me.

quietone’s picture

Status: Reviewed & tested by the community » Needs work

@meghasharma, Welcome to Drupal! Thank you for running phpcs and checking the coding standards. However, this issue isn't about fixing coding standards in the modified files and having those changes in the patch become noise and make it harder to review the patch.

  1. +++ b/core/modules/taxonomy/src/Entity/Routing/VocabularyRouteProvider.php
    @@ -6,6 +6,9 @@
    +/**
    + * HTML routes for entities.
    + */
    

    Out of scope.

  2. +++ b/core/modules/taxonomy/src/Form/OverviewTerms.php
    @@ -536,12 +532,14 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
    -        // Give terms at the root level a weight in sequence with terms on previous pages.
    +        // Give terms at the root level a weight in sequence with terms
    +        // on previous pages.
    ...
    -        // Terms not at the root level can safely start from 0 because they're all on this page.
    +        // Terms not at the root level can safely start from 0 because they're
    +        // all on this page.
    

    Also out of scope

  3. +++ b/core/modules/taxonomy/tests/src/Functional/VocabularyPermissionsTest.php
    @@ -23,6 +23,9 @@ class VocabularyPermissionsTest extends TaxonomyTestBase {
    +  /**
    +   * {@inheritdoc}
    +   */
    

    Out of scope

  4. +++ b/core/modules/taxonomy/tests/src/Functional/VocabularyPermissionsTest.php
    @@ -37,7 +40,6 @@ protected function setUp(): void {
    -
    

    Out of scope

+++ b/core/modules/taxonomy/tests/src/Functional/VocabularyPermissionsTest.php
@@ -142,6 +143,8 @@ public function testTaxonomyVocabularyOverviewPermissions() {
+    $this->drupalPostForm(NULL, [], 'Reset to alphabetical');
+    $assert_session->statusCodeEquals(200);

So here the the the list gets reset to alphabetical. That proves the button is there but how do we know that the data has actually been reordered? Where is the test for that?

jeroent’s picture

anmolgoyal74’s picture

Status: Needs work » Needs review
StatusFileSize
new8.71 KB
new2.71 KB

Removed the out of scope changes mentioned in #26

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.

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.

kim.pepper’s picture

Issue tags: +#pnx-sprint
darvanen’s picture

Status: Needs review » Needs work

The rerolls since #11 have muddled up the logic somewhat, likely because of underlying changes to the form that git/patch couldn't sort out by itself. Here's what I can see at the moment:

  1. +++ b/core/modules/taxonomy/src/Form/OverviewTerms.php
    @@ -314,7 +312,7 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular
    -    if ($create_access->isAllowed()) {
    +    if (!empty($pending_term_ids) || $vocabulary_hierarchy === VocabularyInterface::HIERARCHY_MULTIPLE) {
    

    This is the wrong check to replace with this logic. It's determining whether the "add term" link should be shown so it should be checking create access.

  2. +++ b/core/modules/taxonomy/src/Form/OverviewTerms.php
    @@ -326,13 +324,13 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular
    +        'weight' => empty($pending_term_ids) && $vocabulary_hierarchy !== VocabularyInterface::HIERARCHY_MULTIPLE ? $this->t('Weight') : NULL,
    

    This is the second place this logic exists (it's functionally the same as line 316). Turn this into a variable if the need to use it mutliple times remains.

  3. +++ b/core/modules/taxonomy/src/Form/OverviewTerms.php
    @@ -326,13 +324,13 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular
    -    $this->renderer->addCacheableDependency($form['terms'], $create_access);
    

    This will need to be reinstated because of point 1.

darvanen’s picture

Issue tags: +Bug Smash Initiative

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.

mohit_aghera’s picture

Status: Needs work » Needs review
StatusFileSize
new8.29 KB
new2.12 KB

Updating the comments based on feedback in #32
Test cases are passing on local as well.

Status: Needs review » Needs work

The last submitted patch, 35: updated_files-2984504-35.patch, failed testing. View results

idebr’s picture

Status: Needs work » Needs review
StatusFileSize
new832 bytes
new2.24 KB
new8.28 KB

Attached patch replaces the call to the deprecation drupalPostForm() with submitForm()

The last submitted patch, 37: 2984504-37-test-only.patch, failed testing. View results

jeroent’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good to me.

darvanen’s picture

Status: Reviewed & tested by the community » Needs work

It is looking good :) however:

  1. +++ b/core/modules/taxonomy/src/Form/OverviewTerms.php
    @@ -442,7 +441,6 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular
    -    $this->renderer->addCacheableDependency($form['terms'], $update_tree_access);
    

    Why has this been moved? This looks like an unrelated change.

  2. +++ b/core/modules/taxonomy/src/VocabularyAccessControlHandler.php
    @@ -23,6 +24,33 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter
    +        $pending_term_ids = $storage_controller->getTermIdsWithPendingRevisions();
    +        if (!empty($pending_term_ids)) {
    +          return AccessResult::forbidden()->setReason("$capital_name contains 1 or more terms with multiple parents. Drag and drop of terms with multiple parents is not supported, but you can re-enable drag-and-drop support by editing each term to include only a single parent.");
    +        }
    

    Error message needs to reflect the reason for failure.

idebr’s picture

Status: Needs work » Needs review
StatusFileSize
new2.08 KB
new2.24 KB
new7.7 KB

#40.1 Returned the line to its original location. Having the cache dependencies added on subsequent lines was helping readability for me, but there is a merit to the smallest change possible I suppose

#40.2 Copied the message from \Drupal\taxonomy\Form\OverviewTerms::buildForm() so it accurately reflects the reason for failure.

The last submitted patch, 41: 2984504-41-test-only.patch, failed testing. View results

darvanen’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, thank you.

Re #40.1, the idea is to give core committers less to figure out when reading the patch. I've seen so many issues knocked back with "unrelated change" :)

I wonder if they'll insist on tests for the error messages? That's a grey area for me, so as far as I'm concerned this can go back to RTBC.

catch’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/taxonomy/src/VocabularyAccessControlHandler.php
@@ -23,6 +24,33 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter
+
+        $tree = $storage_controller->loadTree($entity->id(), 0, NULL, TRUE);
+        $access_result = AccessResult::allowed();
+        foreach ($tree as $term) {
+          $access_result = $access_result->andIf($term->access('update', $account, TRUE));
+        }
+

I don't think it's reasonable to load the entire taxonomy tree, which can contain potentially hundreds of thousands of terms, to check access here. Why not make the button access rely on the administer taxonomy permission instead?

dpi’s picture

@catch

I don't think it's reasonable to load the entire taxonomy tree, which can contain potentially hundreds of thousands of terms, to check access here

Not to nitpick, but \Drupal\taxonomy\Form\OverviewTerms's buildForm and submitForm already do this. They make the same call of $this->storageController->loadTree($taxonomy_vocabulary->id(), 0, NULL, TRUE);

Regardless, I think we shouldnt need to do this in the access check either. Checking for the administer permission is enough. If contrib wants to do something fancy this new operation; access check will allow modules to hook in.

Why not make the button access rely on the administer taxonomy permission instead?

The patch moved the 'reset all weights'' permission check to the operation in VocabularyAccessControlHandler. So we dont lose this behavior.

+++ b/core/modules/taxonomy/src/VocabularyAccessControlHandler.php
@@ -23,6 +24,33 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter
+        $tree = $storage_controller->loadTree($entity->id(), 0, NULL, TRUE);
+        $access_result = AccessResult::allowed();
+        foreach ($tree as $term) {
+          $access_result = $access_result->andIf($term->access('update', $account, TRUE));
+        }
+

So, lets lets remove this hunk.

+++ b/core/modules/taxonomy/src/VocabularyAccessControlHandler.php
@@ -23,6 +24,33 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter
+        $capital_name = Unicode::ucfirst($entity->label());
+        if ($vocabulary_hierarchy === VocabularyInterface::HIERARCHY_MULTIPLE) {
+          return AccessResult::forbidden()->setReason("$capital_name contains terms with multiple parents. Drag and drop of terms with multiple parents is not supported, but you can re-enable drag-and-drop support by editing each term to include only a single parent.");
+        }
+
+        $pending_term_ids = $storage_controller->getTermIdsWithPendingRevisions();
+        if (!empty($pending_term_ids)) {
+          return AccessResult::forbidden()->setReason("$capital_name contains 1 or more terms with with pending revisions. Drag and drop of terms with with pending revisions is not supported, but you can re-enable drag-and-drop support by getting each term to a published state.");
+        }

I also dont fully understand why this is in access control. We dont need to determine whether *it is possible* to reorder. We only need to check whether the user should have *permission* to reorder. This responsibility should remain with \Drupal\taxonomy\Form\OverviewTerms

andregp’s picture

Status: Needs work » Needs review
StatusFileSize
new2.42 KB
new2.24 KB
new6.26 KB

@dpi here is a patch as per your comment.

Regardless, I think we shouldnt need to do this in the access check either. Checking for the administer permission is enough

I removed the hunk of code related to $tree = $storage_controller->loadTree($entity->id(), 0, NULL, TRUE); and added a simple permission check.

I also dont fully understand why this is in access control. We dont need to determine whether *it is possible* to reorder. We only need to check whether the user should have *permission* to reorder. This responsibility should remain with \Drupal\taxonomy\Form\OverviewTerms

I also removed these checks as \Drupal\taxonomy\Form\OverviewTerms already takes care of them. (line 308).

Status: Needs review » Needs work

The last submitted patch, 46: 2984504-46.patch, failed testing. View results

andregp’s picture

Status: Needs work » Needs review

Random test fail.

Johnny Santos’s picture

Assigned: Unassigned » Johnny Santos

I'm going to reproduce in my enviroment and check if it's working as planned to be

Johnny Santos’s picture

Assigned: Johnny Santos » Unassigned
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new79.05 KB
new70.76 KB

Tested as Admin and another created user(without administer taxonomy), and it worked as intented ,reseting to alphabetical order.

xjm’s picture

Status: Reviewed & tested by the community » Needs review

Thanks @Johnny Santos for manually testing this!

In addition to manual testing, the patch also needs code review to be marked "Reviewed and tested by the community". It looks like the test hit a known random fail, so I am requeuing it.

lpeidro’s picture

StatusFileSize
new6.89 KB
new3.07 KB

I check the tests about this case. I don't find any cause about the random fail, but I have added new checks about different context.
Please confirm that I correctly understood that;
The user only can "Reset to alphabetical" WHEN
- The user has the permission "administer taxonomy", OR
- The user has the permission "edit terms in ..."
I have generated new patch with the new checks in the test.

lpeidro’s picture

StatusFileSize
new6.97 KB
new3.09 KB

The files uploaded in my last comment (#52) are wrong. I did not properly generated the patches, for this reason they did not pass the test.

I have regenerated them again. Sorry for the confusion, this is one of my first contributions to the community.

lpeidro’s picture

StatusFileSize
new6.97 KB
new3.09 KB

This time, I had problems with a blank line during static analysis. Sorry again.

lpeidro’s picture

StatusFileSize
new3.09 KB
new6.97 KB

I think this is the final version of the patch files.

The last submitted patch, 55: 2984504-55-tests-only.patch, failed testing. View results

andregp’s picture

@Ipeidro, welcome to the Drupal Community! We're happy to have you helping.
It's perfectly normal to make mistakes sometimes, none of us is free from sending a wrong patch from time to time.

Just some tips for you:

You can easily install yarn on your environment and run ./core/scripts/dev/commit-code-check.sh to run the custom commands check before sending the patch (more info).
You can also use the phpcs commands (see here) to check for coding standards on your code.
This way you know beforehand if your patch will pass the initial checks, and save time of having to wait the test results here.

Another good practice to follow is to always provide an interdiff file when sending a patch based on a previous one, so that way other developers can more easily see what you changed on the code between the patches. (see here).

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.

prasanth_kp’s picture

StatusFileSize
new38.23 KB
new78.96 KB

Thanks for the patch,
I have applied it cleanly and it worked perfectly according to the condition.
Now the user can Reset to alphabetical if they have "administer taxonomy " or edit term permissions.

darvanen’s picture

Status: Needs review » Needs work
+++ b/core/modules/taxonomy/src/VocabularyAccessControlHandler.php
@@ -23,6 +23,16 @@ class VocabularyAccessControlHandler extends EntityAccessControlHandler {
+        return AccessResult::allowedIfHasPermissions($account, [
+          'access taxonomy overview',
+          'edit terms in ' . $entity->id(),
+        ]);

Not convinced this is the correct permission to be applying here. Access to the taxonomy overview doesn't automatically imply the right to edit the arrangement of terms.

I think it should be if they have either "edit terms in [vocabulary-name]" or "administer taxonomy" (which is handled in the lines prior to these ones).

ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new7.13 KB
new638 bytes

Made changes as per comment #60, please review.

Status: Needs review » Needs work

The last submitted patch, 61: 2984504-61.patch, failed testing. View results

darvanen’s picture

Status: Needs work » Reviewed & tested by the community

Thanks Ravi, the "edit terms in" line is correct in #55. It's the 'access taxonomy overview' I was questioning, though I was tired so I didn't really see that it was tempered by the presence of the next line already.

Having had more time to think about it I think #55 can be called RTBC. The code looks good, test coverage is good and it's passing, I don't see any outstanding feedback, and it does what the IS says it should.

darvanen’s picture

StatusFileSize
new6.97 KB

Reuploading #55 because of the 2 day test cycle.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 64: 2984504-55.patch, failed testing. View results

darvanen’s picture

Status: Needs work » Reviewed & tested by the community

Random fail, back to RTBC

larowlan’s picture

Queued a 10.0.x test-run

+++ b/core/modules/taxonomy/src/VocabularyAccessControlHandler.php
@@ -23,6 +23,16 @@ class VocabularyAccessControlHandler extends EntityAccessControlHandler {
+        if ($account->hasPermission('administer taxonomy')) {
+          return AccessResult::allowed()->cachePerPermissions();
+        }
+
+        return AccessResult::allowedIfHasPermissions($account, [
+          'access taxonomy overview',
+          'edit terms in ' . $entity->id(),
+        ]);

We could simplify this to

return AccessResult::allowedIfHasPermission($account, 'administer taxonomy')->orIf(AccessResult::allowedIfHasPermissions($account, ['access taxonomy overview', 'edit terms in ' $entity->id()]));

But I don't feel strongly about it.

Let's see what the 10.0.x result comes back (although HEAD is broken atm due to container/ci changes)

quietone’s picture

starting a retest on D10.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 64: 2984504-55.patch, failed testing. View results

darvanen’s picture

Status: Needs work » Needs review
StatusFileSize
new7.07 KB
new1.17 KB

I agree with #67. Applied.

jeroent’s picture

Status: Needs review » Needs work
darvanen’s picture

Status: Needs work » Needs review
StatusFileSize
new7.08 KB
new800 bytes
new1.19 KB

Oops. I ran the auto-formatter in PhpStorm but I must have had it badly highlighted.

berdir’s picture

+++ b/core/modules/taxonomy/src/VocabularyAccessControlHandler.php
@@ -23,6 +23,13 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter
 
+      case 'reset all weights':
+        return AccessResult::allowedIfHasPermission($account, 'administer taxonomy')
+          ->orIf(AccessResult::allowedIfHasPermissions($account, [
+            'access taxonomy overview',
+            'edit terms in ' . $entity->id(),
+          ]));
+

I'm not sure the check for access overview is needed at all? What's the reason for limiting it to that?

We could just an OR check for admin or edit all permission as a single check?

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

jsricardo’s picture

Assigned: Unassigned » jsricardo

I will review this

jsricardo’s picture

Assigned: jsricardo » Unassigned

I think the question in question is valid.
I believe it should be analyzed better!

darvanen’s picture

Version: 10.1.x-dev » 9.5.x-dev
StatusFileSize
new6.99 KB
new1.05 KB

#73 fair point, I agree. New patch attached.

Status: Needs review » Needs work

The last submitted patch, 77: 2984504-77.patch, failed testing. View results

darvanen’s picture

Status: Needs work » Needs review
Manibharathi E R’s picture

StatusFileSize
new129.43 KB
new214.66 KB

Patch #77 Tested and Applied successfully on Drupal 9.5.x.

gaurav-mathur’s picture

StatusFileSize
new12.67 KB
new53.38 KB

Applied patch #77 successfully on Drupal 9.5.x. and work fine .Refer to the screenshot.
Thank you

wells’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #77 applies and addresses point raised in #73. Moving back to RTBC.

Martin Markov’s picture

Applied patch #77 successfully on Drupal 9.4.3. and work fine.
Thank you!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 77: 2984504-77.patch, failed testing. View results

wells’s picture

Status: Needs work » Needs review

Test fail looks unrelated... moving back to NR for new tests.

acbramley’s picture

Status: Needs review » Reviewed & tested by the community

Tests passed so back to RTBC

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 77: 2984504-77.patch, failed testing. View results

penyaskito’s picture

Status: Needs work » Reviewed & tested by the community

Test failures are unrelated. Couldn't find if tracked elsewhere, asked on https://drupal.slack.com/archives/C1BMUQ9U6/p1676468080110019.

  • catch committed 12c59b7b on 10.1.x
    Issue #2984504 by idebr, lpeidro, darvanen, andregp, sarvjeetsingh, ravi...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Did my best with issue credit, but this is a long issue with lots of participants so apologies for any oversights.

This looks good now - since it's adding a new entity access case, going to commit to 10.1.x only.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

boromino’s picture

StatusFileSize
new6.75 KB
new1.64 KB

As described in https://www.drupal.org/project/drupal/issues/3403785, the committed solution does not hide the drag'n'drop icons nor the Show row weights link if there is a term with multiple parents. Therefore, I'm attaching a patch that fixes this for 9.5.x.

boromino’s picture

StatusFileSize
new6.33 KB
new2.05 KB

Overlooked one line to revert.