mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 12:00:55 +01:00
Phriction - add "create" conduit endpoint
Summary: Fixes T6262. Ref T4029. Also gets us ready for T5873 for these end points. I can file something new about someday adding phriction.query, etc but I think we'll remember and can look at that post T5873. Test Plan: made a document via conduit and it worked! Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T6262, T4029 Differential Revision: https://secure.phabricator.com/D10813
This commit is contained in:
parent
b538611e29
commit
6db25aa41c
3 changed files with 81 additions and 3 deletions
|
@ -2762,6 +2762,7 @@ phutil_register_library_map(array(
|
|||
'PhrictionConstants' => 'applications/phriction/constants/PhrictionConstants.php',
|
||||
'PhrictionContent' => 'applications/phriction/storage/PhrictionContent.php',
|
||||
'PhrictionController' => 'applications/phriction/controller/PhrictionController.php',
|
||||
'PhrictionCreateConduitAPIMethod' => 'applications/phriction/conduit/PhrictionCreateConduitAPIMethod.php',
|
||||
'PhrictionDAO' => 'applications/phriction/storage/PhrictionDAO.php',
|
||||
'PhrictionDeleteController' => 'applications/phriction/controller/PhrictionDeleteController.php',
|
||||
'PhrictionDiffController' => 'applications/phriction/controller/PhrictionDiffController.php',
|
||||
|
@ -5966,6 +5967,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorMarkupInterface',
|
||||
),
|
||||
'PhrictionController' => 'PhabricatorController',
|
||||
'PhrictionCreateConduitAPIMethod' => 'PhrictionConduitAPIMethod',
|
||||
'PhrictionDAO' => 'PhabricatorLiskDAO',
|
||||
'PhrictionDeleteController' => 'PhrictionController',
|
||||
'PhrictionDiffController' => 'PhrictionController',
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
final class PhrictionCreateConduitAPIMethod extends PhrictionConduitAPIMethod {
|
||||
public function getAPIMethodName() {
|
||||
return 'phriction.create';
|
||||
}
|
||||
public function getMethodDescription() {
|
||||
return pht('Create a Phriction document.');
|
||||
}
|
||||
public function defineParamTypes() {
|
||||
return array(
|
||||
'slug' => 'required string',
|
||||
'title' => 'required string',
|
||||
'content' => 'required string',
|
||||
'description' => 'optional string',
|
||||
);
|
||||
}
|
||||
public function defineReturnType() {
|
||||
return 'nonempty dict';
|
||||
}
|
||||
public function defineErrorTypes() {
|
||||
return array(
|
||||
);
|
||||
}
|
||||
protected function execute(ConduitAPIRequest $request) {
|
||||
$slug = $request->getValue('slug');
|
||||
if (!strlen($slug)) {
|
||||
throw new Exception(pht('No such document.'));
|
||||
}
|
||||
$doc = id(new PhrictionDocumentQuery())
|
||||
->setViewer($request->getUser())
|
||||
->withSlugs(array(PhabricatorSlug::normalize($slug)))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
))
|
||||
->executeOne();
|
||||
if ($doc) {
|
||||
throw new Exception(pht('Document already exists!'));
|
||||
}
|
||||
|
||||
$doc = PhrictionDocument::initializeNewDocument(
|
||||
$request->getUser(),
|
||||
$slug);
|
||||
|
||||
$xactions = array();
|
||||
$xactions[] = id(new PhrictionTransaction())
|
||||
->setTransactionType(PhrictionTransaction::TYPE_TITLE)
|
||||
->setNewValue($request->getValue('title'));
|
||||
$xactions[] = id(new PhrictionTransaction())
|
||||
->setTransactionType(PhrictionTransaction::TYPE_CONTENT)
|
||||
->setNewValue($request->getValue('content'));
|
||||
|
||||
$editor = id(new PhrictionTransactionEditor())
|
||||
->setActor($request->getUser())
|
||||
->setContentSourceFromConduitRequest($request)
|
||||
->setContinueOnNoEffect(true)
|
||||
->setDescription($request->getValue('description'));
|
||||
|
||||
try {
|
||||
$editor->applyTransactions($doc, $xactions);
|
||||
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
||||
// TODO - some magical hotness via T5873
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
return $this->buildDocumentInfoDictionary($doc);
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ final class PhrictionEditConduitAPIMethod extends PhrictionConduitAPIMethod {
|
|||
}
|
||||
|
||||
public function getMethodDescription() {
|
||||
return 'Update a Phriction document.';
|
||||
return pht('Update a Phriction document.');
|
||||
}
|
||||
|
||||
public function defineParamTypes() {
|
||||
|
@ -57,8 +57,14 @@ final class PhrictionEditConduitAPIMethod extends PhrictionConduitAPIMethod {
|
|||
->setActor($request->getUser())
|
||||
->setContentSourceFromConduitRequest($request)
|
||||
->setContinueOnNoEffect(true)
|
||||
->setDescription($request->getValue('description'))
|
||||
->applyTransactions($doc, $xactions);
|
||||
->setDescription($request->getValue('description'));
|
||||
|
||||
try {
|
||||
$editor->applyTransactions($doc, $xactions);
|
||||
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
||||
// TODO - some magical hotness via T5873
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
return $this->buildDocumentInfoDictionary($doc);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue