Problem/Motivation
Follow on from #3529246: [Regression in 1.6] missing attachments from private://. The attachment access checking code blocks attaching any private file unless there is code to call setAccess(). Sites would prefer to allow selective access without writing code.
Proposed resolution
Allow attaching private files that the recipient would anyway have access to via HTTPS. It's a bit awkward to implement because there isn't an API - the code is tied into FileDownloadController.php. I guess we'd have to invoke hook_file_download().
Alternative (rejected?) idea
Create an EmailAdjuster that allows access to a configurable directory within private://. I (AdamPS) am not convinced this is the right solution. Files that are in private are there because they are not universally safe. The invoices example mentioned in some of the comments of #3529246: [Regression in 1.6] missing attachments from private:// is good. It's safe to email someone their own invoice, but they shouldn't see someone else's. The EmailAdjuster couldn't possibly express this precision - it would simply trust that another piece of code is emailing the right invoice to the right person. Therefore that other code should be setting the access. The code we have in this module is similar to the other access code in Core and to the code for controlling access to private files.
The invoice example would be very simple to write. If the "to" email address matches the email address that was given on the order then grant access. Also could grant access to users with a relevant permission something like "view all invoices".
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork symfony_mailer-3530021
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
Comment #2
adamps commentedComment #4
adamps commentedComment #6
adamps commentedComment #8
mach3.zone commentedFollowed along the Issue missing attachments from private:// and ended up here. I really like the idea, so that we don't have to set the
->setAccess(AccessResult::allowed()manually, although it's not a problem. I just wondered whether the implementation works for others; In our case we have an attachment where thegetUri()call returns something like/var/www/html/private/pdfs/1032233.pdf, then after$scheme = $uri ? parse_url($uri, PHP_URL_SCHEME) : '_data_';$scheme would be null and $check as well and hence we miss both following branches where$attachment->setAccess(AccessResult::allowed());is set.What am I'm missing?