mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-01 03:02:43 +01:00
4489204361
Summary: Ref T2015. Allow configuration of default edit/view policies for blueprints. Add create policy. Remove administrative exception in policies. Test Plan: Configured these settings and created (or, with a restrictive create setting, tried to create) blueprints. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2015 Differential Revision: https://secure.phabricator.com/D7921
88 lines
2.3 KiB
PHP
88 lines
2.3 KiB
PHP
<?php
|
|
|
|
final class DrydockBlueprint extends DrydockDAO
|
|
implements PhabricatorPolicyInterface {
|
|
|
|
protected $className;
|
|
protected $blueprintName;
|
|
protected $viewPolicy;
|
|
protected $editPolicy;
|
|
protected $details = array();
|
|
|
|
private $implementation = self::ATTACHABLE;
|
|
|
|
public static function initializeNewBlueprint(PhabricatorUser $actor) {
|
|
$app = id(new PhabricatorApplicationQuery())
|
|
->setViewer($actor)
|
|
->withClasses(array('PhabricatorApplicationDrydock'))
|
|
->executeOne();
|
|
|
|
$view_policy = $app->getPolicy(
|
|
DrydockCapabilityDefaultView::CAPABILITY);
|
|
$edit_policy = $app->getPolicy(
|
|
DrydockCapabilityDefaultEdit::CAPABILITY);
|
|
|
|
return id(new DrydockBlueprint())
|
|
->setViewPolicy($view_policy)
|
|
->setEditPolicy($edit_policy)
|
|
->setBlueprintName('');
|
|
}
|
|
|
|
public function getConfiguration() {
|
|
return array(
|
|
self::CONFIG_AUX_PHID => true,
|
|
self::CONFIG_SERIALIZATION => array(
|
|
'details' => self::SERIALIZATION_JSON,
|
|
)
|
|
) + parent::getConfiguration();
|
|
}
|
|
|
|
public function generatePHID() {
|
|
return PhabricatorPHID::generateNewPHID(
|
|
DrydockPHIDTypeBlueprint::TYPECONST);
|
|
}
|
|
|
|
public function getImplementation() {
|
|
$class = $this->className;
|
|
$implementations =
|
|
DrydockBlueprintImplementation::getAllBlueprintImplementations();
|
|
if (!isset($implementations[$class])) {
|
|
throw new Exception(
|
|
"Invalid class name for blueprint (got '".$class."')");
|
|
}
|
|
return id(new $class())->attachInstance($this);
|
|
}
|
|
|
|
public function attachImplementation(DrydockBlueprintImplementation $impl) {
|
|
$this->implementation = $impl;
|
|
return $this;
|
|
}
|
|
|
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
|
public function getCapabilities() {
|
|
return array(
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
);
|
|
}
|
|
|
|
public function getPolicy($capability) {
|
|
switch ($capability) {
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
|
return $this->getViewPolicy();
|
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
|
return $this->getEditPolicy();
|
|
}
|
|
}
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
return false;
|
|
}
|
|
|
|
public function describeAutomaticCapability($capability) {
|
|
return null;
|
|
}
|
|
}
|