1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-28 00:10:57 +01:00

Move Audit to proper Subscriptions

Summary:
Ref T4896. Currently, subscriptions to commits are stored as auditors with a special "CC" type.

Instead, use normal subscriptions storage, reads and writes.

Test Plan:
  - Ran migration and verified data still looked good.
  - Viewed commits in UI and saw "subscribers".
  - Saw "Automatically Subscribed", clicked Subscribe/Unsubscribe on a non-authored commit, saw subscriptions update.
  - Pushed a commit through Herald rules and saw them trigger subscriptions and auditors.
  - Used "Add CCs".
  - Added CCs with mentions.

Reviewers: btrahan, joshuaspence

Reviewed By: btrahan, joshuaspence

Subscribers: epriestley

Maniphest Tasks: T4896

Differential Revision: https://secure.phabricator.com/D10103
This commit is contained in:
epriestley 2014-08-02 00:06:13 -07:00
parent 68f1ca896d
commit 89b942c183
7 changed files with 102 additions and 50 deletions

View file

@ -0,0 +1,30 @@
<?php
$table = new PhabricatorRepositoryAuditRequest();
$conn_w = $table->establishConnection('w');
echo "Migrating Audit subscribers to subscriptions...\n";
foreach (new LiskMigrationIterator($table) as $request) {
$id = $request->getID();
echo "Migrating auditor {$id}...\n";
if ($request->getAuditStatus() != 'cc') {
// This isn't a "subscriber", so skip it.
continue;
}
queryfx(
$conn_w,
'INSERT IGNORE INTO %T (src, type, dst) VALUES (%s, %d, %s)',
PhabricatorEdgeConfig::TABLE_NAME_EDGE,
$request->getCommitPHID(),
PhabricatorEdgeConfig::TYPE_OBJECT_HAS_SUBSCRIBER,
$request->getAuditorPHID());
// Wipe the row.
$request->delete();
}
echo "Done.\n";

View file

@ -4847,6 +4847,7 @@ phutil_register_library_map(array(
'PhabricatorPolicyInterface', 'PhabricatorPolicyInterface',
'PhabricatorFlaggableInterface', 'PhabricatorFlaggableInterface',
'PhabricatorTokenReceiverInterface', 'PhabricatorTokenReceiverInterface',
'PhabricatorSubscribableInterface',
'HarbormasterBuildableInterface', 'HarbormasterBuildableInterface',
'PhabricatorCustomFieldInterface', 'PhabricatorCustomFieldInterface',
), ),

View file

