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
This commit is contained in:
		| @@ -32,15 +32,10 @@ final class DivinerBookController extends DivinerController { | ||||
|         ->setName($book->getShortTitle()) | ||||
|         ->setHref('/book/'.$book->getName().'/')); | ||||
|  | ||||
|     $policies = PhabricatorPolicyQuery::renderPolicyDescriptions( | ||||
|       $viewer, | ||||
|       $book, | ||||
|       true); | ||||
|  | ||||
|     $header = id(new PHUIHeaderView()) | ||||
|       ->setHeader($book->getTitle()) | ||||
|       ->addProperty(PHUIHeaderView::PROPERTY_POLICY, | ||||
|         $policies[PhabricatorPolicyCapability::CAN_VIEW]); | ||||
|       ->setUser($viewer) | ||||
|       ->setPolicyObject($book); | ||||
|  | ||||
|     $document = new PHUIDocumentView(); | ||||
|     $document->setHeader($header); | ||||
|   | ||||
| @@ -61,15 +61,10 @@ final class LegalpadDocumentViewController extends LegalpadController { | ||||
|  | ||||
|     $title = $document_body->getTitle(); | ||||
|  | ||||
|     $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( | ||||
|       $user, | ||||
|       $document, | ||||
|       true); | ||||
|  | ||||
|     $header = id(new PHUIHeaderView()) | ||||
|       ->setHeader($title) | ||||
|       ->addProperty(PHUIHeaderView::PROPERTY_POLICY, | ||||
|         $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); | ||||
|       ->setUser($user) | ||||
|       ->setPolicyObject($document); | ||||
|  | ||||
|     $actions = $this->buildActionView($document); | ||||
|     $properties = $this->buildPropertyView($document, $engine); | ||||
|   | ||||
| @@ -142,15 +142,11 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController { | ||||
|   } | ||||
|  | ||||
|   private function buildHeaderView(PhabricatorPaste $paste) { | ||||
|     $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( | ||||
|       $this->getRequest()->getUser(), | ||||
|       $paste, | ||||
|       $icon = true); | ||||
|  | ||||
|     $header = id(new PHUIHeaderView()) | ||||
|       ->setHeader($paste->getTitle()) | ||||
|       ->addProperty(PHUIHeaderView::PROPERTY_POLICY, | ||||
|         $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); | ||||
|       ->setUser($this->getRequest()->getUser()) | ||||
|       ->setPolicyObject($paste); | ||||
|  | ||||
|     return $header; | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -33,15 +33,10 @@ final class PhameBlogViewController extends PhameController { | ||||
|  | ||||
|     $nav = $this->renderSideNavFilterView(null); | ||||
|  | ||||
|     $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( | ||||
|       $user, | ||||
|       $blog, | ||||
|       true); | ||||
|  | ||||
|     $header = id(new PHUIHeaderView()) | ||||
|       ->setHeader($blog->getName()) | ||||
|       ->addProperty(PHUIHeaderView::PROPERTY_POLICY, | ||||
|         $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); | ||||
|       ->setUser($user) | ||||
|       ->setPolicyObject($blog); | ||||
|  | ||||
|     $handle_phids = array_merge( | ||||
|       mpull($posts, 'getBloggerPHID'), | ||||
|   | ||||
| @@ -34,11 +34,6 @@ final class PhamePostViewController extends PhameController { | ||||
|     $actions = $this->renderActions($post, $user); | ||||
|     $properties = $this->renderProperties($post, $user); | ||||
|  | ||||
|     $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( | ||||
|       $user, | ||||
|       $post, | ||||
|       true); | ||||
|  | ||||
|     $crumbs = $this->buildApplicationCrumbs(); | ||||
|     $crumbs->setActionList($actions); | ||||
|     $crumbs->addCrumb( | ||||
| @@ -50,8 +45,8 @@ final class PhamePostViewController extends PhameController { | ||||
|     $nav->appendChild( | ||||
|       id(new PHUIHeaderView()) | ||||
|         ->setHeader($post->getTitle()) | ||||
|         ->addProperty(PHUIHeaderView::PROPERTY_POLICY, | ||||
|           $descriptions[PhabricatorPolicyCapability::CAN_VIEW])); | ||||
|         ->setUser($user) | ||||
|         ->setPolicyObject($post)); | ||||
|  | ||||
|     if ($post->isDraft()) { | ||||
|       $nav->appendChild( | ||||
|   | ||||
| @@ -30,15 +30,10 @@ final class PhluxViewController extends PhluxController { | ||||
|         ->setName($title) | ||||
|         ->setHref($request->getRequestURI())); | ||||
|  | ||||
|     $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( | ||||
|       $user, | ||||
|       $var, | ||||
|       true); | ||||
|  | ||||
|     $header = id(new PHUIHeaderView()) | ||||
|       ->setHeader($title) | ||||
|       ->addProperty(PHUIHeaderView::PROPERTY_POLICY, | ||||
|         $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); | ||||
|       ->setUser($user) | ||||
|       ->setPolicyObject($var); | ||||
|  | ||||
|     $actions = id(new PhabricatorActionListView()) | ||||
|       ->setUser($user) | ||||
| @@ -63,11 +58,7 @@ final class PhluxViewController extends PhluxController { | ||||
|     $properties = id(new PhabricatorPropertyListView()) | ||||
|       ->setUser($user) | ||||
|       ->setObject($var) | ||||
|       ->addProperty(pht('Value'), $display_value) | ||||
|       ->addProperty( | ||||
|         pht('Editable By'), | ||||
|         $descriptions[PhabricatorPolicyCapability::CAN_EDIT]); | ||||
|  | ||||
|       ->addProperty(pht('Value'), $display_value); | ||||
|  | ||||
|     $xactions = id(new PhluxTransactionQuery()) | ||||
|       ->setViewer($user) | ||||
|   | ||||
| @@ -67,15 +67,10 @@ final class PholioMockViewController extends PholioController { | ||||
|  | ||||
|     $title = $mock->getName(); | ||||
|  | ||||
|     $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( | ||||
|       $user, | ||||
|       $mock, | ||||
|       $icon = true); | ||||
|  | ||||
|     $header = id(new PHUIHeaderView()) | ||||
|       ->setHeader($title) | ||||
|       ->addProperty(PHUIHeaderView::PROPERTY_POLICY, | ||||
|         $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); | ||||
|       ->setUser($user) | ||||
|       ->setPolicyObject($mock); | ||||
|  | ||||
|     $actions = $this->buildActionView($mock); | ||||
|     $properties = $this->buildPropertyView($mock, $engine); | ||||
|   | ||||
| @@ -41,15 +41,10 @@ final class PhabricatorSlowvotePollController | ||||
|           )); | ||||
|     } | ||||
|  | ||||
|     $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( | ||||
|       $user, | ||||
|       $poll, | ||||
|       true); | ||||
|  | ||||
|     $header = id(new PHUIHeaderView()) | ||||
|       ->setHeader($poll->getQuestion()) | ||||
|       ->addProperty(PHUIHeaderView::PROPERTY_POLICY, | ||||
|         $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); | ||||
|       ->setUser($user) | ||||
|       ->setPolicyObject($poll); | ||||
|  | ||||
|     $xaction_header = id(new PHUIHeaderView()) | ||||
|       ->setHeader(pht('Ongoing Deliberations')); | ||||
|   | ||||
| @@ -3,7 +3,6 @@ | ||||
| final class PHUIHeaderView extends AphrontView { | ||||
|  | ||||
|   const PROPERTY_STATE = 1; | ||||
|   const PROPERTY_POLICY = 2; | ||||
|  | ||||
|   private $objectName; | ||||
|   private $header; | ||||
| @@ -13,7 +12,8 @@ final class PHUIHeaderView extends AphrontView { | ||||
|   private $gradient; | ||||
|   private $noBackground; | ||||
|   private $bleedHeader; | ||||
|   private $properties; | ||||
|   private $properties = array(); | ||||
|   private $policyObject; | ||||
|  | ||||
|   public function setHeader($header) { | ||||
|     $this->header = $header; | ||||
| @@ -55,6 +55,11 @@ final class PHUIHeaderView extends AphrontView { | ||||
|     return $this; | ||||
|   } | ||||
|  | ||||
|   public function setPolicyObject(PhabricatorPolicyInterface $object) { | ||||
|     $this->policyObject = $object; | ||||
|     return $this; | ||||
|   } | ||||
|  | ||||
|   public function addProperty($property, $value) { | ||||
|     $this->properties[$property] = $value; | ||||
|     return $this; | ||||
| @@ -79,7 +84,7 @@ final class PHUIHeaderView extends AphrontView { | ||||
|       $classes[] = 'gradient-'.$this->gradient.'-header'; | ||||
|     } | ||||
|  | ||||
|     if ($this->properties || $this->subheader) { | ||||
|     if ($this->properties || $this->policyObject || $this->subheader) { | ||||
|       $classes[] = 'phui-header-tall'; | ||||
|     } | ||||
|  | ||||
| @@ -129,22 +134,27 @@ final class PHUIHeaderView extends AphrontView { | ||||
|         $this->subheader); | ||||
|     } | ||||
|  | ||||
|     if ($this->properties) { | ||||
|     if ($this->properties || $this->policyObject) { | ||||
|       $property_list = array(); | ||||
|       foreach ($this->properties as $type => $property) { | ||||
|         switch ($type) { | ||||
|           case self::PROPERTY_STATE: | ||||
|             $property_list[] = $property; | ||||
|           break; | ||||
|           case self::PROPERTY_POLICY: | ||||
|             $property_list[] = $property; | ||||
|           break; | ||||
|           default: | ||||
|             throw new Exception('Incorrect Property Passed'); | ||||
|           break; | ||||
|         } | ||||
|       } | ||||
|  | ||||
|       if ($this->policyObject) { | ||||
|         $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( | ||||
|           $this->getUser(), | ||||
|           $this->policyObject, | ||||
|           true); | ||||
|         $property_list[] = $descriptions[PhabricatorPolicyCapability::CAN_VIEW]; | ||||
|       } | ||||
|  | ||||
|       $header[] = phutil_tag( | ||||
|         'div', | ||||
|         array( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 epriestley
					epriestley