@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

When editing objects which use files, attach the files to the objects

Summary: Ref T603. Fixes T3921. Tightens up policy controls for file/object relationships in existing applications.

Test Plan:
- Uploaded new project image, verified it got an edge to the project.
- Uploaded new profile image, verified it got an edge to me.
- Uploaded new macro image, verified it got an edge to the macro.
- Uploaded new paste via web UI and conduit, verified it got attached.
- Replaced, added images to a mock, verified they got edges.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3921, T603

Differential Revision: https://secure.phabricator.com/D7254

+98 -10
+19
src/applications/files/storage/PhabricatorFile.php
··· 860 860 return idx($this->metadata, self::METADATA_IMAGE_WIDTH); 861 861 } 862 862 863 + /** 864 + * Write the policy edge between this file and some object. 865 + * 866 + * @param PhabricatorUser Acting user. 867 + * @param phid Object PHID to attach to. 868 + * @return this 869 + */ 870 + public function attachToObject(PhabricatorUser $actor, $phid) { 871 + $edge_type = PhabricatorEdgeConfig::TYPE_OBJECT_HAS_FILE; 872 + 873 + id(new PhabricatorEdgeEditor()) 874 + ->setActor($actor) 875 + ->setSuppressEvents(true) 876 + ->addEdge($phid, $edge_type, $this->getPHID()) 877 + ->save(); 878 + 879 + return $this; 880 + } 881 + 863 882 864 883 /* -( PhabricatorPolicyInterface Implementation )-------------------------- */ 865 884
+12
src/applications/macro/editor/PhabricatorMacroEditor.php
··· 77 77 return; 78 78 } 79 79 80 + protected function extractFilePHIDsFromCustomTransaction( 81 + PhabricatorLiskDAO $object, 82 + PhabricatorApplicationTransaction $xaction) { 83 + 84 + switch ($xaction->getTransactionType()) { 85 + case PhabricatorMacroTransactionType::TYPE_FILE: 86 + return array($xaction->getNewValue()); 87 + } 88 + 89 + return array(); 90 + } 91 + 80 92 protected function mergeTransactions( 81 93 PhabricatorApplicationTransaction $u, 82 94 PhabricatorApplicationTransaction $v) {
+4
src/applications/paste/conduit/ConduitAPI_paste_create_Method.php
··· 49 49 'authorPHID' => $user->getPHID(), 50 50 )); 51 51 52 + // TODO: This should use PhabricatorPasteEditor. 53 + 52 54 $paste = new PhabricatorPaste(); 53 55 $paste->setTitle($title); 54 56 $paste->setLanguage($language); ··· 56 58 $paste->setAuthorPHID($user->getPHID()); 57 59 $paste->setViewPolicy(PhabricatorPolicies::POLICY_USER); 58 60 $paste->save(); 61 + 62 + $paste_file->attachToObject($user, $paste->getPHID()); 59 63 60 64 $paste->attachRawContent($content); 61 65
+19 -3
src/applications/paste/editor/PhabricatorPasteEditor.php
··· 1 1 <?php 2 2 3 - /** 4 - * @group paste 5 - */ 6 3 final class PhabricatorPasteEditor 7 4 extends PhabricatorApplicationTransactionEditor { 5 + 6 + private $pasteFile; 8 7 9 8 public function getTransactionTypes() { 10 9 $types = parent::getTransactionTypes(); ··· 95 94 'authorPHID' => $this->getActor()->getPHID(), 96 95 )); 97 96 $object->setFilePHID($paste_file->getPHID()); 97 + 98 + $this->pasteFile = $paste_file; 98 99 break; 99 100 } 100 101 } 101 102 } 103 + 104 + protected function applyFinalEffects( 105 + PhabricatorLiskDAO $object, 106 + array $xactions) { 107 + 108 + // TODO: This should use extractFilePHIDs() instead, but the way 109 + // the transactions work right now makes pretty messy. 110 + 111 + if ($this->pasteFile) { 112 + $this->pasteFile->attachToObject( 113 + $this->getActor(), 114 + $object->getPHID()); 115 + } 116 + } 117 + 102 118 103 119 protected function shouldSendMail( 104 120 PhabricatorLiskDAO $object,
-3
src/applications/paste/storage/PhabricatorPasteTransaction.php
··· 1 1 <?php 2 2 3 - /** 4 - * @group paste 5 - */ 6 3 final class PhabricatorPasteTransaction 7 4 extends PhabricatorApplicationTransaction { 8 5
+1
src/applications/people/controller/PhabricatorPeopleProfilePictureController.php
··· 82 82 $user->setProfileImagePHID(null); 83 83 } else { 84 84 $user->setProfileImagePHID($xformed->getPHID()); 85 + $xformed->attachToObject($viewer, $user->getPHID()); 85 86 } 86 87 $user->save(); 87 88 return id(new AphrontRedirectResponse())->setURI($profile_uri);
+20
src/applications/pholio/editor/PholioMockEditor.php
··· 106 106 } 107 107 } 108 108 109 + protected function extractFilePHIDsFromCustomTransaction( 110 + PhabricatorLiskDAO $object, 111 + PhabricatorApplicationTransaction $xaction) { 112 + 113 + switch ($xaction->getTransactionType()) { 114 + case PholioTransactionType::TYPE_IMAGE_FILE: 115 + $new = $xaction->getNewValue(); 116 + $phids = array(); 117 + foreach ($new as $key => $images) { 118 + $phids[] = mpull($images, 'getFilePHID'); 119 + } 120 + return array_mergev($phids); 121 + case PholioTransactionType::TYPE_IMAGE_REPLACE: 122 + return array($xaction->getNewValue()->getFilePHID()); 123 + } 124 + 125 + return array(); 126 + } 127 + 128 + 109 129 protected function transactionHasEffect( 110 130 PhabricatorLiskDAO $object, 111 131 PhabricatorApplicationTransaction $xaction) {
+3
src/applications/project/controller/PhabricatorProjectProfileEditController.php
··· 107 107 $file, 108 108 $x = 50, 109 109 $y = 50); 110 + 110 111 $profile->setProfileImagePHID($xformed->getPHID()); 112 + $xformed->attachToObject($user, $project->getPHID()); 113 + 111 114 } else { 112 115 $e_image = pht('Not Supported'); 113 116 $errors[] =
+20 -4
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 1575 1575 } 1576 1576 $blocks = array_mergev($blocks); 1577 1577 1578 - if (!$blocks) { 1579 - return array(); 1578 + 1579 + $phids = array(); 1580 + if ($blocks) { 1581 + $phids[] = PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles( 1582 + $blocks); 1580 1583 } 1581 1584 1582 - $phids = PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles( 1583 - $blocks); 1585 + foreach ($xactions as $xaction) { 1586 + $phids[] = $this->extractFilePHIDsFromCustomTransaction( 1587 + $object, 1588 + $xaction); 1589 + } 1584 1590 1591 + $phids = array_unique(array_filter(array_mergev($phids))); 1585 1592 if (!$phids) { 1586 1593 return array(); 1587 1594 } ··· 1596 1603 ->execute(); 1597 1604 1598 1605 return mpull($files, 'getPHID'); 1606 + } 1607 + 1608 + /** 1609 + * @task files 1610 + */ 1611 + protected function extractFilePHIDsFromCustomTransaction( 1612 + PhabricatorLiskDAO $object, 1613 + PhabricatorApplicationTransaction $xaction) { 1614 + return array(); 1599 1615 } 1600 1616 1601 1617