1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-27 07:50: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',
'PhabricatorFlaggableInterface',
'PhabricatorTokenReceiverInterface',
'PhabricatorSubscribableInterface',
'HarbormasterBuildableInterface',
'PhabricatorCustomFieldInterface',
),

View file

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

View file

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

View file

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

View file

@ -6,6 +6,7 @@ final class PhabricatorRepositoryCommit
PhabricatorPolicyInterface,
PhabricatorFlaggableInterface,
PhabricatorTokenReceiverInterface,
PhabricatorSubscribableInterface,
HarbormasterBuildableInterface,
PhabricatorCustomFieldInterface {
@ -330,4 +331,24 @@ final class PhabricatorRepositoryCommit
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(
PhabricatorAuditStatusConstants::AUDIT_REQUIRED => $map,
PhabricatorAuditStatusConstants::CC => $ccmap,
);
foreach ($maps as $status => $map) {
@ -281,6 +280,14 @@ final class PhabricatorRepositoryCommitHeraldWorker
$commit->updateAuditStatus($requests);
$commit->save();
if ($ccmap) {
id(new PhabricatorSubscriptionsEditor())
->setActor(PhabricatorUser::getOmnipotentUser())
->setObject($commit)
->subscribeExplicit(array_keys($ccmap))
->save();
}
}