Problem/Motivation

When a link references a file served from the Drupal-managed files directory (e.g. /sites/site-name/files/fiel-name.pdf), the module flags the URL as access-denied.

Access denied entity mesh file

Not translated file

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

frouco created an issue. See original summary.

eduardo morales alberti made their first commit to this issue’s fork.

eduardo morales alberti’s picture

Status: Active » Needs work

We need more info on how to reproduce it

eduardo morales alberti’s picture

Title: Links to private files under /sites/*/files/ incorrectly flagged as "access-denied" » Links to public files under /sites/*/files/ incorrectly flagged as "access-denied"
eduardo morales alberti’s picture

Assigned: Unassigned » eduardo morales alberti
eduardo morales alberti’s picture

Issue summary: View changes
StatusFileSize
new50.95 KB
new82.84 KB

After reviewing the problem with @frouco the problem comes when the media file's original language does not match the content language or is not translated.

Untranslated file
Access denied entity mesh

eduardo morales alberti’s picture

The problem comes because the media is not translated 404/403, so it does not reach the file, as the file is the "link", we should check if the file is accessible

eduardo morales alberti’s picture

Assigned: eduardo morales alberti » Unassigned
Status: Needs work » Needs review

Ready to review, now it gets the file from the media, and checks the file access instead of the media.

src/Repository:checkDownloadAccessEntity

  /**
   * {@inheritdoc}
   */
  public function checkDownloadAccessEntity(EntityInterface $entity): bool {
    $mesh_account = $this->getMeshAccount();
    return $entity->access('download', $mesh_account);
  }

src/EntityRender:accessCheckTarget

    if ($target->getSourceFileId() !== NULL || $target->getEntityType() === 'file') {
      $file = $target->getSourceFileId() !== NULL
        ? $this->entityTypeManager->getStorage('file')->load($target->getSourceFileId())
        : $entity;
      return $file
        ? $this->entityMeshRepository->checkDownloadAccessEntity($file)
        : FALSE;
    }

lpeidro made their first commit to this issue’s fork.

lpeidro’s picture

I have reviewed the MR and checked it in local.
It works as expected.

It is ready to merge.

lpeidro’s picture

Status: Needs review » Fixed

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.

Status: Fixed » Closed (fixed)

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