mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 13:22:42 +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:
parent
301fed1b43
commit
74a2953ffd
4 changed files with 55 additions and 18 deletions
|
@ -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();
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in a new issue