Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editengine/PhabricatorEditEngine.php
| Show First 20 Lines • Show All 192 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; | ||||
| } | } | ||||
| private function newConfigurationQuery() { | |||||
| return id(new PhabricatorEditEngineConfigurationQuery()) | |||||
| ->setViewer($this->getViewer()) | |||||
| ->withEngineKeys(array($this->getEngineKey())); | |||||
| } | |||||
| /** | private function loadEditEngineConfigurationWithQuery( | ||||
| * Load the default configuration, ignoring customization in the database | PhabricatorEditEngineConfigurationQuery $query, | ||||
| * (which means we implicitly ignore policies). | $sort_method) { | ||||
| * | |||||
| * This is used from places like Conduit, where the fields available in the | if ($sort_method) { | ||||
| * API should not be affected by configuration changes. | $results = $query->execute(); | ||||
| * | $results = msort($results, $sort_method); | ||||
| * @return PhabricatorEditEngineConfiguration Default configuration, ignoring | $result = head($results); | ||||
| * customization. | } else { | ||||
| */ | $result = $query->executeOne(); | ||||
| private function loadDefaultEditEngineConfiguration() { | |||||
| return $this->loadEditEngineConfigurationWithOptions( | |||||
| self::EDITENGINECONFIG_DEFAULT, | |||||
| true); | |||||
| } | } | ||||
| if (!$result) { | |||||
| return null; | |||||
| } | |||||
| /** | $this->editEngineConfiguration = $result; | ||||
| * Load a named configuration, respecting database customization and policies. | return $result; | ||||
| * | |||||
| * @param string Configuration key, or null to load the default. | |||||
| * @return PhabricatorEditEngineConfiguration Default configuration, | |||||
| * respecting customization. | |||||
| */ | |||||
| private function loadEditEngineConfiguration($key) { | |||||
| if (!strlen($key)) { | |||||
| $key = self::EDITENGINECONFIG_DEFAULT; | |||||
| } | } | ||||
| return $this->loadEditEngineConfigurationWithOptions( | private function loadEditEngineConfigurationWithIdentifier($identifier) { | ||||
| $key, | $query = $this->newConfigurationQuery() | ||||
| false); | ->withIdentifiers(array($identifier)); | ||||
| return $this->loadEditEngineConfigurationWithQuery($query, null); | |||||
| } | } | ||||
| private function loadEditEngineConfigurationWithOptions( | private function loadDefaultConfiguration() { | ||||
| $key, | $query = $this->newConfigurationQuery() | ||||
| $ignore_database) { | ->withIdentifiers( | ||||
| $viewer = $this->getViewer(); | array( | ||||
| self::EDITENGINECONFIG_DEFAULT, | |||||
| )) | |||||
| ->withIgnoreDatabaseConfigurations(true); | |||||
| $config = id(new PhabricatorEditEngineConfigurationQuery()) | return $this->loadEditEngineConfigurationWithQuery($query, null); | ||||
| ->setViewer($viewer) | |||||
| ->withEngineKeys(array($this->getEngineKey())) | |||||
| ->withIdentifiers(array($key)) | |||||
| ->withIgnoreDatabaseConfigurations($ignore_database) | |||||
| ->executeOne(); | |||||
| if (!$config) { | |||||
| return null; | |||||
| } | } | ||||
| $this->editEngineConfiguration = $config; | private function loadDefaultCreateConfiguration() { | ||||
| $query = $this->newConfigurationQuery() | |||||
| ->withIsDefault(true) | |||||
| ->withIsDisabled(false); | |||||
| return $this->loadEditEngineConfigurationWithQuery( | |||||
| $query, | |||||
| 'getCreateSortKey'); | |||||
| } | |||||
| private function loadDefaultEditConfiguration() { | |||||
| $query = $this->newConfigurationQuery() | |||||
| ->withIsEdit(true) | |||||
| ->withIsDisabled(false); | |||||
| return $config; | return $this->loadEditEngineConfigurationWithQuery( | ||||
| $query, | |||||
| 'getEditSortKey'); | |||||
| } | } | ||||
| final public function getBuiltinEngineConfigurations() { | final public function getBuiltinEngineConfigurations() { | ||||
| $configurations = $this->newBuiltinEngineConfigurations(); | $configurations = $this->newBuiltinEngineConfigurations(); | ||||
| if (!$configurations) { | if (!$configurations) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| Show All 11 Lines | foreach ($configurations as $config) { | ||||
| } | } | ||||
| } | } | ||||
| if (!$has_default) { | if (!$has_default) { | ||||
| $first = head($configurations); | $first = head($configurations); | ||||
| if (!$first->getBuiltinKey()) { | if (!$first->getBuiltinKey()) { | ||||
| $first | $first | ||||
| ->setBuiltinKey(self::EDITENGINECONFIG_DEFAULT) | ->setBuiltinKey(self::EDITENGINECONFIG_DEFAULT) | ||||
| ->setIsDefault(true); | ->setIsDefault(true) | ||||
| ->setIsEdit(true); | |||||
| if (!strlen($first->getName())) { | if (!strlen($first->getName())) { | ||||
| $first->setName($this->getObjectCreateShortText()); | $first->setName($this->getObjectCreateShortText()); | ||||
| } | } | ||||
| } else { | } else { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'EditEngine ("%s") returned builtin engine configurations, '. | 'EditEngine ("%s") returned builtin engine configurations, '. | ||||
| ▲ Show 20 Lines • Show All 353 Lines • ▼ Show 20 Lines | switch ($action) { | ||||
| case 'nocreate': | case 'nocreate': | ||||
| case 'nomanage': | case 'nomanage': | ||||
| $require_create = false; | $require_create = false; | ||||
| break; | break; | ||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| if ($use_default) { | |||||
| $config = $this->loadDefaultEditEngineConfiguration(); | |||||
| } else { | |||||
| $form_key = $request->getURIData('formKey'); | |||||
| $config = $this->loadEditEngineConfiguration($form_key); | |||||
| } | |||||
| if (!$config) { | |||||
| 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, $capabilities); | $object = $this->newObjectFromID($id, $capabilities); | ||||
| if (!$object) { | if (!$object) { | ||||
| return new Aphront404Response(); | return new Aphront404Response(); | ||||
| } | } | ||||
| } else { | } else { | ||||
| // Make sure the viewer has permission to create new objects of | // Make sure the viewer has permission to create new objects of | ||||
| // this type if we're going to create a new object. | // this type if we're going to create a new object. | ||||
| if ($require_create) { | if ($require_create) { | ||||
| $this->requireCreateCapability(); | $this->requireCreateCapability(); | ||||
| } | } | ||||
| $this->setIsCreate(true); | $this->setIsCreate(true); | ||||
| $object = $this->newEditableObject(); | $object = $this->newEditableObject(); | ||||
| } | } | ||||
| $this->validateObject($object); | $this->validateObject($object); | ||||
| if ($use_default) { | |||||
| $config = $this->loadDefaultConfiguration(); | |||||
| if (!$config) { | |||||
| return new Aphront404Response(); | |||||
| } | |||||
| } else { | |||||
| $form_key = $request->getURIData('formKey'); | |||||
| if (strlen($form_key)) { | |||||
| $config = $this->loadEditEngineConfigurationWithIdentifier($form_key); | |||||
| if (!$config) { | |||||
| return new Aphront404Response(); | |||||
| } | |||||
| if ($id && !$config->getIsEdit()) { | |||||
| return $this->buildNotEditFormRespose($object, $config); | |||||
| } | |||||
| } else { | |||||
| if ($id) { | |||||
| $config = $this->loadDefaultEditConfiguration(); | |||||
| if (!$config) { | |||||
| return $this->buildNoEditResponse($object); | |||||
| } | |||||
| } else { | |||||
| $config = $this->loadDefaultCreateConfiguration(); | |||||
| if (!$config) { | |||||
| return $this->buildNoCreateResponse($object); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| if ($config->getIsDisabled()) { | |||||
| return $this->buildFormDisabledResponse($object, $config); | |||||
| } | |||||
| 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 'nocreate': | case 'nocreate': | ||||
| return $this->buildNoCreateResponse($object); | return $this->buildNoCreateResponse($object); | ||||
| case 'nomanage': | case 'nomanage': | ||||
| ▲ Show 20 Lines • Show All 337 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->loadDefaultEditEngineConfiguration(); | $config = $this->loadDefaultConfiguration(); | ||||
| $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 97 Lines • ▼ Show 20 Lines | private function buildParametersResponse($object) { | ||||
| return $controller->newPage() | return $controller->newPage() | ||||
| ->setTitle(pht('HTTP Parameters')) | ->setTitle(pht('HTTP Parameters')) | ||||
| ->setCrumbs($crumbs) | ->setCrumbs($crumbs) | ||||
| ->appendChild($document); | ->appendChild($document); | ||||
| } | } | ||||
| private function buildNoDefaultResponse($object) { | private function buildError($object, $title, $body) { | ||||
| $cancel_uri = $this->getObjectCreateCancelURI($object); | $cancel_uri = $this->getObjectCreateCancelURI($object); | ||||
| return $this->getController() | return $this->getController() | ||||
| ->newDialog() | ->newDialog() | ||||
| ->setTitle(pht('No Default Create Forms')) | ->setTitle($title) | ||||
| ->appendParagraph( | ->appendParagraph($body) | ||||
| pht( | |||||
| 'This application is not configured with any visible, enabled '. | |||||
| 'forms for creating objects.')) | |||||
| ->addCancelButton($cancel_uri); | ->addCancelButton($cancel_uri); | ||||
| } | } | ||||
| private function buildNoCreateResponse($object) { | |||||
| $cancel_uri = $this->getObjectCreateCancelURI($object); | |||||
| return $this->getController() | private function buildNoDefaultResponse($object) { | ||||
| ->newDialog() | return $this->buildError( | ||||
| ->setTitle(pht('No Create Permission')) | $object, | ||||
| ->appendParagraph( | pht('No Default Create Forms'), | ||||
| pht( | pht( | ||||
| 'You do not have permission to create these objects.')) | 'This application is not configured with any forms for creating '. | ||||
| ->addCancelButton($cancel_uri); | 'objects that are visible to you and enabled.')); | ||||
| } | } | ||||
| private function buildNoManageResponse($object) { | private function buildNoCreateResponse($object) { | ||||
| $cancel_uri = $this->getObjectCreateCancelURI($object); | return $this->buildError( | ||||
| $object, | |||||
| pht('No Create Permission'), | |||||
| pht('You do not have permission to create these objects.')); | |||||
| } | |||||
| return $this->getController() | private function buildNoManageResponse($object) { | ||||
| ->newDialog() | return $this->buildError( | ||||
| ->setTitle(pht('No Manage Permission')) | $object, | ||||
| ->appendParagraph( | pht('No Manage Permission'), | ||||
| pht( | pht( | ||||
| 'You do not have permission to configure forms for this '. | 'You do not have permission to configure forms for this '. | ||||
| 'application.')) | 'application.')); | ||||
| ->addCancelButton($cancel_uri); | } | ||||
| private function buildNoEditResponse($object) { | |||||
| return $this->buildError( | |||||
| $object, | |||||
| pht('No Edit Forms'), | |||||
| pht( | |||||
| 'You do not have access to any forms which are enabled and marked '. | |||||
| 'as edit forms.')); | |||||
| } | |||||
| private function buildNotEditFormRespose($object, $config) { | |||||
| return $this->buildError( | |||||
| $object, | |||||
| pht('Not an Edit Form'), | |||||
| pht( | |||||
| 'This form ("%s") is not marked as an edit form, so '. | |||||
| 'it can not be used to edit objects.', | |||||
| $config->getName())); | |||||
| } | |||||
| private function buildDisabledFormResponse($object, $config) { | |||||
| return $this->buildError( | |||||
| $object, | |||||
| pht('Form Disabled'), | |||||
| pht( | |||||
| 'This form ("%s") has been disabled, so it can not be used.', | |||||
| $config->getName())); | |||||
| } | } | ||||
| private function buildCommentResponse($object) { | private function buildCommentResponse($object) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| if ($this->getIsCreate()) { | if ($this->getIsCreate()) { | ||||
| return new Aphront404Response(); | return new Aphront404Response(); | ||||
| } | } | ||||
| $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->loadDefaultEditEngineConfiguration(); | $config = $this->loadDefaultConfiguration(); | ||||
| $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->loadDefaultEditEngineConfiguration(); | $config = $this->loadDefaultConfiguration(); | ||||
| 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 131 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->loadDefaultEditEngineConfiguration(); | $config = $this->loadDefaultConfiguration(); | ||||
| 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 128 Lines • Show Last 20 Lines | |||||