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

File names should be editable.

Summary: Fixes T7480, File names should be editable and the event should show up in feed.

Test Plan: Upload a file, view file details, edit file, change file name by adding a space and a word to the name, save changes, file name should retain space and not normalize the name, file details should show the edit event, install feed should correctly show an event for the action.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Maniphest Tasks: T7480

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

authored by

lkassianik and committed by
epriestley
55ff197f 3f77ad93

+137 -6
+18 -1
src/applications/files/controller/PhabricatorFileEditController.php
··· 26 26 } 27 27 28 28 $title = pht('Edit %s', $file->getName()); 29 + $file_name = $file->getName(); 29 30 $view_uri = '/'.$file->getMonogram(); 31 + $error_name = true; 32 + $validation_exception = null; 30 33 31 - $validation_exception = null; 32 34 if ($request->isFormPost()) { 33 35 $can_view = $request->getStr('canView'); 36 + $file_name = $request->getStr('name'); 37 + $errors = array(); 38 + 39 + $type_name = PhabricatorFileTransaction::TYPE_NAME; 34 40 35 41 $xactions = array(); 36 42 ··· 38 44 ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) 39 45 ->setNewValue($can_view); 40 46 47 + $xactions[] = id(new PhabricatorFileTransaction()) 48 + ->setTransactionType(PhabricatorFileTransaction::TYPE_NAME) 49 + ->setNewValue($file_name); 50 + 41 51 $editor = id(new PhabricatorFileEditor()) 42 52 ->setActor($viewer) 43 53 ->setContentSourceFromRequest($request) ··· 48 58 return id(new AphrontRedirectResponse())->setURI($view_uri); 49 59 } catch (PhabricatorApplicationTransactionValidationException $ex) { 50 60 $validation_exception = $ex; 61 + $error_name = $ex->getShortMessage($type_name); 51 62 52 63 $file->setViewPolicy($can_view); 53 64 } ··· 61 72 62 73 $form = id(new AphrontFormView()) 63 74 ->setUser($viewer) 75 + ->appendChild( 76 + id(new AphrontFormTextControl()) 77 + ->setName('name') 78 + ->setValue($file_name) 79 + ->setLabel(pht('Name')) 80 + ->setError($error_name)) 64 81 ->appendChild( 65 82 id(new AphrontFormPolicyControl()) 66 83 ->setUser($viewer)
+49 -2
src/applications/files/editor/PhabricatorFileEditor.php
··· 17 17 $types[] = PhabricatorTransactions::TYPE_COMMENT; 18 18 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 19 19 20 + $types[] = PhabricatorFileTransaction::TYPE_NAME; 21 + 20 22 return $types; 21 23 } 22 24 23 25 protected function getCustomTransactionOldValue( 24 26 PhabricatorLiskDAO $object, 25 - PhabricatorApplicationTransaction $xaction) {} 27 + PhabricatorApplicationTransaction $xaction) { 28 + 29 + switch ($xaction->getTransactionType()) { 30 + case PhabricatorFileTransaction::TYPE_NAME: 31 + return $object->getName(); 32 + } 33 + } 26 34 27 35 protected function getCustomTransactionNewValue( 28 36 PhabricatorLiskDAO $object, 29 - PhabricatorApplicationTransaction $xaction) {} 37 + PhabricatorApplicationTransaction $xaction) { 38 + 39 + switch ($xaction->getTransactionType()) { 40 + case PhabricatorFileTransaction::TYPE_NAME: 41 + return $xaction->getNewValue(); 42 + } 43 + } 30 44 31 45 protected function applyCustomInternalTransaction( 32 46 PhabricatorLiskDAO $object, ··· 35 49 switch ($xaction->getTransactionType()) { 36 50 case PhabricatorTransactions::TYPE_VIEW_POLICY: 37 51 $object->setViewPolicy($xaction->getNewValue()); 52 + break; 53 + case PhabricatorFileTransaction::TYPE_NAME: 54 + $object->setName($xaction->getNewValue()); 38 55 break; 39 56 } 40 57 } ··· 96 113 protected function supportsSearch() { 97 114 return false; 98 115 } 116 + 117 + protected function validateTransaction( 118 + PhabricatorLiskDAO $object, 119 + $type, 120 + array $xactions) { 121 + 122 + $errors = parent::validateTransaction($object, $type, $xactions); 123 + 124 + switch ($type) { 125 + case PhabricatorFileTransaction::TYPE_NAME: 126 + $missing = $this->validateIsEmptyTextField( 127 + $object->getName(), 128 + $xactions); 129 + 130 + if ($missing) { 131 + $error = new PhabricatorApplicationTransactionValidationError( 132 + $type, 133 + pht('Required'), 134 + pht('File name is required.'), 135 + nonempty(last($xactions), null)); 136 + 137 + $error->setIsMissingFieldError(true); 138 + $errors[] = $error; 139 + } 140 + break; 141 + } 142 + 143 + return $errors; 144 + } 145 + 99 146 100 147 }
+3 -3
src/applications/files/storage/PhabricatorFile.php
··· 209 209 210 210 $file = id(new PhabricatorFile())->loadOneWhere( 211 211 'name = %s AND contentHash = %s LIMIT 1', 212 - self::normalizeFileName(idx($params, 'name')), 212 + idx($params, 'name'), 213 213 self::hashFileContent($data)); 214 214 215 215 if (!$file) { ··· 692 692 } 693 693 694 694 private function getCDNURI($token) { 695 - $name = phutil_escape_uri($this->getName()); 695 + $name = self::normalizeFileName($this->getName()); 696 + $name = phutil_escape_uri($name); 696 697 697 698 $parts = array(); 698 699 $parts[] = 'file'; ··· 1210 1211 */ 1211 1212 private function readPropertiesFromParameters(array $params) { 1212 1213 $file_name = idx($params, 'name'); 1213 - $file_name = self::normalizeFileName($file_name); 1214 1214 $this->setName($file_name); 1215 1215 1216 1216 $author_phid = idx($params, 'authorPHID');
+67
src/applications/files/storage/PhabricatorFileTransaction.php
··· 3 3 final class PhabricatorFileTransaction 4 4 extends PhabricatorApplicationTransaction { 5 5 6 + const TYPE_NAME = 'file:name'; 7 + 6 8 public function getApplicationName() { 7 9 return 'file'; 8 10 } ··· 15 17 return new PhabricatorFileTransactionComment(); 16 18 } 17 19 20 + public function getTitle() { 21 + $author_phid = $this->getAuthorPHID(); 22 + 23 + $old = $this->getOldValue(); 24 + $new = $this->getNewValue(); 25 + 26 + switch ($this->getTransactionType()) { 27 + case self::TYPE_NAME: 28 + return pht( 29 + '%s updated the name for this file from "%s" to "%s".', 30 + $this->renderHandleLink($author_phid), 31 + $old, 32 + $new); 33 + break; 34 + } 35 + 36 + return parent::getTitle(); 37 + } 38 + 39 + public function getTitleForFeed() { 40 + $author_phid = $this->getAuthorPHID(); 41 + $object_phid = $this->getObjectPHID(); 42 + 43 + $old = $this->getOldValue(); 44 + $new = $this->getNewValue(); 45 + 46 + $type = $this->getTransactionType(); 47 + switch ($type) { 48 + case self::TYPE_NAME: 49 + return pht( 50 + '%s updated the name of %s from "%s" to "%s".', 51 + $this->renderHandleLink($author_phid), 52 + $this->renderHandleLink($object_phid), 53 + $old, 54 + $new); 55 + break; 56 + } 57 + 58 + return parent::getTitleForFeed(); 59 + } 60 + 61 + public function getIcon() { 62 + $old = $this->getOldValue(); 63 + $new = $this->getNewValue(); 64 + 65 + switch ($this->getTransactionType()) { 66 + case self::TYPE_NAME: 67 + return 'fa-pencil'; 68 + } 69 + 70 + return parent::getIcon(); 71 + } 72 + 73 + 74 + public function getColor() { 75 + $old = $this->getOldValue(); 76 + $new = $this->getNewValue(); 77 + 78 + switch ($this->getTransactionType()) { 79 + case self::TYPE_NAME: 80 + return PhabricatorTransactions::COLOR_BLUE; 81 + } 82 + 83 + return parent::getColor(); 84 + } 18 85 }