mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 06:20:56 +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()) {
|
if (!$request->isFormPost()) {
|
||||||
// TODO: This dialog is silly but we're CSRF-able otherwise.
|
|
||||||
|
|
||||||
$dialog = new AphrontDialogView();
|
$dialog = new AphrontDialogView();
|
||||||
|
|
||||||
switch ($this->action) {
|
switch ($this->action) {
|
||||||
|
@ -74,28 +72,16 @@ class DifferentialSubscribeController extends DifferentialController {
|
||||||
|
|
||||||
switch ($this->action) {
|
switch ($this->action) {
|
||||||
case 'add':
|
case 'add':
|
||||||
DifferentialRevisionEditor::addCC(
|
DifferentialRevisionEditor::addCCAndUpdateRevision(
|
||||||
$revision,
|
$revision,
|
||||||
$phid,
|
$phid,
|
||||||
$phid);
|
$phid);
|
||||||
$unsubscribed = $revision->getUnsubscribed();
|
|
||||||
if (isset($unsubscribed[$phid])) {
|
|
||||||
unset($unsubscribed[$phid]);
|
|
||||||
$revision->setUnsubscribed($unsubscribed);
|
|
||||||
$revision->save();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'rem':
|
case 'rem':
|
||||||
DifferentialRevisionEditor::removeCC(
|
DifferentialRevisionEditor::removeCCAndUpdateRevision(
|
||||||
$revision,
|
$revision,
|
||||||
$user->getPHID(),
|
$phid,
|
||||||
$user->getPHID());
|
$phid);
|
||||||
$unsubscribed = $revision->getUnsubscribed();
|
|
||||||
if (empty($unsubscribed[$phid])) {
|
|
||||||
$unsubscribed[$phid] = true;
|
|
||||||
$revision->setUnsubscribed($unsubscribed);
|
|
||||||
$revision->save();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return new Aphront400Response();
|
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(
|
public static function addCC(
|
||||||
DifferentialRevision $revision,
|
DifferentialRevision $revision,
|
||||||
$phid,
|
$phid,
|
||||||
|
|
|
@ -89,6 +89,7 @@ class DifferentialReplyHandler extends PhabricatorMailReplyHandler {
|
||||||
DifferentialAction::ACTION_RECLAIM,
|
DifferentialAction::ACTION_RECLAIM,
|
||||||
DifferentialAction::ACTION_RESIGN,
|
DifferentialAction::ACTION_RESIGN,
|
||||||
DifferentialAction::ACTION_RETHINK,
|
DifferentialAction::ACTION_RETHINK,
|
||||||
|
'unsubscribe',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,6 +115,13 @@ class DifferentialReplyHandler extends PhabricatorMailReplyHandler {
|
||||||
throw new Exception('No actor is set for the reply action.');
|
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 {
|
try {
|
||||||
$editor = new DifferentialCommentEditor(
|
$editor = new DifferentialCommentEditor(
|
||||||
$this->getMailReceiver(),
|
$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/constants/action');
|
||||||
phutil_require_module('phabricator', 'applications/differential/editor/comment');
|
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/differential/mail/exception');
|
||||||
phutil_require_module('phabricator', 'applications/metamta/replyhandler/base');
|
phutil_require_module('phabricator', 'applications/metamta/replyhandler/base');
|
||||||
phutil_require_module('phabricator', 'infrastructure/env');
|
phutil_require_module('phabricator', 'infrastructure/env');
|
||||||
|
|
Loading…
Reference in a new issue