Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/storage/AlmanacService.php
<?php | <?php | ||||
final class AlmanacService | final class AlmanacService | ||||
extends AlmanacDAO | extends AlmanacDAO | ||||
implements | implements | ||||
PhabricatorPolicyInterface, | PhabricatorPolicyInterface, | ||||
PhabricatorApplicationTransactionInterface, | PhabricatorApplicationTransactionInterface, | ||||
PhabricatorProjectInterface, | PhabricatorProjectInterface, | ||||
AlmanacPropertyInterface, | AlmanacPropertyInterface, | ||||
PhabricatorDestructibleInterface, | PhabricatorDestructibleInterface, | ||||
PhabricatorNgramsInterface, | PhabricatorNgramsInterface, | ||||
PhabricatorConduitResultInterface { | PhabricatorConduitResultInterface, | ||||
PhabricatorExtendedPolicyInterface { | |||||
protected $name; | protected $name; | ||||
protected $nameIndex; | protected $nameIndex; | ||||
protected $mailKey; | protected $mailKey; | ||||
protected $viewPolicy; | protected $viewPolicy; | ||||
protected $editPolicy; | protected $editPolicy; | ||||
protected $serviceClass; | protected $serviceClass; | ||||
protected $isLocked; | |||||
private $almanacProperties = self::ATTACHABLE; | private $almanacProperties = self::ATTACHABLE; | ||||
private $bindings = self::ATTACHABLE; | private $bindings = self::ATTACHABLE; | ||||
private $serviceType = self::ATTACHABLE; | private $serviceType = self::ATTACHABLE; | ||||
public static function initializeNewService() { | public static function initializeNewService() { | ||||
return id(new AlmanacService()) | return id(new AlmanacService()) | ||||
->setViewPolicy(PhabricatorPolicies::POLICY_USER) | ->setViewPolicy(PhabricatorPolicies::POLICY_USER) | ||||
->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN) | ->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN) | ||||
->attachAlmanacProperties(array()) | ->attachAlmanacProperties(array()); | ||||
->setIsLocked(0); | |||||
} | } | ||||
protected function getConfiguration() { | protected function getConfiguration() { | ||||
return array( | return array( | ||||
self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
self::CONFIG_COLUMN_SCHEMA => array( | self::CONFIG_COLUMN_SCHEMA => array( | ||||
'name' => 'text128', | 'name' => 'text128', | ||||
'nameIndex' => 'bytes12', | 'nameIndex' => 'bytes12', | ||||
'mailKey' => 'bytes20', | 'mailKey' => 'bytes20', | ||||
'serviceClass' => 'text64', | 'serviceClass' => 'text64', | ||||
'isLocked' => 'bool', | |||||
), | ), | ||||
self::CONFIG_KEY_SCHEMA => array( | self::CONFIG_KEY_SCHEMA => array( | ||||
'key_name' => array( | 'key_name' => array( | ||||
'columns' => array('nameIndex'), | 'columns' => array('nameIndex'), | ||||
'unique' => true, | 'unique' => true, | ||||
), | ), | ||||
'key_nametext' => array( | 'key_nametext' => array( | ||||
'columns' => array('name'), | 'columns' => array('name'), | ||||
Show All 38 Lines | public function getServiceType() { | ||||
return $this->assertAttached($this->serviceType); | return $this->assertAttached($this->serviceType); | ||||
} | } | ||||
public function attachServiceType(AlmanacServiceType $type) { | public function attachServiceType(AlmanacServiceType $type) { | ||||
$this->serviceType = $type; | $this->serviceType = $type; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function isClusterService() { | |||||
return $this->getServiceType()->isClusterServiceType(); | |||||
} | |||||
/* -( AlmanacPropertyInterface )------------------------------------------- */ | /* -( AlmanacPropertyInterface )------------------------------------------- */ | ||||
public function attachAlmanacProperties(array $properties) { | public function attachAlmanacProperties(array $properties) { | ||||
assert_instances_of($properties, 'AlmanacProperty'); | assert_instances_of($properties, 'AlmanacProperty'); | ||||
$this->almanacProperties = mpull($properties, null, 'getFieldName'); | $this->almanacProperties = mpull($properties, null, 'getFieldName'); | ||||
return $this; | return $this; | ||||
Show All 39 Lines | public function getCapabilities() { | ||||
); | ); | ||||
} | } | ||||
public function getPolicy($capability) { | public function getPolicy($capability) { | ||||
switch ($capability) { | switch ($capability) { | ||||
case PhabricatorPolicyCapability::CAN_VIEW: | case PhabricatorPolicyCapability::CAN_VIEW: | ||||
return $this->getViewPolicy(); | return $this->getViewPolicy(); | ||||
case PhabricatorPolicyCapability::CAN_EDIT: | case PhabricatorPolicyCapability::CAN_EDIT: | ||||
if ($this->getIsLocked()) { | |||||
return PhabricatorPolicies::POLICY_NOONE; | |||||
} else { | |||||
return $this->getEditPolicy(); | return $this->getEditPolicy(); | ||||
} | } | ||||
} | } | ||||
} | |||||
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { | public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { | ||||
return false; | return false; | ||||
} | } | ||||
public function describeAutomaticCapability($capability) { | public function describeAutomaticCapability($capability) { | ||||
return null; | |||||
} | |||||
/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */ | |||||
public function getExtendedPolicy($capability, PhabricatorUser $viewer) { | |||||
switch ($capability) { | switch ($capability) { | ||||
case PhabricatorPolicyCapability::CAN_EDIT: | case PhabricatorPolicyCapability::CAN_EDIT: | ||||
if ($this->getIsLocked()) { | if ($this->isClusterService()) { | ||||
return pht('This service is locked and can not be edited.'); | return array( | ||||
array( | |||||
new PhabricatorAlmanacApplication(), | |||||
AlmanacManageClusterServicesCapability::CAPABILITY, | |||||
), | |||||
); | |||||
} | } | ||||
break; | break; | ||||
} | } | ||||
return null; | return array(); | ||||
} | } | ||||
/* -( PhabricatorApplicationTransactionInterface )------------------------- */ | /* -( PhabricatorApplicationTransactionInterface )------------------------- */ | ||||
public function getApplicationTransactionEditor() { | public function getApplicationTransactionEditor() { | ||||
return new AlmanacServiceEditor(); | return new AlmanacServiceEditor(); | ||||
▲ Show 20 Lines • Show All 75 Lines • Show Last 20 Lines |