Page MenuHomePhabricator

D10123.id24350.diff
No OneTemporary

D10123.id24350.diff

diff --git a/src/applications/audit/controller/PhabricatorAuditAddCommentController.php b/src/applications/audit/controller/PhabricatorAuditAddCommentController.php
--- a/src/applications/audit/controller/PhabricatorAuditAddCommentController.php
+++ b/src/applications/audit/controller/PhabricatorAuditAddCommentController.php
@@ -15,6 +15,7 @@
$commit = id(new DiffusionCommitQuery())
->setViewer($user)
->withPHIDs(array($commit_phid))
+ ->needAuditRequests(true)
->executeOne();
if (!$commit) {
return new Aphront404Response();
@@ -31,10 +32,7 @@
$auditors = $request->getArr('auditors');
$comments[] = id(new PhabricatorAuditComment())
->setAction(PhabricatorAuditActionConstants::ADD_AUDITORS)
- ->setMetadata(
- array(
- PhabricatorAuditComment::METADATA_ADDED_AUDITORS => $auditors,
- ));
+ ->setNewValue(array_fuse($auditors));
break;
case PhabricatorAuditActionConstants::ADD_CCS:
$comments[] = id(new PhabricatorAuditComment())
diff --git a/src/applications/audit/editor/PhabricatorAuditCommentEditor.php b/src/applications/audit/editor/PhabricatorAuditCommentEditor.php
--- a/src/applications/audit/editor/PhabricatorAuditCommentEditor.php
+++ b/src/applications/audit/editor/PhabricatorAuditCommentEditor.php
@@ -47,10 +47,7 @@
$audit_phids = self::loadAuditPHIDsForUser($actor);
$audit_phids = array_fill_keys($audit_phids, true);
- $requests = id(new PhabricatorRepositoryAuditRequest())
- ->loadAllWhere(
- 'commitPHID = %s',
- $commit->getPHID());
+ $requests = $commit->getAudits();
// TODO: We should validate the action, currently we allow anyone to, e.g.,
// close an audit if they muck with form parameters. I'll followup with this
@@ -182,38 +179,6 @@
}
}
- $auditors = array();
-
- foreach ($comments as $comment) {
- $meta = $comment->getMetadata();
-
- $auditor_phids = idx(
- $meta,
- PhabricatorAuditComment::METADATA_ADDED_AUDITORS,
- array());
- foreach ($auditor_phids as $phid) {
- $auditors[] = $phid;
- }
- }
-
- $requests_by_auditor = mpull($requests, null, 'getAuditorPHID');
- $requests_phids = array_keys($requests_by_auditor);
-
- $auditors = array_diff($auditors, $requests_phids);
-
- if ($auditors) {
- foreach ($auditors as $auditor_phid) {
- $audit_requested = PhabricatorAuditStatusConstants::AUDIT_REQUESTED;
- $requests[] = id (new PhabricatorRepositoryAuditRequest())
- ->setCommitPHID($commit->getPHID())
- ->setAuditorPHID($auditor_phid)
- ->setAuditStatus($audit_requested)
- ->setAuditReasons(
- array('Added by '.$actor->getUsername()))
- ->save();
- }
- }
-
$commit->updateAuditStatus($requests);
$commit->save();
diff --git a/src/applications/audit/editor/PhabricatorAuditEditor.php b/src/applications/audit/editor/PhabricatorAuditEditor.php
--- a/src/applications/audit/editor/PhabricatorAuditEditor.php
+++ b/src/applications/audit/editor/PhabricatorAuditEditor.php
@@ -86,7 +86,42 @@
case PhabricatorAuditActionConstants::INLINE:
return;
case PhabricatorAuditActionConstants::ADD_AUDITORS:
- // TODO: For now, these are applied externally.
+ $new = $xaction->getNewValue();
+ if (!is_array($new)) {
+ $new = array();
+ }
+
+ $old = $xaction->getOldValue();
+ if (!is_array($old)) {
+ $old = array();
+ }
+
+ $add = array_diff_key($new, $old);
+
+ $actor = $this->requireActor();
+
+ $requests = $object->getAudits();
+ $requests = mpull($requests, null, 'getAuditorPHID');
+ foreach ($add as $phid) {
+ if (isset($requests[$phid])) {
+ continue;
+ }
+
+ $audit_requested = PhabricatorAuditStatusConstants::AUDIT_REQUESTED;
+ $requests[] = id (new PhabricatorRepositoryAuditRequest())
+ ->setCommitPHID($object->getPHID())
+ ->setAuditorPHID($phid)
+ ->setAuditStatus($audit_requested)
+ ->setAuditReasons(
+ array(
+ 'Added by '.$actor->getUsername(),
+ ))
+ ->save();
+ }
+
+ $object->updateAuditStatus($requests);
+ $object->attachAudits($requests);
+ $object->save();
return;
}
diff --git a/src/applications/audit/mail/PhabricatorAuditMailReceiver.php b/src/applications/audit/mail/PhabricatorAuditMailReceiver.php
--- a/src/applications/audit/mail/PhabricatorAuditMailReceiver.php
+++ b/src/applications/audit/mail/PhabricatorAuditMailReceiver.php
@@ -17,6 +17,7 @@
return id(new DiffusionCommitQuery())
->setViewer($viewer)
->withIDs(array($id))
+ ->needAuditRequests(true)
->executeOne();
}
diff --git a/src/applications/audit/storage/PhabricatorAuditComment.php b/src/applications/audit/storage/PhabricatorAuditComment.php
--- a/src/applications/audit/storage/PhabricatorAuditComment.php
+++ b/src/applications/audit/storage/PhabricatorAuditComment.php
@@ -3,8 +3,6 @@
final class PhabricatorAuditComment
implements PhabricatorMarkupInterface {
- const METADATA_ADDED_AUDITORS = 'added-auditors';
-
const MARKUP_FIELD_BODY = 'markup:body';
private $proxyComment;
@@ -145,42 +143,6 @@
}
}
- public function setMetadata(array $metadata) {
- if (!$this->proxy->getTransactionType()) {
- throw new Exception(pht('Call setAction() before getMetadata()!'));
- }
-
- $type = $this->proxy->getTransactionType();
- switch ($type) {
- case PhabricatorAuditActionConstants::ADD_AUDITORS:
- $raw_phids = idx($metadata, self::METADATA_ADDED_AUDITORS, array());
- break;
- default:
- throw new Exception(pht('No metadata expected!'));
- }
-
- $this->proxy->setNewValue(array_fuse($raw_phids));
-
- return $this;
- }
-
- public function getMetadata() {
- if (!$this->proxy->getTransactionType()) {
- throw new Exception(pht('Call setAction() before getMetadata()!'));
- }
-
- $type = $this->proxy->getTransactionType();
- $new_value = $this->proxy->getNewValue();
- switch ($type) {
- case PhabricatorAuditActionConstants::ADD_AUDITORS:
- return array(
- self::METADATA_ADDED_AUDITORS => array_keys($new_value),
- );
- }
-
- return array();
- }
-
public function save() {
throw new Exception(
pht('This object can no longer be written to directly!'));
diff --git a/src/applications/diffusion/conduit/DiffusionCreateCommentConduitAPIMethod.php b/src/applications/diffusion/conduit/DiffusionCreateCommentConduitAPIMethod.php
--- a/src/applications/diffusion/conduit/DiffusionCreateCommentConduitAPIMethod.php
+++ b/src/applications/diffusion/conduit/DiffusionCreateCommentConduitAPIMethod.php
@@ -43,6 +43,7 @@
$commit = id(new DiffusionCommitQuery())
->setViewer($request->getUser())
->withPHIDs(array($commit_phid))
+ ->needAuditRequests(true)
->executeOne();
if (!$commit) {
throw new ConduitException('ERR_BAD_COMMIT');

File Metadata

Mime Type
text/plain
Expires
Nov 14 2025, 8:18 AM (5 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
12596100
Default Alt Text
D10123.id24350.diff (7 KB)

Event Timeline