@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.

Make the paste "Create" transaction take a file PHID instead of content

Summary:
Ref T4814. Although this approach made sense at one point, we have more file infrastructure now and T4814 will be easier if we just pass a PHID in.

Also swap Conduit over to use the Editor.

Test Plan:
- Created a paste.
- Created a paste via Conduit.
- Verified that files had correct permissions and appropriate object links in Files.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4814

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

+87 -85
+24 -16
src/applications/paste/conduit/ConduitAPI_paste_create_Method.php
··· 39 39 $title = nonempty($title, 'Masterwork From Distant Lands'); 40 40 $language = nonempty($language, ''); 41 41 42 - $user = $request->getUser(); 42 + $viewer = $request->getUser(); 43 43 44 - $paste_file = PhabricatorFile::newFromFileData( 45 - $content, 46 - array( 47 - 'name' => $title, 48 - 'mime-type' => 'text/plain; charset=utf-8', 49 - 'authorPHID' => $user->getPHID(), 50 - )); 44 + $paste = PhabricatorPaste::initializeNewPaste($viewer); 51 45 52 - // TODO: This should use PhabricatorPasteEditor. 46 + $file = PhabricatorPasteEditor::initializeFileForPaste( 47 + $viewer, 48 + $title, 49 + $content); 53 50 54 - $paste = PhabricatorPaste::initializeNewPaste($user); 55 - $paste->setTitle($title); 56 - $paste->setLanguage($language); 57 - $paste->setFilePHID($paste_file->getPHID()); 58 - $paste->save(); 51 + $xactions = array(); 59 52 60 - $paste_file->attachToObject($user, $paste->getPHID()); 53 + $xactions[] = id(new PhabricatorPasteTransaction()) 54 + ->setTransactionType(PhabricatorPasteTransaction::TYPE_CREATE) 55 + ->setNewValue($file->getPHID()); 61 56 62 - $paste->attachRawContent($content); 57 + $xactions[] = id(new PhabricatorPasteTransaction()) 58 + ->setTransactionType(PhabricatorPasteTransaction::TYPE_TITLE) 59 + ->setNewValue($title); 63 60 61 + $xactions[] = id(new PhabricatorPasteTransaction()) 62 + ->setTransactionType(PhabricatorPasteTransaction::TYPE_LANGUAGE) 63 + ->setNewValue($language); 64 + 65 + $editor = id(new PhabricatorPasteEditor()) 66 + ->setActor($viewer) 67 + ->setContentSourceFromConduitRequest($request); 68 + 69 + $xactions = $editor->applyTransactions($paste, $xactions); 70 + 71 + $paste->attachRawContent($content); 64 72 return $this->buildPasteInfoDictionary($paste); 65 73 } 66 74
+7 -3
src/applications/paste/controller/PhabricatorPasteEditController.php
··· 95 95 96 96 if (!$errors) { 97 97 if ($is_create) { 98 + $file = PhabricatorPasteEditor::initializeFileForPaste( 99 + $user, 100 + $v_title, 101 + $v_text); 102 + 98 103 $xactions[] = id(new PhabricatorPasteTransaction()) 99 104 ->setTransactionType(PhabricatorPasteTransaction::TYPE_CREATE) 100 - ->setNewValue(array( 101 - 'title' => $v_title, 102 - 'text' => $v_text)); 105 + ->setNewValue($file->getPHID()); 103 106 } 107 + 104 108 $xactions[] = id(new PhabricatorPasteTransaction()) 105 109 ->setTransactionType(PhabricatorPasteTransaction::TYPE_TITLE) 106 110 ->setNewValue($v_title);
+8 -8
src/applications/paste/controller/PhabricatorPasteViewController.php
··· 173 173 ->setObjectURI($this->getRequest()->getRequestURI()) 174 174 ->addAction( 175 175 id(new PhabricatorActionView()) 176 + ->setName(pht('Edit Paste')) 177 + ->setIcon('edit') 178 + ->setDisabled(!$can_edit) 179 + ->setWorkflow(!$can_edit) 180 + ->setHref($this->getApplicationURI('/edit/'.$paste->getID().'/'))) 181 + ->addAction( 182 + id(new PhabricatorActionView()) 176 183 ->setName(pht('Fork This Paste')) 177 184 ->setIcon('fork') 178 185 ->setDisabled(!$can_fork) ··· 182 189 id(new PhabricatorActionView()) 183 190 ->setName(pht('View Raw File')) 184 191 ->setIcon('file') 185 - ->setHref($file->getBestURI())) 186 - ->addAction( 187 - id(new PhabricatorActionView()) 188 - ->setName(pht('Edit Paste')) 189 - ->setIcon('edit') 190 - ->setDisabled(!$can_edit) 191 - ->setWorkflow(!$can_edit) 192 - ->setHref($this->getApplicationURI('/edit/'.$paste->getID().'/'))); 192 + ->setHref($file->getBestURI())); 193 193 } 194 194 195 195 private function buildPropertyView(
+34 -49
src/applications/paste/editor/PhabricatorPasteEditor.php
··· 5 5 6 6 private $pasteFile; 7 7 8 + public static function initializeFileForPaste( 9 + PhabricatorUser $actor, 10 + $name, 11 + $data) { 12 + 13 + return PhabricatorFile::newFromFileData( 14 + $data, 15 + array( 16 + 'name' => $name, 17 + 'mime-type' => 'text/plain; charset=utf-8', 18 + 'authorPHID' => $actor->getPHID(), 19 + 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, 20 + )); 21 + } 22 + 8 23 public function getTransactionTypes() { 9 24 $types = parent::getTransactionTypes(); 10 25 ··· 37 52 38 53 switch ($xaction->getTransactionType()) { 39 54 case PhabricatorPasteTransaction::TYPE_CREATE: 40 - // this was set via applyInitialEffects 41 - return $object->getFilePHID(); 42 55 case PhabricatorPasteTransaction::TYPE_TITLE: 43 56 case PhabricatorPasteTransaction::TYPE_LANGUAGE: 44 57 return $xaction->getNewValue(); ··· 50 63 PhabricatorApplicationTransaction $xaction) { 51 64 52 65 switch ($xaction->getTransactionType()) { 66 + case PhabricatorPasteTransaction::TYPE_CREATE: 67 + $object->setFilePHID($xaction->getNewValue()); 68 + return; 53 69 case PhabricatorPasteTransaction::TYPE_TITLE: 54 70 $object->setTitle($xaction->getNewValue()); 55 - break; 71 + return; 56 72 case PhabricatorPasteTransaction::TYPE_LANGUAGE: 57 73 $object->setLanguage($xaction->getNewValue()); 58 - break; 74 + return; 59 75 } 76 + 77 + return parent::applyCustomInternalTransaction($object, $xaction); 60 78 } 61 79 62 80 protected function applyCustomExternalTransaction( 63 81 PhabricatorLiskDAO $object, 64 82 PhabricatorApplicationTransaction $xaction) { 65 - } 66 83 67 - 68 - protected function shouldApplyInitialEffects( 69 - PhabricatorLiskDAO $object, 70 - array $xactions) { 71 - 72 - foreach ($xactions as $xaction) { 73 - if ($xaction->getTransactionType() == 74 - PhabricatorPasteTransaction::TYPE_CREATE) { 75 - return true; 76 - } 84 + switch ($xaction->getTransactionType()) { 85 + case PhabricatorPasteTransaction::TYPE_CREATE: 86 + case PhabricatorPasteTransaction::TYPE_TITLE: 87 + case PhabricatorPasteTransaction::TYPE_LANGUAGE: 88 + return; 77 89 } 78 - return false; 79 - } 80 90 81 - protected function applyInitialEffects( 82 - PhabricatorLiskDAO $object, 83 - array $xactions) { 84 - 85 - foreach ($xactions as $xaction) { 86 - switch ($xaction->getTransactionType()) { 87 - case PhabricatorPasteTransaction::TYPE_CREATE: 88 - $data = $xaction->getNewValue(); 89 - $paste_file = PhabricatorFile::newFromFileData( 90 - $data['text'], 91 - array( 92 - 'name' => $data['title'], 93 - 'mime-type' => 'text/plain; charset=utf-8', 94 - 'authorPHID' => $this->getActor()->getPHID(), 95 - )); 96 - $object->setFilePHID($paste_file->getPHID()); 97 - 98 - $this->pasteFile = $paste_file; 99 - break; 100 - } 101 - } 91 + return parent::applyCustomExternalTransaction($object, $xaction); 102 92 } 103 93 104 - protected function applyFinalEffects( 94 + protected function extractFilePHIDsFromCustomTransaction( 105 95 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. 96 + PhabricatorApplicationTransaction $xaction) { 110 97 111 - if ($this->pasteFile) { 112 - $this->pasteFile->attachToObject( 113 - $this->getActor(), 114 - $object->getPHID()); 98 + switch ($xaction->getTransactionType()) { 99 + case PhabricatorPasteTransaction::TYPE_CREATE: 100 + return array($xaction->getNewValue()); 115 101 } 116 102 117 - return $xactions; 103 + return parent::extractFilePHIDsFromCustomTransaction($object, $xaction); 118 104 } 119 - 120 105 121 106 protected function shouldSendMail( 122 107 PhabricatorLiskDAO $object,
+14 -9
src/applications/paste/mail/PasteCreateMailReceiver.php
··· 33 33 34 34 $title = $mail->getSubject(); 35 35 if (!$title) { 36 - $title = pht('Pasted via email.'); 36 + $title = pht('Email Paste'); 37 37 } 38 + 39 + $file = PhabricatorPasteEditor::initializeFileForPaste( 40 + $sender, 41 + $title, 42 + $mail->getCleanTextBody()); 43 + 38 44 $xactions = array(); 45 + 39 46 $xactions[] = id(new PhabricatorPasteTransaction()) 40 47 ->setTransactionType(PhabricatorPasteTransaction::TYPE_CREATE) 41 - ->setNewValue(array( 42 - 'title' => $title, 43 - 'text' => $mail->getCleanTextBody())); 48 + ->setNewValue($file->getPHID()); 49 + 44 50 $xactions[] = id(new PhabricatorPasteTransaction()) 45 51 ->setTransactionType(PhabricatorPasteTransaction::TYPE_TITLE) 46 52 ->setNewValue($title); 53 + 47 54 $xactions[] = id(new PhabricatorPasteTransaction()) 48 55 ->setTransactionType(PhabricatorPasteTransaction::TYPE_LANGUAGE) 49 56 ->setNewValue(''); // auto-detect 50 - $xactions[] = id(new PhabricatorPasteTransaction()) 51 - ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) 52 - ->setNewValue(PhabricatorPolicies::POLICY_USER); 57 + 58 + $paste = PhabricatorPaste::initializeNewPaste($sender); 53 59 54 - $paste = id(new PhabricatorPaste()) 55 - ->setAuthorPHID($sender->getPHID()); 56 60 $content_source = PhabricatorContentSource::newForSource( 57 61 PhabricatorContentSource::SOURCE_EMAIL, 58 62 array( 59 63 'id' => $mail->getID(), 60 64 )); 65 + 61 66 $editor = id(new PhabricatorPasteEditor()) 62 67 ->setActor($sender) 63 68 ->setContentSource($content_source)