Skip to content

Commit

Permalink
Make file policies for emailed files more consistent
Browse files Browse the repository at this point in the history
Summary:
Fixes T7712. Currently, files sent via email get default policies, like they were dragged and dropped onto the home page.

User expectation is better aligned with giving files more restrictive policies, like they were draggged and dropped directly onto an object.

Make files sent via email have restricted default visibility. Once we identify the sender, set them as the file author. Later, the file will become visible to other users via attachment to a task, revision, etc.

Test Plan: Sent some files via email; verified they got restrictive policies, correct authorship, and appropriate object attachment.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T7712

Differential Revision: https://secure.phabricator.com/D12255
  • Loading branch information
epriestley committed Apr 2, 2015
1 parent e74c386 commit a804f0a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions scripts/mail/mail_handler.php
Expand Up @@ -77,6 +77,7 @@
$attachment->getContent(),
array(
'name' => $attachment->getFilename(),
'viewPolicy' => PhabricatorPolicies::POLICY_NOONE,
));
$attachments[] = $file->getPHID();
}
Expand Down
Expand Up @@ -56,7 +56,7 @@ public function processRequest() {
$file = PhabricatorFile::newFromPHPUpload(
$file_raw,
array(
'authorPHID' => $user->getPHID(),
'viewPolicy' => PhabricatorPolicies::POLICY_NOONE,
));
$file_phids[] = $file->getPHID();
} catch (Exception $ex) {
Expand Down
Expand Up @@ -42,7 +42,7 @@ public function processRequest() {
$file = PhabricatorFile::newFromPHPUpload(
$file_raw,
array(
'authorPHID' => $user->getPHID(),
'viewPolicy' => PhabricatorPolicies::POLICY_NOONE,
));
$file_phids[] = $file->getPHID();
} catch (Exception $ex) {
Expand Down
Expand Up @@ -327,11 +327,8 @@ final protected function enhanceBodyWithAttachments(
return $body;
}

// NOTE: This is safe, but not entirely correct. Clean it up after
// T7712. These files have the install-default policy right now, which
// may or may not be permissive.
$files = id(new PhabricatorFileQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->setViewer($this->getActor())
->withPHIDs($attachments)
->execute();

Expand Down
Expand Up @@ -121,6 +121,19 @@ public function processReceivedMail() {

$this->setAuthorPHID($sender->getPHID());

// Now that we've identified the sender, mark them as the author of
// any attached files.
$attachments = $this->getAttachments();
if ($attachments) {
$files = id(new PhabricatorFileQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withPHIDs($attachments)
->execute();
foreach ($files as $file) {
$file->setAuthorPHID($sender->getPHID())->save();
}
}

$receiver->receiveMail($this, $sender);
} catch (PhabricatorMetaMTAReceivedMailProcessingException $ex) {
switch ($ex->getStatusCode()) {
Expand Down

0 comments on commit a804f0a

Please sign in to comment.