1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 04:20:55 +01:00

Support "!unsubscribe" in Differential reply handler

Summary:
See task. Allows users to unsubscribe via email.

Test Plan:
Used mail receiver to unsubscribe from a revision. Tested subscribe/unsubscribe
buttons. Verified "!unsubscribe" appears as an avilable action in email.

Reviewed By: ola
Reviewers: ola, mroch, jungejason, tuomaspelkonen, aran
CC: aran, epriestley, ola
Differential Revision: 385
This commit is contained in:
epriestley 2011-05-31 14:53:03 -07:00
parent 301fed1b43
commit 74a2953ffd
4 changed files with 55 additions and 18 deletions

View file

@ -37,8 +37,6 @@ class DifferentialSubscribeController extends DifferentialController {
}
if (!$request->isFormPost()) {
// TODO: This dialog is silly but we're CSRF-able otherwise.
$dialog = new AphrontDialogView();
switch ($this->action) {
@ -74,28 +72,16 @@ class DifferentialSubscribeController extends DifferentialController {
switch ($this->action) {
case 'add':
DifferentialRevisionEditor::addCC(
DifferentialRevisionEditor::addCCAndUpdateRevision(
$revision,
$phid,
$phid);
$unsubscribed = $revision->getUnsubscribed();
if (isset($unsubscribed[$phid])) {
unset($unsubscribed[$phid]);
$revision->setUnsubscribed($unsubscribed);
$revision->save();
}
break;
case 'rem':
DifferentialRevisionEditor::removeCC(
DifferentialRevisionEditor::removeCCAndUpdateRevision(
$revision,
$user->getPHID(),
$user->getPHID());
$unsubscribed = $revision->getUnsubscribed();
if (empty($unsubscribed[$phid])) {
$unsubscribed[$phid] = true;
$revision->setUnsubscribed($unsubscribed);
$revision->save();
}
$phid,
$phid);
break;
default:
return new Aphront400Response();

View file

@ -416,6 +416,36 @@ class DifferentialRevisionEditor {
}
}
public static function addCCAndUpdateRevision(
$revision,
$phid,
$reason) {
self::addCC($revision, $phid, $reason);
$unsubscribed = $revision->getUnsubscribed();
if (isset($unsubscribed[$phid])) {
unset($unsubscribed[$phid]);
$revision->setUnsubscribed($unsubscribed);
$revision->save();
}
}
public static function removeCCAndUpdateRevision(
$revision,
$phid,
$reason) {
self::removeCC($revision, $phid, $reason);
$unsubscribed = $revision->getUnsubscribed();
if (empty($unsubscribed[$phid])) {
$unsubscribed[$phid] = true;
$revision->setUnsubscribed($unsubscribed);
$revision->save();
}
}
public static function addCC(
DifferentialRevision $revision,
$phid,

View file

@ -89,6 +89,7 @@ class DifferentialReplyHandler extends PhabricatorMailReplyHandler {
DifferentialAction::ACTION_RECLAIM,
DifferentialAction::ACTION_RESIGN,
DifferentialAction::ACTION_RETHINK,
'unsubscribe',
);
}
@ -114,6 +115,13 @@ class DifferentialReplyHandler extends PhabricatorMailReplyHandler {
throw new Exception('No actor is set for the reply action.');
}
switch ($command) {
case 'unsubscribe':
$this->unsubscribeUser($this->getMailReceiver(), $actor);
// TODO: Send the user a confirmation email?
return null;
}
try {
$editor = new DifferentialCommentEditor(
$this->getMailReceiver(),
@ -139,4 +147,16 @@ class DifferentialReplyHandler extends PhabricatorMailReplyHandler {
}
}
private function unsubscribeUser(
DifferentialRevision $revision,
PhabricatorUser $user) {
$revision->loadRelationships();
DifferentialRevisionEditor::removeCCAndUpdateRevision(
$revision,
$user->getPHID(),
$user->getPHID());
}
}

View file

@ -8,6 +8,7 @@
phutil_require_module('phabricator', 'applications/differential/constants/action');
phutil_require_module('phabricator', 'applications/differential/editor/comment');
phutil_require_module('phabricator', 'applications/differential/editor/revision');
phutil_require_module('phabricator', 'applications/differential/mail/exception');
phutil_require_module('phabricator', 'applications/metamta/replyhandler/base');
phutil_require_module('phabricator', 'infrastructure/env');