mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-01 09:28:22 +01:00
75c3598359
Summary: See <https://discourse.phabricator-community.org/t/cannot-audit-a-git-commit/2848>. In D20581, I made some audit behavior dependent upon identities, but the actual edit flow doesn't load them. This can cause us to raise an "attach identities first" exception in the bowels of the edit workflow and trigger unexpected behavior at top level. Load identities when editing a commit so that the transaction flows have access to identity information and can use it to figure out if a user is an author, etc. Test Plan: - As an auditor, applied an "Accept Commit" action to an open audit after D20581. - Before patch: accept no-ops internally since the preconditions throw. - After patch: accept works properly. Reviewers: amckinley Reviewed By: amckinley Differential Revision: https://secure.phabricator.com/D20612
180 lines
4.8 KiB
PHP
180 lines
4.8 KiB
PHP
<?php
|
|
|
|
final class DiffusionCommitEditEngine
|
|
extends PhabricatorEditEngine {
|
|
|
|
const ENGINECONST = 'diffusion.commit';
|
|
|
|
const ACTIONGROUP_AUDIT = 'audit';
|
|
const ACTIONGROUP_COMMIT = 'commit';
|
|
|
|
public function isEngineConfigurable() {
|
|
return false;
|
|
}
|
|
|
|
public function getEngineName() {
|
|
return pht('Commits');
|
|
}
|
|
|
|
public function getSummaryHeader() {
|
|
return pht('Edit Commits');
|
|
}
|
|
|
|
public function getSummaryText() {
|
|
return pht('Edit commits.');
|
|
}
|
|
|
|
public function getEngineApplicationClass() {
|
|
return 'PhabricatorDiffusionApplication';
|
|
}
|
|
|
|
protected function newEditableObject() {
|
|
// NOTE: We must return a valid object here so that things like Conduit
|
|
// documentation generation work. You can't actually create commits via
|
|
// EditEngine. This is enforced with a "No One" creation policy.
|
|
|
|
$repository = new PhabricatorRepository();
|
|
$data = new PhabricatorRepositoryCommitData();
|
|
|
|
return id(new PhabricatorRepositoryCommit())
|
|
->attachRepository($repository)
|
|
->attachCommitData($data)
|
|
->attachAudits(array());
|
|
}
|
|
|
|
protected function newObjectQuery() {
|
|
$viewer = $this->getViewer();
|
|
|
|
return id(new DiffusionCommitQuery())
|
|
->needCommitData(true)
|
|
->needAuditRequests(true)
|
|
->needAuditAuthority(array($viewer))
|
|
->needIdentities(true);
|
|
}
|
|
|
|
protected function getEditorURI() {
|
|
return $this->getApplication()->getApplicationURI('commit/edit/');
|
|
}
|
|
|
|
protected function newCommentActionGroups() {
|
|
return array(
|
|
id(new PhabricatorEditEngineCommentActionGroup())
|
|
->setKey(self::ACTIONGROUP_AUDIT)
|
|
->setLabel(pht('Audit Actions')),
|
|
id(new PhabricatorEditEngineCommentActionGroup())
|
|
->setKey(self::ACTIONGROUP_COMMIT)
|
|
->setLabel(pht('Commit Actions')),
|
|
);
|
|
}
|
|
|
|
protected function getObjectCreateTitleText($object) {
|
|
return pht('Create Commit');
|
|
}
|
|
|
|
protected function getObjectCreateShortText() {
|
|
return pht('Create Commit');
|
|
}
|
|
|
|
protected function getObjectEditTitleText($object) {
|
|
return pht('Edit Commit: %s', $object->getDisplayName());
|
|
}
|
|
|
|
protected function getObjectEditShortText($object) {
|
|
return $object->getDisplayName();
|
|
}
|
|
|
|
protected function getObjectName() {
|
|
return pht('Commit');
|
|
}
|
|
|
|
protected function getObjectViewURI($object) {
|
|
return $object->getURI();
|
|
}
|
|
|
|
protected function getCreateNewObjectPolicy() {
|
|
return PhabricatorPolicies::POLICY_NOONE;
|
|
}
|
|
|
|
protected function buildCustomEditFields($object) {
|
|
$viewer = $this->getViewer();
|
|
$data = $object->getCommitData();
|
|
|
|
$fields = array();
|
|
|
|
$fields[] = id(new PhabricatorDatasourceEditField())
|
|
->setKey('auditors')
|
|
->setLabel(pht('Auditors'))
|
|
->setDatasource(new DiffusionAuditorDatasource())
|
|
->setUseEdgeTransactions(true)
|
|
->setTransactionType(
|
|
DiffusionCommitAuditorsTransaction::TRANSACTIONTYPE)
|
|
->setCommentActionLabel(pht('Change Auditors'))
|
|
->setDescription(pht('Auditors for this commit.'))
|
|
->setConduitDescription(pht('Change the auditors for this commit.'))
|
|
->setConduitTypeDescription(pht('New auditors.'))
|
|
->setValue($object->getAuditorPHIDsForEdit());
|
|
|
|
$actions = DiffusionCommitActionTransaction::loadAllActions();
|
|
$actions = msortv($actions, 'getCommitActionOrderVector');
|
|
|
|
foreach ($actions as $key => $action) {
|
|
$fields[] = $action->newEditField($object, $viewer);
|
|
}
|
|
|
|
return $fields;
|
|
}
|
|
|
|
protected function newAutomaticCommentTransactions($object) {
|
|
$viewer = $this->getViewer();
|
|
$xactions = array();
|
|
|
|
$inlines = PhabricatorAuditInlineComment::loadDraftComments(
|
|
$viewer,
|
|
$object->getPHID(),
|
|
$raw = true);
|
|
$inlines = msort($inlines, 'getID');
|
|
|
|
$editor = $object->getApplicationTransactionEditor()
|
|
->setActor($viewer);
|
|
|
|
$query_template = id(new DiffusionDiffInlineCommentQuery())
|
|
->withCommitPHIDs(array($object->getPHID()));
|
|
|
|
$xactions = $editor->newAutomaticInlineTransactions(
|
|
$object,
|
|
$inlines,
|
|
PhabricatorAuditActionConstants::INLINE,
|
|
$query_template);
|
|
|
|
return $xactions;
|
|
}
|
|
|
|
protected function newCommentPreviewContent($object, array $xactions) {
|
|
$viewer = $this->getViewer();
|
|
$type_inline = PhabricatorAuditActionConstants::INLINE;
|
|
|
|
$inlines = array();
|
|
foreach ($xactions as $xaction) {
|
|
if ($xaction->getTransactionType() === $type_inline) {
|
|
$inlines[] = $xaction->getComment();
|
|
}
|
|
}
|
|
|
|
$content = array();
|
|
|
|
if ($inlines) {
|
|
$inline_preview = id(new PHUIDiffInlineCommentPreviewListView())
|
|
->setViewer($viewer)
|
|
->setInlineComments($inlines);
|
|
|
|
$content[] = phutil_tag(
|
|
'div',
|
|
array(
|
|
'id' => 'inline-comment-preview',
|
|
),
|
|
$inline_preview);
|
|
}
|
|
|
|
return $content;
|
|
}
|
|
}
|