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

Policy - fix up DifferentialChangesetParser

Summary:
Ref T7094. We should do a policy query on the files IMO because there exists a scenario where the file gets locked down directly. This requires being a bit more disciplined about setting user, which in turn requires deciding whether or not to show edit / reply links as a separate piece of logic, not conditional on user presence.

This is not the best code but I don't think it gets worse with this and is just some other nuance in any larger cleanup we take on someday.

Test Plan: looked at a revision and noted inline comments rendered correctly with reply / edit actions. looked at a diff standalone and noted no reply / edit actions as expected. looked at a "details" link on a transaction and it rendered correctly. looked at a diff in phriction of page edits and it looked good. grepped around and verified the remaining callsite in diffusion already has the setUser call.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T7094

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

+40 -15
+1
src/applications/differential/__tests__/DifferentialParseRenderTestCase.php
··· 48 48 $engine->setViewer(new PhabricatorUser()); 49 49 50 50 $cparser = new DifferentialChangesetParser(); 51 + $cparser->setUser(new PhabricatorUser()); 51 52 $cparser->setDisableCache(true); 52 53 $cparser->setChangeset($changeset); 53 54 $cparser->setMarkupEngine($engine);
+4 -3
src/applications/differential/controller/DifferentialChangesetViewController.php
··· 207 207 208 208 $engine->process(); 209 209 $parser->setMarkupEngine($engine); 210 + $parser->setUser($request->getUser()); 210 211 211 212 if ($request->isAjax()) { 212 - // TODO: This is sort of lazy, the effect is just to not render "Edit" 213 - // and "Reply" links on the "standalone view". 214 - $parser->setUser($request->getUser()); 213 + $parser->setShowEditAndReplyLinks(true); 214 + } else { 215 + $parser->setShowEditAndReplyLinks(false); 215 216 } 216 217 217 218 $output = $parser->render($range_s, $range_e, $mask);
+21 -10
src/applications/differential/parser/DifferentialChangesetParser.php
··· 43 43 private $renderer; 44 44 private $characterEncoding; 45 45 private $highlightAs; 46 + private $showEditAndReplyLinks = true; 47 + 48 + public function setShowEditAndReplyLinks($bool) { 49 + $this->showEditAndReplyLinks = $bool; 50 + return $this; 51 + } 52 + public function getShowEditAndReplyLinks() { 53 + return $this->showEditAndReplyLinks; 54 + } 46 55 47 56 public function setHighlightAs($highlight_as) { 48 57 $this->highlightAs = $highlight_as; ··· 62 71 return $this->characterEncoding; 63 72 } 64 73 65 - public function setRenderer($renderer) { 74 + public function setRenderer(DifferentialChangesetRenderer $renderer) { 66 75 $this->renderer = $renderer; 67 76 return $this; 68 77 } ··· 250 259 public function setUser(PhabricatorUser $user) { 251 260 $this->user = $user; 252 261 return $this; 262 + } 263 + 264 + public function getUser() { 265 + return $this->user; 253 266 } 254 267 255 268 public function setCoverage($coverage) { ··· 739 752 count($this->new)); 740 753 741 754 $renderer = $this->getRenderer() 755 + ->setUser($this->getUser()) 742 756 ->setChangeset($this->changeset) 743 757 ->setRenderPropertyChangeHeader($render_pch) 744 758 ->setIsTopLevel($this->isTopLevel) ··· 755 769 ->setHandles($this->handles) 756 770 ->setOldLines($this->old) 757 771 ->setNewLines($this->new) 758 - ->setOriginalCharacterEncoding($encoding); 759 - 760 - if ($this->user) { 761 - $renderer->setUser($this->user); 762 - } 772 + ->setOriginalCharacterEncoding($encoding) 773 + ->setShowEditAndReplyLinks($this->getShowEditAndReplyLinks()); 763 774 764 775 $shield = null; 765 776 if ($this->isTopLevel && !$this->comments) { ··· 905 916 $file_phids[] = $new_phid; 906 917 } 907 918 908 - // TODO: (T603) Probably fine to use omnipotent viewer here? 909 - $files = id(new PhabricatorFile())->loadAllWhere( 910 - 'phid IN (%Ls)', 911 - $file_phids); 919 + $files = id(new PhabricatorFileQuery()) 920 + ->setViewer($this->getUser()) 921 + ->withPHIDs($file_phids) 922 + ->execute(); 912 923 foreach ($files as $file) { 913 924 if (empty($file)) { 914 925 continue;
+3 -2
src/applications/differential/render/DifferentialChangesetHTMLRenderer.php
··· 443 443 $user = $this->getUser(); 444 444 $edit = $user && 445 445 ($comment->getAuthorPHID() == $user->getPHID()) && 446 - ($comment->isDraft()); 447 - $allow_reply = (bool)$user; 446 + ($comment->isDraft()) 447 + && $this->getShowEditAndReplyLinks(); 448 + $allow_reply = (bool)$user && $this->getShowEditAndReplyLinks(); 448 449 449 450 return id(new DifferentialInlineCommentView()) 450 451 ->setInlineComment($comment)
+9
src/applications/differential/render/DifferentialChangesetRenderer.php
··· 29 29 private $mask; 30 30 private $depths; 31 31 private $originalCharacterEncoding; 32 + private $showEditAndReplyLinks; 32 33 33 34 private $oldFile = false; 34 35 private $newFile = false; 36 + 37 + public function setShowEditAndReplyLinks($bool) { 38 + $this->showEditAndReplyLinks = $bool; 39 + return $this; 40 + } 41 + public function getShowEditAndReplyLinks() { 42 + return $this->showEditAndReplyLinks; 43 + } 35 44 36 45 public function setOriginalCharacterEncoding($original_character_encoding) { 37 46 $this->originalCharacterEncoding = $original_character_encoding;
+1
src/applications/phriction/controller/PhrictionDiffController.php
··· 71 71 $whitespace_mode = DifferentialChangesetParser::WHITESPACE_SHOW_ALL; 72 72 73 73 $parser = new DifferentialChangesetParser(); 74 + $parser->setUser($user); 74 75 $parser->setChangeset($changeset); 75 76 $parser->setRenderingReference("{$l},{$r}"); 76 77 $parser->setWhitespaceMode($whitespace_mode);
+1
src/applications/transactions/view/PhabricatorApplicationTransactionTextDiffDetailView.php
··· 43 43 $markup_engine->setViewer($this->getUser()); 44 44 45 45 $parser = new DifferentialChangesetParser(); 46 + $parser->setUser($this->getUser()); 46 47 $parser->setChangeset($changeset); 47 48 $parser->setMarkupEngine($markup_engine); 48 49 $parser->setWhitespaceMode($whitespace_mode);