Problem/Motivation

The \Drupal\content_translation\Controller\ContentTranslationController::overview() method checks update/delete access on an untranslated entity, while the \Drupal\content_translation\Access\ContentTranslationManageAccessCheck::access() checks access on a specific translation. Once an entity access check depends on a value of a translatable field or on the active language of the translation, users may end up seeing access denied, because access to the translation form is denied for users who are able to use the edit form.

Steps to reproduce

  • Install Drupal using Standard profile.
  • Install 2.x version of Allowed Languages module.
  • Enable multiple languages, e.g. English & French.
  • Grant the following permissions to the Content Editor role:
    • Article: Delete any content
    • Article: Edit any content
    • Delete translations
    • Edit translations
    • Translate Article content item.
  • Create an Article node in English as admin.
  • Translate it into French as admin.
  • Create user A of Content Editor role with French as the only allowed language.
  • Log in as user A and visit the list of the node's translation.
  • The edit link next to the French translation follows to the translation form, which shows 403 Access Denied to this user. Same is for the deletion link.
  • However, you're still able to view the translation and then edit it through the local task.

The Allowed Languages module just implements a language-dependent access check that triggers the bug, the same could be achieved with a custom module. It also provides a route access check, but even with the allowed_languages.content_translation_access_check service removed, the issue is still reproducible.

Proposed resolution

Perform the access check on an entity translation in the content translation overview.

Remaining tasks

  • Submit MR.
  • Write release notes snippet.

User interface changes

No.

API changes

No.

Data model changes

No.

Release notes snippet

TODO

Issue fork drupal-3257030

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Dmitriy.trt created an issue. See original summary.

dmitriy.trt’s picture

StatusFileSize
new7.87 KB

The attached patch contains tests only, to make sure they fail without actual changes.

dmitriy.trt’s picture

Status: Active » Needs review
StatusFileSize
new9.87 KB

Attaching a patch that was made from MR!1611 at commit 92afcb78 for a stable reference from Composer.

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.

recrit’s picture

Status: Needs review » Needs work

Thanks for the patch. I ran into this access check oddity too when attempting to add some access rules for translations.
I would expect that the "create" access call should get the same updates as in this patch, so that the creation of specific translations could be restricted as well.
However, the translation entity cannot be created at that time so we would need to pass the language or just the language code.

-  $create_translation_access = $handler->getTranslationAccess($entity, 'create');
+ $create_translation_access = $handler->getTranslationAccess($entity, 'create', $langcode);

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

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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.

balagan’s picture

I confirm that applying the patch in #4 solves the problem. Edit/Delete operation buttons only display for eligible translations.

Version: 9.5.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. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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.

quietone’s picture

Work done by longwave using an LLM that identified this as a duplicate of #3371291: Content translation "update" and "delete" entity operation access checks are not made on the correct entity translation and suggested closing that one. After reading both issue I choose to close this one, so the new patch in the other issue is used. I've updated the issue summary over there with a task to get the test from the patch here.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.