From 5bf28498c87d90c67def0a83a8e4530b98497607 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 17 Aug 2011 15:19:48 -0700 Subject: [PATCH] Provide a basic maniphest.createtask method via Conduit Summary: This could be a lot fancier but let's see what else we need. Also fixed some bugs with maniphest.info. Test Plan: Used the Conduit web console to create some tasks with different values. Reviewers: jungejason, tuomaspelkonen, aran Reviewed By: jungejason CC: aran, jungejason, epriestley Differential Revision: 824 --- src/__phutil_library_map__.php | 6 +- .../base/ConduitAPI_maniphest_Method.php | 51 +++++++++ .../method/maniphest/base/__init__.php | 16 +++ ...ConduitAPI_maniphest_createtask_Method.php | 107 ++++++++++++++++++ .../method/maniphest/createtask/__init__.php | 19 ++++ .../info/ConduitAPI_maniphest_info_Method.php | 28 +---- .../method/maniphest/info/__init__.php | 4 +- 7 files changed, 203 insertions(+), 28 deletions(-) create mode 100644 src/applications/conduit/method/maniphest/base/ConduitAPI_maniphest_Method.php create mode 100644 src/applications/conduit/method/maniphest/base/__init__.php create mode 100644 src/applications/conduit/method/maniphest/createtask/ConduitAPI_maniphest_createtask_Method.php create mode 100644 src/applications/conduit/method/maniphest/createtask/__init__.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 91f516ff78..e30db127a6 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -112,6 +112,8 @@ phutil_register_library_map(array( 'ConduitAPI_file_download_Method' => 'applications/conduit/method/file/download', 'ConduitAPI_file_info_Method' => 'applications/conduit/method/file/info', 'ConduitAPI_file_upload_Method' => 'applications/conduit/method/file/upload', + 'ConduitAPI_maniphest_Method' => 'applications/conduit/method/maniphest/base', + 'ConduitAPI_maniphest_createtask_Method' => 'applications/conduit/method/maniphest/createtask', 'ConduitAPI_maniphest_info_Method' => 'applications/conduit/method/maniphest/info', 'ConduitAPI_paste_Method' => 'applications/conduit/method/paste/base', 'ConduitAPI_paste_create_Method' => 'applications/conduit/method/paste/create', @@ -782,7 +784,9 @@ phutil_register_library_map(array( 'ConduitAPI_file_download_Method' => 'ConduitAPIMethod', 'ConduitAPI_file_info_Method' => 'ConduitAPIMethod', 'ConduitAPI_file_upload_Method' => 'ConduitAPIMethod', - 'ConduitAPI_maniphest_info_Method' => 'ConduitAPIMethod', + 'ConduitAPI_maniphest_Method' => 'ConduitAPIMethod', + 'ConduitAPI_maniphest_createtask_Method' => 'ConduitAPI_maniphest_Method', + 'ConduitAPI_maniphest_info_Method' => 'ConduitAPI_maniphest_Method', 'ConduitAPI_paste_Method' => 'ConduitAPIMethod', 'ConduitAPI_paste_create_Method' => 'ConduitAPI_paste_Method', 'ConduitAPI_paste_info_Method' => 'ConduitAPI_paste_Method', diff --git a/src/applications/conduit/method/maniphest/base/ConduitAPI_maniphest_Method.php b/src/applications/conduit/method/maniphest/base/ConduitAPI_maniphest_Method.php new file mode 100644 index 0000000000..d825a3baa9 --- /dev/null +++ b/src/applications/conduit/method/maniphest/base/ConduitAPI_maniphest_Method.php @@ -0,0 +1,51 @@ +loadAuxiliaryAttributes(); + $auxiliary = mpull($auxiliary, 'getValue', 'getName'); + + $result = array( + 'id' => $task->getID(), + 'phid' => $task->getPHID(), + 'authorPHID' => $task->getAuthorPHID(), + 'ownerPHID' => $task->getOwnerPHID(), + 'ccPHIDs' => $task->getCCPHIDs(), + 'status' => $task->getStatus(), + 'priority' => ManiphestTaskPriority::getTaskPriorityName( + $task->getPriority()), + 'title' => $task->getTitle(), + 'description' => $task->getDescription(), + 'projectPHIDs' => $task->getProjectPHIDs(), + 'uri' => PhabricatorEnv::getProductionURI('/T'.$task->getID()), + 'auxiliary' => $auxiliary, + + 'objectName' => 'T'.$task->getID(), + 'dateCreated' => $task->getDateCreated(), + 'dateModified' => $task->getDateModified(), + ); + + return $result; + } + +} diff --git a/src/applications/conduit/method/maniphest/base/__init__.php b/src/applications/conduit/method/maniphest/base/__init__.php new file mode 100644 index 0000000000..ee28a563bd --- /dev/null +++ b/src/applications/conduit/method/maniphest/base/__init__.php @@ -0,0 +1,16 @@ + 'required string', + 'description' => 'optional string', + 'ownerPHID' => 'optional phid', + 'ccPHIDs' => 'optional list', + 'priority' => 'optional int', + 'projectPHIDs' => 'optional list', + 'filePHIDs' => 'optional list', + ); + } + + public function defineReturnType() { + return 'nonempty dict'; + } + + public function defineErrorTypes() { + return array( + ); + } + + protected function execute(ConduitAPIRequest $request) { + $task = new ManiphestTask(); + $task->setPriority(ManiphestTaskPriority::PRIORITY_TRIAGE); + $task->setAuthorPHID($request->getUser()->getPHID()); + + $task->setTitle((string)$request->getValue('title')); + $task->setDescription((string)$request->getValue('description')); + + $changes = array(); + $changes[ManiphestTransactionType::TYPE_STATUS] = + ManiphestTaskStatus::STATUS_OPEN; + + $priority = $request->getValue('priority'); + if ($priority !== null) { + $changes[ManiphestTransactionType::TYPE_PRIORITY] = $priority; + } + + $owner_phid = $request->getValue('ownerPHID'); + if ($owner_phid !== null) { + $changes[ManiphestTransactionType::TYPE_OWNER] = $owner_phid; + } + + $ccs = $request->getValue('ccPHIDs'); + if ($ccs !== null) { + $changes[ManiphestTransactionType::TYPE_CCS] = $ccs; + } + + $project_phids = $request->getValue('projectPHIDs'); + if ($project_phids !== null) { + $changes[ManiphestTransactionType::TYPE_PROJECTS] = $project_phids; + } + + $file_phids = $request->getValue('filePHIDs'); + if ($file_phids !== null) { + $file_map = array_fill_keys($file_phids, true); + $changes[ManiphestTransactionType::TYPE_ATTACH] = array( + PhabricatorPHIDConstants::PHID_TYPE_FILE => $file_map, + ); + } + + $template = new ManiphestTransaction(); + $template->setAuthorPHID($request->getUser()->getPHID()); + + $transactions = array(); + foreach ($changes as $type => $value) { + $transaction = clone $template; + $transaction->setTransactionType($type); + $transaction->setNewValue($value); + $transactions[] = $transaction; + } + + $editor = new ManiphestTransactionEditor(); + $editor->applyTransactions($task, $transactions); + + return $this->buildTaskInfoDictionary($task); + } + +} diff --git a/src/applications/conduit/method/maniphest/createtask/__init__.php b/src/applications/conduit/method/maniphest/createtask/__init__.php new file mode 100644 index 0000000000..26dcd306c8 --- /dev/null +++ b/src/applications/conduit/method/maniphest/createtask/__init__.php @@ -0,0 +1,19 @@ +loadAuxiliaryAttributes(); - $auxiliary = mpull($auxiliary, 'getValue', 'getName'); - - $result = array( - 'id' => $task->getID(), - 'phid' => $task->getPHID(), - 'authorPHID' => $task->getAuthorPHID(), - 'ownerPHID' => $task->getAuthorPHID(), - 'ccPHIDs' => $task->getCCPHIDs(), - 'status' => $task->getStatus(), - 'priority' => ManiphestTaskPriority::getTaskPriorityName( - $task->getPriority()), - 'title' => $task->getTitle(), - 'description' => $task->getDescription(), - 'projectPHIDs' => $task->getProjectPHIDs(), - 'uri' => PhabricatorEnv::getProductionURI('/T'.$task->getID()), - - 'auxiliary' => $auxiliary, - - // Not sure what this is yet. - // 'attached' => array($task->getAttached()), - ); - return $result; + return $this->buildTaskInfoDictionary($task); } } diff --git a/src/applications/conduit/method/maniphest/info/__init__.php b/src/applications/conduit/method/maniphest/info/__init__.php index f6d47f4ece..61475ad914 100644 --- a/src/applications/conduit/method/maniphest/info/__init__.php +++ b/src/applications/conduit/method/maniphest/info/__init__.php @@ -6,11 +6,9 @@ -phutil_require_module('phabricator', 'applications/conduit/method/base'); +phutil_require_module('phabricator', 'applications/conduit/method/maniphest/base'); phutil_require_module('phabricator', 'applications/conduit/protocol/exception'); -phutil_require_module('phabricator', 'applications/maniphest/constants/priority'); phutil_require_module('phabricator', 'applications/maniphest/storage/task'); -phutil_require_module('phabricator', 'infrastructure/env'); phutil_require_module('phutil', 'utils');