Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editengine/PhabricatorEditEngine.php
| Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | foreach ($extensions as $extension) { | ||||
| assert_instances_of($extension_fields, 'PhabricatorEditField'); | assert_instances_of($extension_fields, 'PhabricatorEditField'); | ||||
| foreach ($extension_fields as $field) { | foreach ($extension_fields as $field) { | ||||
| $fields[] = $field; | $fields[] = $field; | ||||
| } | } | ||||
| } | } | ||||
| $config = $this->getEditEngineConfiguration(); | $config = $this->getEditEngineConfiguration(); | ||||
| $fields = $config->applyConfigurationToFields($this, $fields); | $fields = $config->applyConfigurationToFields($this, $object, $fields); | ||||
| foreach ($fields as $field) { | foreach ($fields as $field) { | ||||
| $field | $field | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->setObject($object); | ->setObject($object); | ||||
| } | } | ||||
| return $fields; | return $fields; | ||||
| ▲ Show 20 Lines • Show All 331 Lines • ▼ Show 20 Lines | /* -( Creating and Loading Objects )--------------------------------------- */ | ||||
| } | } | ||||
| /** | /** | ||||
| * Try to load an object by ID, PHID, or monogram. This is done primarily | * Try to load an object by ID, PHID, or monogram. This is done primarily | ||||
| * to make Conduit a little easier to use. | * to make Conduit a little easier to use. | ||||
| * | * | ||||
| * @param wild ID, PHID, or monogram. | * @param wild ID, PHID, or monogram. | ||||
| * @param list<const> List of required capability constants, or omit for | |||||
| * defaults. | |||||
| * @return object Corresponding editable object. | * @return object Corresponding editable object. | ||||
| * @task load | * @task load | ||||
| */ | */ | ||||
| private function newObjectFromIdentifier($identifier) { | private function newObjectFromIdentifier( | ||||
| $identifier, | |||||
| array $capabilities = array()) { | |||||
| if (is_int($identifier) || ctype_digit($identifier)) { | if (is_int($identifier) || ctype_digit($identifier)) { | ||||
| $object = $this->newObjectFromID($identifier); | $object = $this->newObjectFromID($identifier, $capabilities); | ||||
| if (!$object) { | if (!$object) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'No object exists with ID "%s".', | 'No object exists with ID "%s".', | ||||
| $identifier)); | $identifier)); | ||||
| } | } | ||||
| return $object; | return $object; | ||||
| } | } | ||||
| $type_unknown = PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN; | $type_unknown = PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN; | ||||
| if (phid_get_type($identifier) != $type_unknown) { | if (phid_get_type($identifier) != $type_unknown) { | ||||
| $object = $this->newObjectFromPHID($identifier); | $object = $this->newObjectFromPHID($identifier, $capabilities); | ||||
| if (!$object) { | if (!$object) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'No object exists with PHID "%s".', | 'No object exists with PHID "%s".', | ||||
| $identifier)); | $identifier)); | ||||
| } | } | ||||
| Show All 24 Lines | if ($expect_class !== $target_class) { | ||||
| $target_class, | $target_class, | ||||
| $expect_class)); | $expect_class)); | ||||
| } | } | ||||
| // Load the object by PHID using this engine's standard query. This makes | // Load the object by PHID using this engine's standard query. This makes | ||||
| // sure it's really valid, goes through standard policy check logic, and | // sure it's really valid, goes through standard policy check logic, and | ||||
| // picks up any `need...()` clauses we want it to load with. | // picks up any `need...()` clauses we want it to load with. | ||||
| $object = $this->newObjectFromPHID($target->getPHID()); | $object = $this->newObjectFromPHID($target->getPHID(), $capabilities); | ||||
| if (!$object) { | if (!$object) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Failed to reload object identified by monogram "%s" when '. | 'Failed to reload object identified by monogram "%s" when '. | ||||
| 'querying by PHID.', | 'querying by PHID.', | ||||
| $identifier)); | $identifier)); | ||||
| } | } | ||||
| Show All 16 Lines | private function newObjectFromID($id, array $capabilities = array()) { | ||||
| return $this->newObjectFromQuery($query, $capabilities); | return $this->newObjectFromQuery($query, $capabilities); | ||||
| } | } | ||||
| /** | /** | ||||
| * Load an object by PHID. | * Load an object by PHID. | ||||
| * | * | ||||
| * @param phid Object PHID. | * @param phid Object PHID. | ||||
| * @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 newObjectFromPHID($phid) { | private function newObjectFromPHID($phid, array $capabilities = array()) { | ||||
| $query = $this->newObjectQuery() | $query = $this->newObjectQuery() | ||||
| ->withPHIDs(array($phid)); | ->withPHIDs(array($phid)); | ||||
| return $this->newObjectFromQuery($query); | return $this->newObjectFromQuery($query, $capabilities); | ||||
| } | } | ||||
| /** | /** | ||||
| * 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 | * @param list<const> List of required capabilitiy constants, or omit for | ||||
| ▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | final public function buildResponse() { | ||||
| $use_default = false; | $use_default = false; | ||||
| switch ($action) { | switch ($action) { | ||||
| case 'comment': | case 'comment': | ||||
| $capabilities = array( | $capabilities = array( | ||||
| PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
| ); | ); | ||||
| $use_default = true; | $use_default = true; | ||||
| break; | break; | ||||
| case 'parameters': | |||||
| $use_default = true; | |||||
| break; | |||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| if ($use_default) { | if ($use_default) { | ||||
| $config = $this->loadDefaultEditEngineConfiguration(); | $config = $this->loadDefaultEditEngineConfiguration(); | ||||
| } else { | } else { | ||||
| $form_key = $request->getURIData('formKey'); | $form_key = $request->getURIData('formKey'); | ||||
| ▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | if ($request->isFormPost()) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| $field->setControlError($message); | $field->setControlError($message); | ||||
| } | } | ||||
| } | } | ||||
| } else { | } else { | ||||
| if ($this->getIsCreate()) { | if ($this->getIsCreate()) { | ||||
| $template = $request->getStr('template'); | |||||
| if (strlen($template)) { | |||||
| $template_object = $this->newObjectFromIdentifier( | |||||
| $template, | |||||
| array( | |||||
| PhabricatorPolicyCapability::CAN_VIEW, | |||||
| )); | |||||
| if (!$template_object) { | |||||
| return new Aphront404Response(); | |||||
| } | |||||
| } else { | |||||
| $template_object = null; | |||||
| } | |||||
| if ($template_object) { | |||||
| $copy_fields = $this->buildEditFields($template_object); | |||||
| $copy_fields = mpull($copy_fields, null, 'getKey'); | |||||
| foreach ($copy_fields as $copy_key => $copy_field) { | |||||
| if (!$copy_field->getIsCopyable()) { | |||||
| unset($copy_fields[$copy_key]); | |||||
| } | |||||
| } | |||||
| } else { | |||||
| $copy_fields = array(); | |||||
| } | |||||
| foreach ($fields as $field) { | foreach ($fields as $field) { | ||||
| if ($field->getIsLocked() || $field->getIsHidden()) { | if ($field->getIsLocked() || $field->getIsHidden()) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| $field_key = $field->getKey(); | |||||
| if (isset($copy_fields[$field_key])) { | |||||
| $field->readValueFromField($copy_fields[$field_key]); | |||||
| } | |||||
| $field->readValueFromRequest($request); | $field->readValueFromRequest($request); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| $action_button = $this->buildEditFormActionButton($object); | $action_button = $this->buildEditFormActionButton($object); | ||||
| if ($this->getIsCreate()) { | if ($this->getIsCreate()) { | ||||
| ▲ Show 20 Lines • Show All 684 Lines • Show Last 20 Lines | |||||