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