Differential D18523 Diff 44527 src/applications/diffusion/management/DiffusionRepositoryPoliciesManagementPanel.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/management/DiffusionRepositoryPoliciesManagementPanel.php
<?php | <?php | ||||
final class DiffusionRepositoryPoliciesManagementPanel | final class DiffusionRepositoryPoliciesManagementPanel | ||||
extends DiffusionRepositoryManagementPanel { | extends DiffusionRepositoryManagementPanel { | ||||
const PANELKEY = 'policies'; | const PANELKEY = 'policies'; | ||||
public function getManagementPanelLabel() { | public function getManagementPanelLabel() { | ||||
return pht('Policies'); | return pht('Policies'); | ||||
} | } | ||||
public function getManagementPanelOrder() { | public function getManagementPanelOrder() { | ||||
return 300; | return 300; | ||||
} | } | ||||
public function getManagementPanelIcon() { | public function getManagementPanelIcon() { | ||||
$viewer = $this->getViewer(); | |||||
$repository = $this->getRepository(); | |||||
$can_view = PhabricatorPolicyCapability::CAN_VIEW; | |||||
$can_edit = PhabricatorPolicyCapability::CAN_EDIT; | |||||
$can_push = DiffusionPushCapability::CAPABILITY; | |||||
$actual_values = array( | |||||
'spacePHID' => $repository->getSpacePHID(), | |||||
'view' => $repository->getPolicy($can_view), | |||||
'edit' => $repository->getPolicy($can_edit), | |||||
'push' => $repository->getPolicy($can_push), | |||||
); | |||||
$default = PhabricatorRepository::initializeNewRepository( | |||||
$viewer); | |||||
$default_values = array( | |||||
'spacePHID' => $default->getSpacePHID(), | |||||
'view' => $default->getPolicy($can_view), | |||||
'edit' => $default->getPolicy($can_edit), | |||||
'push' => $default->getPolicy($can_push), | |||||
); | |||||
if ($actual_values === $default_values) { | |||||
return 'fa-lock grey'; | |||||
} else { | |||||
return 'fa-lock'; | return 'fa-lock'; | ||||
} | } | ||||
} | |||||
protected function getEditEngineFieldKeys() { | protected function getEditEngineFieldKeys() { | ||||
return array( | return array( | ||||
'policy.view', | 'policy.view', | ||||
'policy.edit', | 'policy.edit', | ||||
'spacePHID', | 'spacePHID', | ||||
'policy.push', | 'policy.push', | ||||
); | ); | ||||
} | } | ||||
public function buildManagementPanelCurtain() { | |||||
$repository = $this->getRepository(); | |||||
$viewer = $this->getViewer(); | |||||
$action_list = $this->getNewActionList(); | |||||
$can_edit = PhabricatorPolicyFilter::hasCapability( | |||||
$viewer, | |||||
$repository, | |||||
PhabricatorPolicyCapability::CAN_EDIT); | |||||
$edit_uri = $this->getEditPageURI(); | |||||
$action_list->addAction( | |||||
id(new PhabricatorActionView()) | |||||
->setIcon('fa-pencil') | |||||
->setName(pht('Edit Policies')) | |||||
->setHref($edit_uri) | |||||
->setDisabled(!$can_edit) | |||||
->setWorkflow(!$can_edit)); | |||||
return $this->getNewCurtainView($action_list); | |||||
} | |||||
public function buildManagementPanelContent() { | public function buildManagementPanelContent() { | ||||
$repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$view = id(new PHUIPropertyListView()) | $view = id(new PHUIPropertyListView()) | ||||
->setViewer($viewer); | ->setViewer($viewer); | ||||
$descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( | $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( | ||||
Show All 16 Lines | $view->addProperty( | ||||
pht('Editable By'), | pht('Editable By'), | ||||
$descriptions[PhabricatorPolicyCapability::CAN_EDIT]); | $descriptions[PhabricatorPolicyCapability::CAN_EDIT]); | ||||
$pushable = $repository->isHosted() | $pushable = $repository->isHosted() | ||||
? $descriptions[DiffusionPushCapability::CAPABILITY] | ? $descriptions[DiffusionPushCapability::CAPABILITY] | ||||
: phutil_tag('em', array(), pht('Not a Hosted Repository')); | : phutil_tag('em', array(), pht('Not a Hosted Repository')); | ||||
$view->addProperty(pht('Pushable By'), $pushable); | $view->addProperty(pht('Pushable By'), $pushable); | ||||
return $this->newBox(pht('Policies'), $view); | $can_edit = PhabricatorPolicyFilter::hasCapability( | ||||
$viewer, | |||||
$repository, | |||||
PhabricatorPolicyCapability::CAN_EDIT); | |||||
$edit_uri = $this->getEditPageURI(); | |||||
$button = id(new PHUIButtonView()) | |||||
->setTag('a') | |||||
->setIcon('fa-pencil') | |||||
->setText(pht('Edit')) | |||||
->setHref($edit_uri) | |||||
->setDisabled(!$can_edit) | |||||
->setWorkflow(!$can_edit); | |||||
return $this->newBox(pht('Policies'), $view, array($button)); | |||||
} | } | ||||
} | } |