Differential D14700 Diff 35556 src/applications/transactions/storage/PhabricatorEditEngineConfiguration.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/storage/PhabricatorEditEngineConfiguration.php
<?php | <?php | ||||
final class PhabricatorEditEngineConfiguration | final class PhabricatorEditEngineConfiguration | ||||
extends PhabricatorSearchDAO | extends PhabricatorSearchDAO | ||||
implements | implements | ||||
PhabricatorApplicationTransactionInterface, | PhabricatorApplicationTransactionInterface, | ||||
PhabricatorPolicyInterface { | PhabricatorPolicyInterface { | ||||
protected $engineKey; | protected $engineKey; | ||||
protected $builtinKey; | protected $builtinKey; | ||||
protected $name; | protected $name; | ||||
protected $viewPolicy; | protected $viewPolicy; | ||||
protected $editPolicy; | |||||
protected $properties = array(); | protected $properties = array(); | ||||
protected $isDisabled = 0; | protected $isDisabled = 0; | ||||
protected $isDefault = 0; | protected $isDefault = 0; | ||||
protected $isEdit = 0; | |||||
protected $createOrder = 0; | |||||
protected $editOrder = 0; | |||||
private $engine = self::ATTACHABLE; | private $engine = self::ATTACHABLE; | ||||
const LOCK_VISIBLE = 'visible'; | const LOCK_VISIBLE = 'visible'; | ||||
const LOCK_LOCKED = 'locked'; | const LOCK_LOCKED = 'locked'; | ||||
const LOCK_HIDDEN = 'hidden'; | const LOCK_HIDDEN = 'hidden'; | ||||
public function getTableName() { | public function getTableName() { | ||||
return 'search_editengineconfiguration'; | return 'search_editengineconfiguration'; | ||||
} | } | ||||
public static function initializeNewConfiguration( | public static function initializeNewConfiguration( | ||||
PhabricatorUser $actor, | PhabricatorUser $actor, | ||||
PhabricatorEditEngine $engine) { | PhabricatorEditEngine $engine) { | ||||
// TODO: This should probably be controlled by a new default capability. | |||||
$edit_policy = PhabricatorPolicies::POLICY_ADMIN; | |||||
return id(new PhabricatorEditEngineConfiguration()) | return id(new PhabricatorEditEngineConfiguration()) | ||||
->setEngineKey($engine->getEngineKey()) | ->setEngineKey($engine->getEngineKey()) | ||||
->attachEngine($engine) | ->attachEngine($engine) | ||||
->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()) | ->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()); | ||||
->setEditPolicy($edit_policy); | |||||
} | } | ||||
public function generatePHID() { | public function generatePHID() { | ||||
return PhabricatorPHID::generateNewPHID( | return PhabricatorPHID::generateNewPHID( | ||||
PhabricatorEditEngineConfigurationPHIDType::TYPECONST); | PhabricatorEditEngineConfigurationPHIDType::TYPECONST); | ||||
} | } | ||||
public function getCreateSortKey() { | |||||
return $this->getSortKey($this->createOrder); | |||||
} | |||||
public function getEditSortKey() { | |||||
return $this->getSortKey($this->editOrder); | |||||
} | |||||
private function getSortKey($order) { | |||||
// Put objects at the bottom by default if they haven't previously been | |||||
// reordered. When they're explicitly reordered, the smallest sort key we | |||||
// assign is 1, so if the object has a value of 0 it means it hasn't been | |||||
// ordered yet. | |||||
if ($order != 0) { | |||||
$group = 'A'; | |||||
} else { | |||||
$group = 'B'; | |||||
} | |||||
return sprintf( | |||||
"%s%012d%s\0%012d", | |||||
chadUnsubmitted Not Done Inline Actionschad: {F1017416} | |||||
$group, | |||||
$order, | |||||
$this->getName(), | |||||
$this->getID()); | |||||
} | |||||
protected function getConfiguration() { | protected function getConfiguration() { | ||||
return array( | return array( | ||||
self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
self::CONFIG_SERIALIZATION => array( | self::CONFIG_SERIALIZATION => array( | ||||
'properties' => self::SERIALIZATION_JSON, | 'properties' => self::SERIALIZATION_JSON, | ||||
), | ), | ||||
self::CONFIG_COLUMN_SCHEMA => array( | self::CONFIG_COLUMN_SCHEMA => array( | ||||
'engineKey' => 'text64', | 'engineKey' => 'text64', | ||||
'builtinKey' => 'text64?', | 'builtinKey' => 'text64?', | ||||
'name' => 'text255', | 'name' => 'text255', | ||||
'isDisabled' => 'bool', | 'isDisabled' => 'bool', | ||||
'isDefault' => 'bool', | 'isDefault' => 'bool', | ||||
'isEdit' => 'bool', | |||||
'createOrder' => 'uint32', | |||||
'editOrder' => 'uint32', | |||||
), | ), | ||||
self::CONFIG_KEY_SCHEMA => array( | self::CONFIG_KEY_SCHEMA => array( | ||||
'key_engine' => array( | 'key_engine' => array( | ||||
'columns' => array('engineKey', 'builtinKey'), | 'columns' => array('engineKey', 'builtinKey'), | ||||
'unique' => true, | 'unique' => true, | ||||
), | ), | ||||
'key_default' => array( | 'key_default' => array( | ||||
'columns' => array('engineKey', 'isDefault', 'isDisabled'), | 'columns' => array('engineKey', 'isDefault', 'isDisabled'), | ||||
), | ), | ||||
'key_edit' => array( | |||||
'columns' => array('engineKey', 'isEdit', 'isDisabled'), | |||||
), | |||||
), | ), | ||||
) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
} | } | ||||
public function getProperty($key, $default = null) { | public function getProperty($key, $default = null) { | ||||
return idx($this->properties, $key, $default); | return idx($this->properties, $key, $default); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 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: | ||||
return $this->getEditPolicy(); | return $this->getEngine() | ||||
->getApplication() | |||||
->getPolicy($capability); | |||||
} | } | ||||
} | } | ||||
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { | public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { | ||||
switch ($capability) { | |||||
case PhabricatorPolicyCapability::CAN_VIEW: | |||||
return PhabricatorPolicyFilter::hasCapability( | |||||
$viewer, | |||||
$this->getEngine()->getApplication(), | |||||
PhabricatorPolicyCapability::CAN_EDIT); | |||||
} | |||||
return false; | return false; | ||||
} | } | ||||
public function describeAutomaticCapability($capability) { | public function describeAutomaticCapability($capability) { | ||||
return null; | return null; | ||||
} | } | ||||
Show All 22 Lines |