mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-19 18:28:39 +01:00
MetaMTA - add support for "Default Author"
Summary: Ref T5952. This adds support for a "default author" and deploys it on Maniphest. Test Plan: used augmented (by this diff) bin/mail receive-test to test creation via an application email with a default author configured and no author specified. a task was created with the author as the default author i configured. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T5952 Differential Revision: https://secure.phabricator.com/D11446
This commit is contained in:
parent
9b359affe7
commit
799dada3ad
7 changed files with 134 additions and 45 deletions
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
$key = 'metamta.maniphest.default-public-author';
|
||||
echo "Migrating `$key` to new application email infrastructure...\n";
|
||||
$value = PhabricatorEnv::getEnvConfigIfExists($key);
|
||||
$maniphest = new PhabricatorManiphestApplication();
|
||||
$config_key =
|
||||
PhabricatorMetaMTAApplicationEmail::CONFIG_DEFAULT_AUTHOR;
|
||||
|
||||
if ($value) {
|
||||
$app_emails = id(new PhabricatorMetaMTAApplicationEmailQuery())
|
||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||
->withApplicationPHIDs($maniphest->getPHID())
|
||||
->execute();
|
||||
|
||||
foreach ($app_emails as $app_email) {
|
||||
$app_email->setConfigValue($config_key, $value);
|
||||
$app_email->save();
|
||||
}
|
||||
}
|
||||
|
||||
echo "Done.\n";
|
|
@ -318,9 +318,18 @@ EOTEXT
|
|||
'metamta.maniphest.default-public-author',
|
||||
'string',
|
||||
null)
|
||||
->setSummary(pht('Username anonymous bugs are filed under.'))
|
||||
->setLocked(true)
|
||||
->setLockedMessage(pht(
|
||||
'This configuration is deprecated. See description for details.'))
|
||||
->setSummary(pht(
|
||||
'DEPRECATED - Username anonymous bugs are filed under.'))
|
||||
->setDescription(
|
||||
pht(
|
||||
'This config has been deprecated in favor of [[ '.
|
||||
'/applications/view/PhabricatorManiphestApplication/ | '.
|
||||
'application settings ]], which allow for multiple email '.
|
||||
'addresses each with its own default author, and other '.
|
||||
'functionality.'."\n\n".
|
||||
'If you enable `metamta.maniphest.public-create-email` and create '.
|
||||
'an email address like "bugs@phabricator.example.com", it will '.
|
||||
'default to rejecting mail which doesn\'t come from a known user. '.
|
||||
|
|
|
@ -18,6 +18,7 @@ final class ManiphestCreateMailReceiver extends PhabricatorMailReceiver {
|
|||
foreach ($application_emails as $application_email) {
|
||||
$create_address = $application_email->getAddress();
|
||||
if ($this->matchAddresses($create_address, $to_address)) {
|
||||
$this->setApplicationEmail($application_email);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -26,42 +27,6 @@ final class ManiphestCreateMailReceiver extends PhabricatorMailReceiver {
|
|||
return false;
|
||||
}
|
||||
|
||||
public function loadSender(PhabricatorMetaMTAReceivedMail $mail) {
|
||||
try {
|
||||
// Try to load the sender normally.
|
||||
return parent::loadSender($mail);
|
||||
} catch (PhabricatorMetaMTAReceivedMailProcessingException $ex) {
|
||||
|
||||
// If we failed to load the sender normally, use this special legacy
|
||||
// black magic.
|
||||
|
||||
// TODO: Deprecate and remove this.
|
||||
|
||||
$default_author_key = 'metamta.maniphest.default-public-author';
|
||||
$default_author = PhabricatorEnv::getEnvConfig($default_author_key);
|
||||
|
||||
if (!strlen($default_author)) {
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
$user = id(new PhabricatorUser())->loadOneWhere(
|
||||
'username = %s',
|
||||
$default_author);
|
||||
|
||||
if ($user) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
throw new PhabricatorMetaMTAReceivedMailProcessingException(
|
||||
MetaMTAReceivedMailStatus::STATUS_UNKNOWN_SENDER,
|
||||
pht(
|
||||
"Phabricator is misconfigured, the configuration key ".
|
||||
"'metamta.maniphest.default-public-author' is set to user ".
|
||||
"'%s' but that user does not exist.",
|
||||
$default_author));
|
||||
}
|
||||
}
|
||||
|
||||
protected function processReceivedMail(
|
||||
PhabricatorMetaMTAReceivedMail $mail,
|
||||
PhabricatorUser $sender) {
|
||||
|
|
|
@ -220,10 +220,17 @@ final class PhabricatorApplicationEditEmailController
|
|||
$e_email = true;
|
||||
$email = null;
|
||||
$errors = array();
|
||||
$default_user_key =
|
||||
PhabricatorMetaMTAApplicationEmail::CONFIG_DEFAULT_AUTHOR;
|
||||
if ($request->isDialogFormPost()) {
|
||||
$email = trim($request->getStr('email'));
|
||||
list($e_email, $errors) = $this->validateApplicationEmail($email);
|
||||
$email_object->setAddress($email);
|
||||
$default_user = $request->getArr($default_user_key);
|
||||
$default_user = reset($default_user);
|
||||
if ($default_user) {
|
||||
$email_object->setConfigValue($default_user_key, $default_user);
|
||||
}
|
||||
|
||||
if (!$errors) {
|
||||
try {
|
||||
|
@ -244,6 +251,13 @@ final class PhabricatorApplicationEditEmailController
|
|||
->setErrors($errors);
|
||||
}
|
||||
|
||||
$default_user = $email_object->getConfigValue($default_user_key);
|
||||
if ($default_user) {
|
||||
$default_user_handle = $this->loadViewerHandles(array($default_user));
|
||||
} else {
|
||||
$default_user_handle = array();
|
||||
}
|
||||
|
||||
$form = id(new PHUIFormLayoutView())
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
|
@ -251,11 +265,25 @@ final class PhabricatorApplicationEditEmailController
|
|||
->setName('email')
|
||||
->setValue($email_object->getAddress())
|
||||
->setCaption(PhabricatorUserEmail::describeAllowedAddresses())
|
||||
->setError($e_email));
|
||||
|
||||
->setError($e_email))
|
||||
->appendChild(
|
||||
id(new AphrontFormTokenizerControl())
|
||||
->setDatasource(new PhabricatorPeopleDatasource())
|
||||
->setLabel(pht('Default Author'))
|
||||
->setName($default_user_key)
|
||||
->setLimit(1)
|
||||
->setValue($default_user_handle)
|
||||
->setCaption(pht(
|
||||
'Used if the "From:" address does not map to a known account.')));
|
||||
if ($is_new) {
|
||||
$title = pht('New Address');
|
||||
} else {
|
||||
$title = pht('Edit Address');
|
||||
}
|
||||
$dialog = id(new AphrontDialogView())
|
||||
->setUser($viewer)
|
||||
->setTitle(pht('New Address'))
|
||||
->setWidth(AphrontDialogView::WIDTH_FORM)
|
||||
->setTitle($title)
|
||||
->appendChild($errors)
|
||||
->appendChild($form)
|
||||
->addSubmitButton(pht('Save'))
|
||||
|
|
|
@ -35,7 +35,32 @@ final class PhabricatorMailManagementReceiveTestWorkflow
|
|||
public function execute(PhutilArgumentParser $args) {
|
||||
$console = PhutilConsole::getConsole();
|
||||
|
||||
$to = $args->getArg('to');
|
||||
if (!$to) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
"Use '--to' to specify the receiving object or email address.");
|
||||
}
|
||||
|
||||
$to_application_email = id(new PhabricatorMetaMTAApplicationEmailQuery())
|
||||
->setViewer($this->getViewer())
|
||||
->withAddresses(array($to))
|
||||
->executeOne();
|
||||
|
||||
$as = $args->getArg('as');
|
||||
if (!$as && $to_application_email) {
|
||||
$default_phid = $to_application_email->getConfigValue(
|
||||
PhabricatorMetaMTAApplicationEmail::CONFIG_DEFAULT_AUTHOR);
|
||||
if ($default_phid) {
|
||||
$default_user = id(new PhabricatorPeopleQuery())
|
||||
->setViewer($this->getViewer())
|
||||
->withPHIDs(array($default_phid))
|
||||
->executeOne();
|
||||
if ($default_user) {
|
||||
$as = $default_user->getUsername();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$as) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
pht("Use '--as' to specify the acting user."));
|
||||
|
@ -50,11 +75,6 @@ final class PhabricatorMailManagementReceiveTestWorkflow
|
|||
pht("No such user '%s' exists.", $as));
|
||||
}
|
||||
|
||||
$to = $args->getArg('to');
|
||||
if (!$to) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
"Use '--to' to specify the receiving object or email address.");
|
||||
}
|
||||
|
||||
$from = $args->getArg('from');
|
||||
if (!$from) {
|
||||
|
|
|
@ -2,9 +2,22 @@
|
|||
|
||||
abstract class PhabricatorMailReceiver {
|
||||
|
||||
private $applicationEmail;
|
||||
|
||||
public function setApplicationEmail(
|
||||
PhabricatorMetaMTAApplicationEmail $email) {
|
||||
$this->applicationEmail = $email;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getApplicationEmail() {
|
||||
return $this->applicationEmail;
|
||||
}
|
||||
|
||||
abstract public function isEnabled();
|
||||
abstract public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail);
|
||||
|
||||
|
||||
abstract protected function processReceivedMail(
|
||||
PhabricatorMetaMTAReceivedMail $mail,
|
||||
PhabricatorUser $sender);
|
||||
|
@ -128,6 +141,27 @@ abstract class PhabricatorMailReceiver {
|
|||
$raw_from);
|
||||
}
|
||||
|
||||
if ($this->getApplicationEmail()) {
|
||||
$application_email = $this->getApplicationEmail();
|
||||
$default_user_phid = $application_email->getConfigValue(
|
||||
PhabricatorMetaMTAApplicationEmail::CONFIG_DEFAULT_AUTHOR);
|
||||
|
||||
if ($default_user_phid) {
|
||||
$user = id(new PhabricatorUser())->loadOneWhere(
|
||||
'phid = %s',
|
||||
$default_user_phid);
|
||||
if ($user) {
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
$reasons[] = pht(
|
||||
"Phabricator is misconfigured, the application email ".
|
||||
"'%s' is set to user '%s' but that user does not exist.",
|
||||
$application_email->getAddress(),
|
||||
$default_user_phid);
|
||||
}
|
||||
|
||||
$reasons = implode("\n\n", $reasons);
|
||||
|
||||
throw new PhabricatorMetaMTAReceivedMailProcessingException(
|
||||
|
|
|
@ -10,6 +10,8 @@ final class PhabricatorMetaMTAApplicationEmail
|
|||
|
||||
private $application = self::ATTACHABLE;
|
||||
|
||||
const CONFIG_DEFAULT_AUTHOR = 'config:default:author';
|
||||
|
||||
protected function getConfiguration() {
|
||||
return array(
|
||||
self::CONFIG_AUX_PHID => true,
|
||||
|
@ -50,6 +52,15 @@ final class PhabricatorMetaMTAApplicationEmail
|
|||
return self::assertAttached($this->application);
|
||||
}
|
||||
|
||||
public function setConfigValue($key, $value) {
|
||||
$this->configData[$key] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getConfigValue($key, $default = null) {
|
||||
return idx($this->configData, $key, $default);
|
||||
}
|
||||
|
||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue