diff --git a/src/applications/diviner/controller/DivinerBookController.php b/src/applications/diviner/controller/DivinerBookController.php index f7f7295bc8..a96fd8606b 100644 --- a/src/applications/diviner/controller/DivinerBookController.php +++ b/src/applications/diviner/controller/DivinerBookController.php @@ -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); diff --git a/src/applications/legalpad/controller/LegalpadDocumentViewController.php b/src/applications/legalpad/controller/LegalpadDocumentViewController.php index 4773881e08..134d94e0da 100644 --- a/src/applications/legalpad/controller/LegalpadDocumentViewController.php +++ b/src/applications/legalpad/controller/LegalpadDocumentViewController.php @@ -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); diff --git a/src/applications/paste/controller/PhabricatorPasteViewController.php b/src/applications/paste/controller/PhabricatorPasteViewController.php index d6f0782add..dab9f113ab 100644 --- a/src/applications/paste/controller/PhabricatorPasteViewController.php +++ b/src/applications/paste/controller/PhabricatorPasteViewController.php @@ -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; } diff --git a/src/applications/phame/controller/blog/PhameBlogViewController.php b/src/applications/phame/controller/blog/PhameBlogViewController.php index 2e42df5e8b..4b3caf8896 100644 --- a/src/applications/phame/controller/blog/PhameBlogViewController.php +++ b/src/applications/phame/controller/blog/PhameBlogViewController.php @@ -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'), diff --git a/src/applications/phame/controller/post/PhamePostViewController.php b/src/applications/phame/controller/post/PhamePostViewController.php index 4882a87e65..471c596c57 100644 --- a/src/applications/phame/controller/post/PhamePostViewController.php +++ b/src/applications/phame/controller/post/PhamePostViewController.php @@ -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( diff --git a/src/applications/phlux/controller/PhluxViewController.php b/src/applications/phlux/controller/PhluxViewController.php index a6849bc315..776df44614 100644 --- a/src/applications/phlux/controller/PhluxViewController.php +++ b/src/applications/phlux/controller/PhluxViewController.php @@ -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) diff --git a/src/applications/pholio/controller/PholioMockViewController.php b/src/applications/pholio/controller/PholioMockViewController.php index 298aa84a45..f90a34b7e1 100644 --- a/src/applications/pholio/controller/PholioMockViewController.php +++ b/src/applications/pholio/controller/PholioMockViewController.php @@ -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); diff --git a/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php b/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php index 1bde176be2..0952085ad7 100644 --- a/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php +++ b/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php @@ -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')); diff --git a/src/view/phui/PHUIHeaderView.php b/src/view/phui/PHUIHeaderView.php index 7283be15a7..ac226fb249 100644 --- a/src/view/phui/PHUIHeaderView.php +++ b/src/view/phui/PHUIHeaderView.php @@ -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(