@ -93,6 +93,8 @@ final class PhabricatorAuditCommentEditor extends PhabricatorEditor {
} }
} }
$add_self_cc = false;
if ($action == PhabricatorAuditActionConstants::CLOSE) { if ($action == PhabricatorAuditActionConstants::CLOSE) {
if (!PhabricatorEnv::getEnvConfig('audit.can-author-close-audit')) { if (!PhabricatorEnv::getEnvConfig('audit.can-author-close-audit')) {
throw new Exception('Cannot Close Audit without enabling'. throw new Exception('Cannot Close Audit without enabling'.
@ -177,9 +179,9 @@ final class PhabricatorAuditCommentEditor extends PhabricatorEditor {
$new_status = null; $new_status = null;
switch ($action) { switch ($action) {
case PhabricatorAuditActionConstants::COMMENT: case PhabricatorAuditActionConstants::COMMENT:
case PhabricatorAuditActionConstants::ADD_CCS:
case PhabricatorAuditActionConstants::ADD_AUDITORS: case PhabricatorAuditActionConstants::ADD_AUDITORS:
$new_status = PhabricatorAuditStatusConstants::AUDIT_NOT_REQUIRED; case PhabricatorAuditActionConstants::ADD_CCS:
$add_self_cc = true;
break; break;
case PhabricatorAuditActionConstants::ACCEPT: case PhabricatorAuditActionConstants::ACCEPT:
$new_status = PhabricatorAuditStatusConstants::ACCEPTED; $new_status = PhabricatorAuditStatusConstants::ACCEPTED;
@ -193,18 +195,25 @@ final class PhabricatorAuditCommentEditor extends PhabricatorEditor {
throw new Exception("Unknown or invalid action '{$action}'!"); throw new Exception("Unknown or invalid action '{$action}'!");
} }
$request = id(new PhabricatorRepositoryAuditRequest()) if ($new_status !== null) {
->setCommitPHID($commit->getPHID()) $request = id(new PhabricatorRepositoryAuditRequest())
->setAuditorPHID($actor->getPHID()) ->setCommitPHID($commit->getPHID())
->setAuditStatus($new_status) ->setAuditorPHID($actor->getPHID())
->setAuditReasons(array('Voluntary Participant')) ->setAuditStatus($new_status)
->save(); ->setAuditReasons(array('Voluntary Participant'))
$requests[] = $request; ->save();
$requests[] = $request;
}
} }
} }
$auditors = array(); $auditors = array();
$ccs = array(); $ccs = array();
if ($add_self_cc) {
$ccs[] = $actor->getPHID();
}
foreach ($comments as $comment) { foreach ($comments as $comment) {
$meta = $comment->getMetadata(); $meta = $comment->getMetadata();
@ -244,22 +253,17 @@ final class PhabricatorAuditCommentEditor extends PhabricatorEditor {
} }
} }
if ($ccs) {
foreach ($ccs as $cc_phid) {
$audit_cc = PhabricatorAuditStatusConstants::CC;
$requests[] = id (new PhabricatorRepositoryAuditRequest())
->setCommitPHID($commit->getPHID())
->setAuditorPHID($cc_phid)
->setAuditStatus($audit_cc)
->setAuditReasons(
array('Added by '.$actor->getUsername()))
->save();
}
}
$commit->updateAuditStatus($requests); $commit->updateAuditStatus($requests);
$commit->save(); $commit->save();
if ($ccs) {
id(new PhabricatorSubscriptionsEditor())
->setActor($actor)
->setObject($commit)
->subscribeExplicit($ccs)
->save();
}
$content_source = PhabricatorContentSource::newForSource( $content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_LEGACY, PhabricatorContentSource::SOURCE_LEGACY,
array()); array());
@ -288,15 +292,14 @@ final class PhabricatorAuditCommentEditor extends PhabricatorEditor {
foreach ($requests as $request) { foreach ($requests as $request) {
$status = $request->getAuditStatus(); $status = $request->getAuditStatus();
switch ($status) { switch ($status) {
case PhabricatorAuditStatusConstants::RESIGNED: case PhabricatorAuditStatusConstants::RESIGNED:
case PhabricatorAuditStatusConstants::NONE: case PhabricatorAuditStatusConstants::NONE:
case PhabricatorAuditStatusConstants::AUDIT_NOT_REQUIRED: case PhabricatorAuditStatusConstants::AUDIT_NOT_REQUIRED:
case PhabricatorAuditStatusConstants::CC: $feed_dont_publish_phids[$request->getAuditorPHID()] = 1;
$feed_dont_publish_phids[$request->getAuditorPHID()] = 1; break;
break; default:
default: unset($feed_dont_publish_phids[$request->getAuditorPHID()]);
unset($feed_dont_publish_phids[$request->getAuditorPHID()]); break;
break;
} }
} }
$feed_dont_publish_phids = array_keys($feed_dont_publish_phids); $feed_dont_publish_phids = array_keys($feed_dont_publish_phids);
@ -452,9 +455,14 @@ final class PhabricatorAuditCommentEditor extends PhabricatorEditor {
$email_cc[$other_comment->getActorPHID()] = true; $email_cc[$other_comment->getActorPHID()] = true;
} }
$subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID(
$commit->getPHID());
foreach ($subscribers as $subscriber) {
$email_cc[$subscriber] = true;
}
foreach ($requests as $request) { foreach ($requests as $request) {
switch ($request->getAuditStatus()) { switch ($request->getAuditStatus()) {
case PhabricatorAuditStatusConstants::CC:
case PhabricatorAuditStatusConstants::AUDIT_REQUIRED: case PhabricatorAuditStatusConstants::AUDIT_REQUIRED:
$email_cc[$request->getAuditorPHID()] = true; $email_cc[$request->getAuditorPHID()] = true;
break; break;

View file

@ -1100,12 +1100,6 @@ final class DiffusionCommitController extends DiffusionController {
'blue', 'blue',
pht('Closed')); pht('Closed'));
break; break;
case PhabricatorAuditStatusConstants::CC:
$item->setIcon(
PHUIStatusItemView::ICON_INFO,
'dark',
pht('Subscribed'));
break;
default: default:
$item->setIcon( $item->setIcon(
PHUIStatusItemView::ICON_QUESTION, PHUIStatusItemView::ICON_QUESTION,

View file

@ -69,10 +69,6 @@ final class DiffusionDoorkeeperCommitFeedStoryPublisher
foreach ($requests as $request) { foreach ($requests as $request) {
$status = $request->getAuditStatus(); $status = $request->getAuditStatus();
if ($status == PhabricatorAuditStatusConstants::CC) {
// We handle these specially below.
continue;
}
$object = idx($objects, $request->getAuditorPHID()); $object = idx($objects, $request->getAuditorPHID());
if (!$object) { if (!$object) {
@ -133,13 +129,8 @@ final class DiffusionDoorkeeperCommitFeedStoryPublisher
} }
public function getCCUserPHIDs($object) { public function getCCUserPHIDs($object) {
$ccs = array(); return PhabricatorSubscribersQuery::loadSubscribersForPHID(
foreach ($this->getAuditRequests() as $request) { $object->getPHID());
if ($request->getAuditStatus() == PhabricatorAuditStatusConstants::CC) {
$ccs[] = $request->getAuditorPHID();
}
}
return $ccs;
} }
public function getObjectTitle($object) { public function getObjectTitle($object) {

View file

@ -6,6 +6,7 @@ final class PhabricatorRepositoryCommit
PhabricatorPolicyInterface, PhabricatorPolicyInterface,
PhabricatorFlaggableInterface, PhabricatorFlaggableInterface,
PhabricatorTokenReceiverInterface, PhabricatorTokenReceiverInterface,
PhabricatorSubscribableInterface,
HarbormasterBuildableInterface, HarbormasterBuildableInterface,
PhabricatorCustomFieldInterface { PhabricatorCustomFieldInterface {
@ -330,4 +331,24 @@ final class PhabricatorRepositoryCommit
return $this; return $this;
} }
/* -( PhabricatorSubscribableInterface )----------------------------------- */
public function isAutomaticallySubscribed($phid) {
// TODO: This should also list auditors, but handling that is a bit messy
// right now because we are not guaranteed to have the data.
return ($phid == $this->getAuthorPHID());
}
public function shouldShowSubscribersProperty() {
return true;
}
public function shouldAllowSubscription($phid) {
return true;
}
} }

View file

@ -244,7 +244,6 @@ final class PhabricatorRepositoryCommitHeraldWorker
$maps = array( $maps = array(
PhabricatorAuditStatusConstants::AUDIT_REQUIRED => $map, PhabricatorAuditStatusConstants::AUDIT_REQUIRED => $map,
PhabricatorAuditStatusConstants::CC => $ccmap,
); );
foreach ($maps as $status => $map) { foreach ($maps as $status => $map) {
@ -281,6 +280,14 @@ final class PhabricatorRepositoryCommitHeraldWorker
$commit->updateAuditStatus($requests); $commit->updateAuditStatus($requests);
$commit->save(); $commit->save();
if ($ccmap) {
id(new PhabricatorSubscriptionsEditor())
->setActor(PhabricatorUser::getOmnipotentUser())
->setObject($commit)
->subscribeExplicit(array_keys($ccmap))
->save();
}
} }