Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14005030
D10097.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D10097.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1062,6 +1062,7 @@
'PasteCreateConduitAPIMethod' => 'applications/paste/conduit/PasteCreateConduitAPIMethod.php',
'PasteCreateMailReceiver' => 'applications/paste/mail/PasteCreateMailReceiver.php',
'PasteDefaultViewCapability' => 'applications/paste/capability/PasteDefaultViewCapability.php',
+ 'PasteEditConduitAPIMethod' => 'applications/paste/conduit/PasteEditConduitAPIMethod.php',
'PasteEmbedView' => 'applications/paste/view/PasteEmbedView.php',
'PasteInfoConduitAPIMethod' => 'applications/paste/conduit/PasteInfoConduitAPIMethod.php',
'PasteMockMailReceiver' => 'applications/paste/mail/PasteMockMailReceiver.php',
@@ -3851,6 +3852,7 @@
'PasteCreateConduitAPIMethod' => 'PasteConduitAPIMethod',
'PasteCreateMailReceiver' => 'PhabricatorMailReceiver',
'PasteDefaultViewCapability' => 'PhabricatorPolicyCapability',
+ 'PasteEditConduitAPIMethod' => 'PasteConduitAPIMethod',
'PasteEmbedView' => 'AphrontView',
'PasteInfoConduitAPIMethod' => 'PasteConduitAPIMethod',
'PasteMockMailReceiver' => 'PhabricatorObjectMailReceiver',
diff --git a/src/applications/paste/conduit/PasteEditConduitAPIMethod.php b/src/applications/paste/conduit/PasteEditConduitAPIMethod.php
new file mode 100644
--- /dev/null
+++ b/src/applications/paste/conduit/PasteEditConduitAPIMethod.php
@@ -0,0 +1,102 @@
+<?php
+
+final class PasteEditConduitAPIMethod extends PasteConduitAPIMethod {
+
+ public function getAPIMethodName() {
+ return 'paste.edit';
+ }
+
+ public function getMethodDescription() {
+ return 'Edit a paste.';
+ }
+
+ public function defineParamTypes() {
+ return array(
+ 'content' => 'required string',
+ 'paste_id' => 'required id',
+ 'title' => 'optional string',
+ 'language' => 'optional string',
+ );
+ }
+
+ public function defineReturnType() {
+ return 'nonempty dict';
+ }
+
+ public function defineErrorTypes() {
+ return array(
+ 'ERR-NO-PASTE' => 'Paste may not be empty.',
+ 'ERR-NO-ACCESS' => 'You do not have permission to edit this paste.',
+ 'ERR-BAD-PASTE' => 'No such paste exists',
+ );
+ }
+
+ protected function execute(ConduitAPIRequest $request) {
+ $content = $request->getValue('content');
+ $title = $request->getValue('title');
+ $language = $request->getValue('language');
+ $paste_id = $request->getValue('paste_id');
+
+ if (!strlen($content)) {
+ throw new ConduitException('ERR-NO-PASTE');
+ }
+
+ $viewer = $request->getUser();
+
+ try {
+ $paste = id(new PhabricatorPasteQuery())
+ ->setViewer($request->getUser())
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ PhabricatorPolicyCapability::CAN_EDIT,
+ ))
+ ->withIDs(array($paste_id))
+ ->needRawContent(true)
+ ->executeOne();
+ } catch (PhabricatorPolicyException $ex) {
+ throw new ConduitException('ERR-NO-ACCESS');
+ }
+
+ if (!$paste) {
+ throw new ConduitException('ERR-BAD-PASTE');
+ }
+
+ $xactions = array();
+
+ if ($content != $paste->getRawContent()) {
+ $file = PhabricatorPasteEditor::initializeFileForPaste(
+ $viewer,
+ $title,
+ $content);
+
+ $xactions[] = id(new PhabricatorPasteTransaction())
+ ->setTransactionType(PhabricatorPasteTransaction::TYPE_CONTENT)
+ ->setNewValue($file->getPHID());
+ }
+
+ if ($title && $title != $paste->getTitle()) {
+ $xactions[] = id(new PhabricatorPasteTransaction())
+ ->setTransactionType(PhabricatorPasteTransaction::TYPE_TITLE)
+ ->setNewValue($title);
+ }
+
+ if ($language && $language != $paste->getLanguage()) {
+ $xactions[] = id(new PhabricatorPasteTransaction())
+ ->setTransactionType(PhabricatorPasteTransaction::TYPE_LANGUAGE)
+ ->setNewValue($language);
+ }
+
+ if (count($xactions) > 0) {
+ $editor = id(new PhabricatorPasteEditor())
+ ->setActor($viewer)
+ ->setContentSourceFromConduitRequest($request);
+
+ $xactions = $editor->applyTransactions($paste, $xactions);
+
+ $paste->attachRawContent($content);
+ }
+ return $this->buildPasteInfoDictionary($paste);
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Oct 28, 6:32 AM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6716153
Default Alt Text
D10097.diff (4 KB)
Attached To
Mode
D10097: Allow pastes to be edited from conduit call.
Attached
Detach File
Event Timeline
Log In to Comment