mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 01:02:42 +01:00
Conpherence - add an updatethread conduit method
Summary: Last of the methods. Fixes T3166. Test Plan: updated a thread in all the various ways except remove and it worked. removed myself and it worked! tried to remove someone else and it yelled at me. Reviewers: epriestley Reviewed By: epriestley CC: chad, aran, Korvin Maniphest Tasks: T3166 Differential Revision: https://secure.phabricator.com/D6103
This commit is contained in:
parent
569ddd3e78
commit
f4bd214f14
2 changed files with 106 additions and 0 deletions
|
@ -122,6 +122,7 @@ phutil_register_library_map(array(
|
||||||
'ConduitAPI_conpherence_createthread_Method' => 'applications/conpherence/conduit/ConduitAPI_conpherence_createthread_Method.php',
|
'ConduitAPI_conpherence_createthread_Method' => 'applications/conpherence/conduit/ConduitAPI_conpherence_createthread_Method.php',
|
||||||
'ConduitAPI_conpherence_querythread_Method' => 'applications/conpherence/conduit/ConduitAPI_conpherence_querythread_Method.php',
|
'ConduitAPI_conpherence_querythread_Method' => 'applications/conpherence/conduit/ConduitAPI_conpherence_querythread_Method.php',
|
||||||
'ConduitAPI_conpherence_querytransaction_Method' => 'applications/conpherence/conduit/ConduitAPI_conpherence_querytransaction_Method.php',
|
'ConduitAPI_conpherence_querytransaction_Method' => 'applications/conpherence/conduit/ConduitAPI_conpherence_querytransaction_Method.php',
|
||||||
|
'ConduitAPI_conpherence_updatethread_Method' => 'applications/conpherence/conduit/ConduitAPI_conpherence_updatethread_Method.php',
|
||||||
'ConduitAPI_daemon_launched_Method' => 'applications/daemon/conduit/ConduitAPI_daemon_launched_Method.php',
|
'ConduitAPI_daemon_launched_Method' => 'applications/daemon/conduit/ConduitAPI_daemon_launched_Method.php',
|
||||||
'ConduitAPI_daemon_log_Method' => 'applications/daemon/conduit/ConduitAPI_daemon_log_Method.php',
|
'ConduitAPI_daemon_log_Method' => 'applications/daemon/conduit/ConduitAPI_daemon_log_Method.php',
|
||||||
'ConduitAPI_daemon_setstatus_Method' => 'applications/daemon/conduit/ConduitAPI_daemon_setstatus_Method.php',
|
'ConduitAPI_daemon_setstatus_Method' => 'applications/daemon/conduit/ConduitAPI_daemon_setstatus_Method.php',
|
||||||
|
@ -1963,6 +1964,7 @@ phutil_register_library_map(array(
|
||||||
'ConduitAPI_conpherence_createthread_Method' => 'ConduitAPI_conpherence_Method',
|
'ConduitAPI_conpherence_createthread_Method' => 'ConduitAPI_conpherence_Method',
|
||||||
'ConduitAPI_conpherence_querythread_Method' => 'ConduitAPI_conpherence_Method',
|
'ConduitAPI_conpherence_querythread_Method' => 'ConduitAPI_conpherence_Method',
|
||||||
'ConduitAPI_conpherence_querytransaction_Method' => 'ConduitAPI_conpherence_Method',
|
'ConduitAPI_conpherence_querytransaction_Method' => 'ConduitAPI_conpherence_Method',
|
||||||
|
'ConduitAPI_conpherence_updatethread_Method' => 'ConduitAPI_conpherence_Method',
|
||||||
'ConduitAPI_daemon_launched_Method' => 'ConduitAPIMethod',
|
'ConduitAPI_daemon_launched_Method' => 'ConduitAPIMethod',
|
||||||
'ConduitAPI_daemon_log_Method' => 'ConduitAPIMethod',
|
'ConduitAPI_daemon_log_Method' => 'ConduitAPIMethod',
|
||||||
'ConduitAPI_daemon_setstatus_Method' => 'ConduitAPIMethod',
|
'ConduitAPI_daemon_setstatus_Method' => 'ConduitAPIMethod',
|
||||||
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group conduit
|
||||||
|
*/
|
||||||
|
final class ConduitAPI_conpherence_updatethread_Method
|
||||||
|
extends ConduitAPI_conpherence_Method {
|
||||||
|
|
||||||
|
public function getMethodDescription() {
|
||||||
|
return pht('Update an existing conpherence thread.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function defineParamTypes() {
|
||||||
|
return array(
|
||||||
|
'id' => 'optional int',
|
||||||
|
'phid' => 'optional phid',
|
||||||
|
'title' => 'optional string',
|
||||||
|
'message' => 'optional string',
|
||||||
|
'addParticipantPHIDs' => 'optional list<phids>',
|
||||||
|
'removeParticipantPHID' => 'optional phid'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function defineReturnType() {
|
||||||
|
return 'bool';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function defineErrorTypes() {
|
||||||
|
return array(
|
||||||
|
'ERR_USAGE_NO_THREAD_ID' => pht(
|
||||||
|
'You must specify a thread id or thread phid to query transactions '.
|
||||||
|
'from.'),
|
||||||
|
'ERR_USAGE_THREAD_NOT_FOUND' => pht(
|
||||||
|
'Thread does not exist or logged in user can not see it.'),
|
||||||
|
'ERR_USAGE_ONLY_SELF_REMOVE' => pht(
|
||||||
|
'Only a user can remove themselves from a thread.'),
|
||||||
|
'ERR_USAGE_NO_UPDATES' => pht(
|
||||||
|
'You must specify data that actually updates the conpherence.')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(ConduitAPIRequest $request) {
|
||||||
|
$user = $request->getUser();
|
||||||
|
$id = $request->getValue('id');
|
||||||
|
$phid = $request->getValue('phid');
|
||||||
|
$query = id(new ConpherenceThreadQuery())
|
||||||
|
->setViewer($user)
|
||||||
|
->needFilePHIDs(true);
|
||||||
|
if ($id) {
|
||||||
|
$query->withIDs(array($id));
|
||||||
|
} else if ($phid) {
|
||||||
|
$query->withPHIDs(array($phid));
|
||||||
|
} else {
|
||||||
|
throw new ConduitException('ERR_USAGE_NO_THREAD_ID');
|
||||||
|
}
|
||||||
|
$conpherence = $query->executeOne();
|
||||||
|
if (!$conpherence) {
|
||||||
|
throw new ConduitException('ERR_USAGE_THREAD_NOT_FOUND');
|
||||||
|
}
|
||||||
|
|
||||||
|
$source = PhabricatorContentSource::newFromConduitRequest($request);
|
||||||
|
$editor = id(new ConpherenceEditor())
|
||||||
|
->setContentSource($source)
|
||||||
|
->setActor($user);
|
||||||
|
$xactions = array();
|
||||||
|
$add_participant_phids = $request->getValue('addParticipantPHIDs', array());
|
||||||
|
$remove_participant_phid = $request->getValue('removeParticipantPHID');
|
||||||
|
$message = $request->getValue('message');
|
||||||
|
$title = $request->getValue('title');
|
||||||
|
if ($add_participant_phids) {
|
||||||
|
$xactions[] = id(new ConpherenceTransaction())
|
||||||
|
->setTransactionType(
|
||||||
|
ConpherenceTransactionType::TYPE_PARTICIPANTS)
|
||||||
|
->setNewValue(array('+' => $add_participant_phids));
|
||||||
|
}
|
||||||
|
if ($remove_participant_phid) {
|
||||||
|
if ($remove_participant_phid != $user->getPHID()) {
|
||||||
|
throw new ConduitException('ERR_USAGE_ONLY_SELF_REMOVE');
|
||||||
|
}
|
||||||
|
$xactions[] = id(new ConpherenceTransaction())
|
||||||
|
->setTransactionType(
|
||||||
|
ConpherenceTransactionType::TYPE_PARTICIPANTS)
|
||||||
|
->setNewValue(array('-' => array($remove_participant_phid)));
|
||||||
|
}
|
||||||
|
if ($title) {
|
||||||
|
$xactions[] = id(new ConpherenceTransaction())
|
||||||
|
->setTransactionType(ConpherenceTransactionType::TYPE_TITLE)
|
||||||
|
->setNewValue($title);
|
||||||
|
}
|
||||||
|
if ($message) {
|
||||||
|
$xactions = array_merge(
|
||||||
|
$xactions,
|
||||||
|
$editor->generateTransactionsFromText($conpherence, $message));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$xactions = $editor->applyTransactions($conpherence, $xactions);
|
||||||
|
} catch (PhabricatorApplicationTransactionNoEffectException $ex) {
|
||||||
|
throw new ConduitException('ERR_USAGE_NO_UPDATES');
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue