Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editengine/PhabricatorEditEngine.php
Show First 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | /* -( Edit Engine Configuration )------------------------------------------ */ | ||||
protected function supportsEditEngineConfiguration() { | protected function supportsEditEngineConfiguration() { | ||||
return true; | return true; | ||||
} | } | ||||
final protected function getEditEngineConfiguration() { | final protected function getEditEngineConfiguration() { | ||||
return $this->editEngineConfiguration; | return $this->editEngineConfiguration; | ||||
} | } | ||||
/** | |||||
* Load the default configuration, ignoring customization in the database | |||||
* (which means we implicitly ignore policies). | |||||
* | |||||
* This is used from places like Conduit, where the fields available in the | |||||
* API should not be affected by configuration changes. | |||||
* | |||||
* @return PhabricatorEditEngineConfiguration Default configuration, ignoring | |||||
* customization. | |||||
*/ | |||||
private function loadDefaultEditEngineConfiguration() { | |||||
return $this->loadEditEngineConfigurationWithOptions( | |||||
self::EDITENGINECONFIG_DEFAULT, | |||||
true); | |||||
} | |||||
/** | |||||
* Load a named configuration, respecting database customization and policies. | |||||
* | |||||
* @param string Configuration key, or null to load the default. | |||||
* @return PhabricatorEditEngineConfiguration Default configuration, | |||||
* respecting customization. | |||||
*/ | |||||
private function loadEditEngineConfiguration($key) { | private function loadEditEngineConfiguration($key) { | ||||
$viewer = $this->getViewer(); | if (!strlen($key)) { | ||||
if ($key === null) { | |||||
$key = self::EDITENGINECONFIG_DEFAULT; | $key = self::EDITENGINECONFIG_DEFAULT; | ||||
} | |||||
// TODO: At least for now, we need to load the default configuration | return $this->loadEditEngineConfigurationWithOptions( | ||||
// in some cases (editing, comment actions) even if the viewer can not | $key, | ||||
// otherwise see it. This should be cleaned up eventually, but we can | false); | ||||
// safely use the omnipotent user for now without policy violations. | |||||
$viewer = PhabricatorUser::getOmnipotentUser(); | |||||
} | } | ||||
private function loadEditEngineConfigurationWithOptions( | |||||
$key, | |||||
$ignore_database) { | |||||
$viewer = $this->getViewer(); | |||||
$config = id(new PhabricatorEditEngineConfigurationQuery()) | $config = id(new PhabricatorEditEngineConfigurationQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withEngineKeys(array($this->getEngineKey())) | ->withEngineKeys(array($this->getEngineKey())) | ||||
->withIdentifiers(array($key)) | ->withIdentifiers(array($key)) | ||||
->withIgnoreDatabaseConfigurations($ignore_database) | |||||
->executeOne(); | ->executeOne(); | ||||
if (!$config) { | if (!$config) { | ||||
return null; | return null; | ||||
} | } | ||||
$this->editEngineConfiguration = $config; | $this->editEngineConfiguration = $config; | ||||
return $config; | return $config; | ||||
▲ Show 20 Lines • Show All 260 Lines • ▼ Show 20 Lines | private function newObjectFromIdentifier($identifier) { | ||||
return $object; | return $object; | ||||
} | } | ||||
/** | /** | ||||
* Load an object by ID. | * Load an object by ID. | ||||
* | * | ||||
* @param int Object ID. | * @param int Object ID. | ||||
* @param list<const> List of required capability constants, or omit for | |||||
* defaults. | |||||
* @return object|null Object, or null if no such object exists. | * @return object|null Object, or null if no such object exists. | ||||
* @task load | * @task load | ||||
*/ | */ | ||||
private function newObjectFromID($id) { | private function newObjectFromID($id, array $capabilities = array()) { | ||||
$query = $this->newObjectQuery() | $query = $this->newObjectQuery() | ||||
->withIDs(array($id)); | ->withIDs(array($id)); | ||||
return $this->newObjectFromQuery($query); | return $this->newObjectFromQuery($query, $capabilities); | ||||
} | } | ||||
/** | /** | ||||
* Load an object by PHID. | * Load an object by PHID. | ||||
* | * | ||||
* @param phid Object PHID. | * @param phid Object PHID. | ||||
* @return object|null Object, or null if no such object exists. | * @return object|null Object, or null if no such object exists. | ||||
* @task load | * @task load | ||||
*/ | */ | ||||
private function newObjectFromPHID($phid) { | private function newObjectFromPHID($phid) { | ||||
$query = $this->newObjectQuery() | $query = $this->newObjectQuery() | ||||
->withPHIDs(array($phid)); | ->withPHIDs(array($phid)); | ||||
return $this->newObjectFromQuery($query); | return $this->newObjectFromQuery($query); | ||||
} | } | ||||
/** | /** | ||||
* Load an object given a configured query. | * Load an object given a configured query. | ||||
* | * | ||||
* @param PhabricatorPolicyAwareQuery Configured query. | * @param PhabricatorPolicyAwareQuery Configured query. | ||||
* @param list<const> List of required capabilitiy constants, or omit for | |||||
* defaults. | |||||
* @return object|null Object, or null if no such object exists. | * @return object|null Object, or null if no such object exists. | ||||
* @task load | * @task load | ||||
*/ | */ | ||||
private function newObjectFromQuery(PhabricatorPolicyAwareQuery $query) { | private function newObjectFromQuery( | ||||
PhabricatorPolicyAwareQuery $query, | |||||
array $capabilities = array()) { | |||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$object = $query | if (!$capabilities) { | ||||
->setViewer($viewer) | $capabilities = array( | ||||
->requireCapabilities( | |||||
array( | |||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
)) | ); | ||||
} | |||||
$object = $query | |||||
->setViewer($viewer) | |||||
->requireCapabilities($capabilities) | |||||
->executeOne(); | ->executeOne(); | ||||
if (!$object) { | if (!$object) { | ||||
return null; | return null; | ||||
} | } | ||||
return $object; | return $object; | ||||
} | } | ||||
Show All 30 Lines | |||||
/* -( Responding to Web Requests )----------------------------------------- */ | /* -( Responding to Web Requests )----------------------------------------- */ | ||||
final public function buildResponse() { | final public function buildResponse() { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$controller = $this->getController(); | $controller = $this->getController(); | ||||
$request = $controller->getRequest(); | $request = $controller->getRequest(); | ||||
$action = $request->getURIData('editAction'); | |||||
$capabilities = array(); | |||||
$use_default = false; | |||||
switch ($action) { | |||||
case 'comment': | |||||
$capabilities = array( | |||||
PhabricatorPolicyCapability::CAN_VIEW, | |||||
); | |||||
$use_default = true; | |||||
break; | |||||
default: | |||||
break; | |||||
} | |||||
if ($use_default) { | |||||
$config = $this->loadDefaultEditEngineConfiguration(); | |||||
} else { | |||||
$form_key = $request->getURIData('formKey'); | $form_key = $request->getURIData('formKey'); | ||||
$config = $this->loadEditEngineConfiguration($form_key); | $config = $this->loadEditEngineConfiguration($form_key); | ||||
} | |||||
if (!$config) { | if (!$config) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$id = $request->getURIData('id'); | $id = $request->getURIData('id'); | ||||
if ($id) { | if ($id) { | ||||
$this->setIsCreate(false); | $this->setIsCreate(false); | ||||
$object = $this->newObjectFromID($id); | $object = $this->newObjectFromID($id, $capabilities); | ||||
if (!$object) { | if (!$object) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
} else { | } else { | ||||
$this->setIsCreate(true); | $this->setIsCreate(true); | ||||
$object = $this->newEditableObject(); | $object = $this->newEditableObject(); | ||||
} | } | ||||
$this->validateObject($object); | $this->validateObject($object); | ||||
$action = $request->getURIData('editAction'); | |||||
switch ($action) { | switch ($action) { | ||||
case 'parameters': | case 'parameters': | ||||
return $this->buildParametersResponse($object); | return $this->buildParametersResponse($object); | ||||
case 'nodefault': | case 'nodefault': | ||||
return $this->buildNoDefaultResponse($object); | return $this->buildNoDefaultResponse($object); | ||||
case 'comment': | case 'comment': | ||||
return $this->buildCommentResponse($object); | return $this->buildCommentResponse($object); | ||||
default: | default: | ||||
▲ Show 20 Lines • Show All 272 Lines • ▼ Show 20 Lines | final public function addActionToCrumbs(PHUICrumbsView $crumbs) { | ||||
if ($dropdown) { | if ($dropdown) { | ||||
$action->setDropdownMenu($dropdown); | $action->setDropdownMenu($dropdown); | ||||
} | } | ||||
$crumbs->addAction($action); | $crumbs->addAction($action); | ||||
} | } | ||||
final public function buildEditEngineCommentView($object) { | final public function buildEditEngineCommentView($object) { | ||||
$config = $this->loadEditEngineConfiguration(null); | $config = $this->loadDefaultEditEngineConfiguration(); | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$object_phid = $object->getPHID(); | $object_phid = $object->getPHID(); | ||||
$header_text = $this->getCommentViewHeaderText($object); | $header_text = $this->getCommentViewHeaderText($object); | ||||
$button_text = $this->getCommentViewButtonText($object); | $button_text = $this->getCommentViewButtonText($object); | ||||
$comment_uri = $this->getEditURI($object, 'comment/'); | $comment_uri = $this->getEditURI($object, 'comment/'); | ||||
▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | private function buildCommentResponse($object) { | ||||
$controller = $this->getController(); | $controller = $this->getController(); | ||||
$request = $controller->getRequest(); | $request = $controller->getRequest(); | ||||
if (!$request->isFormPost()) { | if (!$request->isFormPost()) { | ||||
return new Aphront400Response(); | return new Aphront400Response(); | ||||
} | } | ||||
$config = $this->loadEditEngineConfiguration(null); | $config = $this->loadDefaultEditEngineConfiguration(); | ||||
$fields = $this->buildEditFields($object); | $fields = $this->buildEditFields($object); | ||||
$is_preview = $request->isPreviewRequest(); | $is_preview = $request->isPreviewRequest(); | ||||
$view_uri = $this->getObjectViewURI($object); | $view_uri = $this->getObjectViewURI($object); | ||||
$template = $object->getApplicationTransactionTemplate(); | $template = $object->getApplicationTransactionTemplate(); | ||||
$comment_template = $template->getApplicationTransactionCommentObject(); | $comment_template = $template->getApplicationTransactionCommentObject(); | ||||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | /* -( Conduit )------------------------------------------------------------ */ | ||||
* This method accepts a list of transactions to apply to an object, and | * This method accepts a list of transactions to apply to an object, and | ||||
* either edits an existing object or creates a new one. | * either edits an existing object or creates a new one. | ||||
* | * | ||||
* @task conduit | * @task conduit | ||||
*/ | */ | ||||
final public function buildConduitResponse(ConduitAPIRequest $request) { | final public function buildConduitResponse(ConduitAPIRequest $request) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$config = $this->loadEditEngineConfiguration(null); | $config = $this->loadDefaultEditEngineConfiguration(); | ||||
if (!$config) { | if (!$config) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Unable to load configuration for this EditEngine ("%s").', | 'Unable to load configuration for this EditEngine ("%s").', | ||||
get_class($this))); | get_class($this))); | ||||
} | } | ||||
$identifier = $request->getValue('objectIdentifier'); | $identifier = $request->getValue('objectIdentifier'); | ||||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | foreach ($fields as $field) { | ||||
$field_type->setField($field); | $field_type->setField($field); | ||||
$types[$field_type->getEditType()] = $field_type; | $types[$field_type->getEditType()] = $field_type; | ||||
} | } | ||||
} | } | ||||
return $types; | return $types; | ||||
} | } | ||||
public function getConduitEditTypes() { | public function getConduitEditTypes() { | ||||
$config = $this->loadEditEngineConfiguration(null); | $config = $this->loadDefaultEditEngineConfiguration(); | ||||
if (!$config) { | if (!$config) { | ||||
return array(); | return array(); | ||||
} | } | ||||
$object = $this->newEditableObject(); | $object = $this->newEditableObject(); | ||||
$fields = $this->buildEditFields($object); | $fields = $this->buildEditFields($object); | ||||
return $this->getConduitEditTypesFromFields($fields); | return $this->getConduitEditTypesFromFields($fields); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines |