mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-26 13:39:08 +01:00
Summary: Ref T4896. Replaces more custom stuff with standard stuff. In particular: - No more fake proxy writes; - no more fake detection of `@mentions`. For now, the old code still applies most of the effects and handles feed and email. Test Plan: - Added comments. - Added comments with inline comments. - Added just inline comments. - Added comments with Conduit. - Previewed comments. - Added CCs explicitly and with `@mentions`. - Added auditors. - Accepted a commit. Reviewers: joshuaspence, btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4896 Differential Revision: https://secure.phabricator.com/D10109
88 lines
2.6 KiB
PHP
88 lines
2.6 KiB
PHP
<?php
|
|
|
|
final class PhabricatorAuditPreviewController
|
|
extends PhabricatorAuditController {
|
|
|
|
private $id;
|
|
|
|
public function willProcessRequest(array $data) {
|
|
$this->id = $data['id'];
|
|
}
|
|
|
|
public function processRequest() {
|
|
$request = $this->getRequest();
|
|
$user = $request->getUser();
|
|
|
|
$commit = id(new PhabricatorRepositoryCommit())->load($this->id);
|
|
if (!$commit) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
$xactions = array();
|
|
|
|
$action = $request->getStr('action');
|
|
if ($action != PhabricatorAuditActionConstants::COMMENT) {
|
|
$action_xaction = id(new PhabricatorAuditTransaction())
|
|
->setAuthorPHID($user->getPHID())
|
|
->setObjectPHID($commit->getPHID())
|
|
->setTransactionType(PhabricatorAuditActionConstants::ACTION)
|
|
->setNewValue($action);
|
|
|
|
$auditors = $request->getStrList('auditors');
|
|
if ($action == PhabricatorAuditActionConstants::ADD_AUDITORS &&
|
|
$auditors) {
|
|
$action_xaction->setTransactionType($action);
|
|
$action_xaction->setNewValue(array_fuse($auditors));
|
|
}
|
|
|
|
$ccs = $request->getStrList('ccs');
|
|
if ($action == PhabricatorAuditActionConstants::ADD_CCS && $ccs) {
|
|
$action_xaction->setTransactionType(
|
|
PhabricatorTransactions::TYPE_SUBSCRIBERS);
|
|
|
|
// NOTE: This doesn't get processed before use, so just provide fake
|
|
// values.
|
|
$action_xaction->setOldValue(array());
|
|
$action_xaction->setNewValue($ccs);
|
|
}
|
|
|
|
$xactions[] = $action_xaction;
|
|
}
|
|
|
|
$content = $request->getStr('content');
|
|
if (strlen($content)) {
|
|
$xactions[] = id(new PhabricatorAuditTransaction())
|
|
->setAuthorPHID($user->getPHID())
|
|
->setObjectPHID($commit->getPHID())
|
|
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
|
->attachComment(
|
|
id(new PhabricatorAuditTransactionComment())
|
|
->setContent($content));
|
|
}
|
|
|
|
$phids = array();
|
|
foreach ($xactions as $xaction) {
|
|
$phids[] = $xaction->getRequiredHandlePHIDs();
|
|
}
|
|
$phids = array_mergev($phids);
|
|
$handles = $this->loadViewerHandles($phids);
|
|
foreach ($xactions as $xaction) {
|
|
$xaction->setHandles($handles);
|
|
}
|
|
|
|
$view = id(new PhabricatorAuditTransactionView())
|
|
->setIsPreview(true)
|
|
->setUser($user)
|
|
->setObjectPHID($commit->getPHID())
|
|
->setTransactions($xactions);
|
|
|
|
id(new PhabricatorDraft())
|
|
->setAuthorPHID($user->getPHID())
|
|
->setDraftKey('diffusion-audit-'.$this->id)
|
|
->setDraft($content)
|
|
->replaceOrDelete();
|
|
|
|
return id(new AphrontAjaxResponse())->setContent(hsprintf('%s', $view));
|
|
}
|
|
|
|
}
|