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

Simplify policy header implementation

Summary: Instead of rendering this in all callers, just pass the object into the header and let it figure out how to format it.

Test Plan: Looked at Legalpad, Paste, and Pholio.

Reviewers: chad, btrahan

Reviewed By: chad

CC: aran

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

+35 -68
+2 -7
src/applications/diviner/controller/DivinerBookController.php
··· 32 32 ->setName($book->getShortTitle()) 33 33 ->setHref('/book/'.$book->getName().'/')); 34 34 35 - $policies = PhabricatorPolicyQuery::renderPolicyDescriptions( 36 - $viewer, 37 - $book, 38 - true); 39 - 40 35 $header = id(new PHUIHeaderView()) 41 36 ->setHeader($book->getTitle()) 42 - ->addProperty(PHUIHeaderView::PROPERTY_POLICY, 43 - $policies[PhabricatorPolicyCapability::CAN_VIEW]); 37 + ->setUser($viewer) 38 + ->setPolicyObject($book); 44 39 45 40 $document = new PHUIDocumentView(); 46 41 $document->setHeader($header);
+2 -7
src/applications/legalpad/controller/LegalpadDocumentViewController.php
··· 61 61 62 62 $title = $document_body->getTitle(); 63 63 64 - $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( 65 - $user, 66 - $document, 67 - true); 68 - 69 64 $header = id(new PHUIHeaderView()) 70 65 ->setHeader($title) 71 - ->addProperty(PHUIHeaderView::PROPERTY_POLICY, 72 - $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); 66 + ->setUser($user) 67 + ->setPolicyObject($document); 73 68 74 69 $actions = $this->buildActionView($document); 75 70 $properties = $this->buildPropertyView($document, $engine);
+3 -7
src/applications/paste/controller/PhabricatorPasteViewController.php
··· 142 142 } 143 143 144 144 private function buildHeaderView(PhabricatorPaste $paste) { 145 - $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( 146 - $this->getRequest()->getUser(), 147 - $paste, 148 - $icon = true); 149 - 150 145 $header = id(new PHUIHeaderView()) 151 146 ->setHeader($paste->getTitle()) 152 - ->addProperty(PHUIHeaderView::PROPERTY_POLICY, 153 - $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); 147 + ->setUser($this->getRequest()->getUser()) 148 + ->setPolicyObject($paste); 149 + 154 150 return $header; 155 151 } 156 152
+2 -7
src/applications/phame/controller/blog/PhameBlogViewController.php
··· 33 33 34 34 $nav = $this->renderSideNavFilterView(null); 35 35 36 - $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( 37 - $user, 38 - $blog, 39 - true); 40 - 41 36 $header = id(new PHUIHeaderView()) 42 37 ->setHeader($blog->getName()) 43 - ->addProperty(PHUIHeaderView::PROPERTY_POLICY, 44 - $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); 38 + ->setUser($user) 39 + ->setPolicyObject($blog); 45 40 46 41 $handle_phids = array_merge( 47 42 mpull($posts, 'getBloggerPHID'),
+2 -7
src/applications/phame/controller/post/PhamePostViewController.php
··· 34 34 $actions = $this->renderActions($post, $user); 35 35 $properties = $this->renderProperties($post, $user); 36 36 37 - $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( 38 - $user, 39 - $post, 40 - true); 41 - 42 37 $crumbs = $this->buildApplicationCrumbs(); 43 38 $crumbs->setActionList($actions); 44 39 $crumbs->addCrumb( ··· 50 45 $nav->appendChild( 51 46 id(new PHUIHeaderView()) 52 47 ->setHeader($post->getTitle()) 53 - ->addProperty(PHUIHeaderView::PROPERTY_POLICY, 54 - $descriptions[PhabricatorPolicyCapability::CAN_VIEW])); 48 + ->setUser($user) 49 + ->setPolicyObject($post)); 55 50 56 51 if ($post->isDraft()) { 57 52 $nav->appendChild(
+3 -12
src/applications/phlux/controller/PhluxViewController.php
··· 30 30 ->setName($title) 31 31 ->setHref($request->getRequestURI())); 32 32 33 - $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( 34 - $user, 35 - $var, 36 - true); 37 - 38 33 $header = id(new PHUIHeaderView()) 39 34 ->setHeader($title) 40 - ->addProperty(PHUIHeaderView::PROPERTY_POLICY, 41 - $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); 35 + ->setUser($user) 36 + ->setPolicyObject($var); 42 37 43 38 $actions = id(new PhabricatorActionListView()) 44 39 ->setUser($user) ··· 63 58 $properties = id(new PhabricatorPropertyListView()) 64 59 ->setUser($user) 65 60 ->setObject($var) 66 - ->addProperty(pht('Value'), $display_value) 67 - ->addProperty( 68 - pht('Editable By'), 69 - $descriptions[PhabricatorPolicyCapability::CAN_EDIT]); 70 - 61 + ->addProperty(pht('Value'), $display_value); 71 62 72 63 $xactions = id(new PhluxTransactionQuery()) 73 64 ->setViewer($user)
+2 -7
src/applications/pholio/controller/PholioMockViewController.php
··· 67 67 68 68 $title = $mock->getName(); 69 69 70 - $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( 71 - $user, 72 - $mock, 73 - $icon = true); 74 - 75 70 $header = id(new PHUIHeaderView()) 76 71 ->setHeader($title) 77 - ->addProperty(PHUIHeaderView::PROPERTY_POLICY, 78 - $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); 72 + ->setUser($user) 73 + ->setPolicyObject($mock); 79 74 80 75 $actions = $this->buildActionView($mock); 81 76 $properties = $this->buildPropertyView($mock, $engine);
+2 -7
src/applications/slowvote/controller/PhabricatorSlowvotePollController.php
··· 41 41 )); 42 42 } 43 43 44 - $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( 45 - $user, 46 - $poll, 47 - true); 48 - 49 44 $header = id(new PHUIHeaderView()) 50 45 ->setHeader($poll->getQuestion()) 51 - ->addProperty(PHUIHeaderView::PROPERTY_POLICY, 52 - $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); 46 + ->setUser($user) 47 + ->setPolicyObject($poll); 53 48 54 49 $xaction_header = id(new PHUIHeaderView()) 55 50 ->setHeader(pht('Ongoing Deliberations'));
+17 -7
src/view/phui/PHUIHeaderView.php
··· 3 3 final class PHUIHeaderView extends AphrontView { 4 4 5 5 const PROPERTY_STATE = 1; 6 - const PROPERTY_POLICY = 2; 7 6 8 7 private $objectName; 9 8 private $header; ··· 13 12 private $gradient; 14 13 private $noBackground; 15 14 private $bleedHeader; 16 - private $properties; 15 + private $properties = array(); 16 + private $policyObject; 17 17 18 18 public function setHeader($header) { 19 19 $this->header = $header; ··· 55 55 return $this; 56 56 } 57 57 58 + public function setPolicyObject(PhabricatorPolicyInterface $object) { 59 + $this->policyObject = $object; 60 + return $this; 61 + } 62 + 58 63 public function addProperty($property, $value) { 59 64 $this->properties[$property] = $value; 60 65 return $this; ··· 79 84 $classes[] = 'gradient-'.$this->gradient.'-header'; 80 85 } 81 86 82 - if ($this->properties || $this->subheader) { 87 + if ($this->properties || $this->policyObject || $this->subheader) { 83 88 $classes[] = 'phui-header-tall'; 84 89 } 85 90 ··· 129 134 $this->subheader); 130 135 } 131 136 132 - if ($this->properties) { 137 + if ($this->properties || $this->policyObject) { 133 138 $property_list = array(); 134 139 foreach ($this->properties as $type => $property) { 135 140 switch ($type) { 136 141 case self::PROPERTY_STATE: 137 142 $property_list[] = $property; 138 143 break; 139 - case self::PROPERTY_POLICY: 140 - $property_list[] = $property; 141 - break; 142 144 default: 143 145 throw new Exception('Incorrect Property Passed'); 144 146 break; 145 147 } 148 + } 149 + 150 + if ($this->policyObject) { 151 + $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( 152 + $this->getUser(), 153 + $this->policyObject, 154 + true); 155 + $property_list[] = $descriptions[PhabricatorPolicyCapability::CAN_VIEW]; 146 156 } 147 157 148 158 $header[] = phutil_tag(