Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14055228
D11446.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
D11446.diff
View Options
diff --git a/resources/sql/autopatches/20150120.maniphestdefaultauthor.php b/resources/sql/autopatches/20150120.maniphestdefaultauthor.php
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20150120.maniphestdefaultauthor.php
@@ -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";
diff --git a/src/applications/maniphest/config/PhabricatorManiphestConfigOptions.php b/src/applications/maniphest/config/PhabricatorManiphestConfigOptions.php
--- a/src/applications/maniphest/config/PhabricatorManiphestConfigOptions.php
+++ b/src/applications/maniphest/config/PhabricatorManiphestConfigOptions.php
@@ -318,9 +318,18 @@
'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. '.
diff --git a/src/applications/maniphest/mail/ManiphestCreateMailReceiver.php b/src/applications/maniphest/mail/ManiphestCreateMailReceiver.php
--- a/src/applications/maniphest/mail/ManiphestCreateMailReceiver.php
+++ b/src/applications/maniphest/mail/ManiphestCreateMailReceiver.php
@@ -18,6 +18,7 @@
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 @@
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) {
diff --git a/src/applications/meta/controller/PhabricatorApplicationEditEmailController.php b/src/applications/meta/controller/PhabricatorApplicationEditEmailController.php
--- a/src/applications/meta/controller/PhabricatorApplicationEditEmailController.php
+++ b/src/applications/meta/controller/PhabricatorApplicationEditEmailController.php
@@ -220,10 +220,17 @@
$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 @@
->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 @@
->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'))
diff --git a/src/applications/metamta/management/PhabricatorMailManagementReceiveTestWorkflow.php b/src/applications/metamta/management/PhabricatorMailManagementReceiveTestWorkflow.php
--- a/src/applications/metamta/management/PhabricatorMailManagementReceiveTestWorkflow.php
+++ b/src/applications/metamta/management/PhabricatorMailManagementReceiveTestWorkflow.php
@@ -35,7 +35,32 @@
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 @@
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) {
diff --git a/src/applications/metamta/receiver/PhabricatorMailReceiver.php b/src/applications/metamta/receiver/PhabricatorMailReceiver.php
--- a/src/applications/metamta/receiver/PhabricatorMailReceiver.php
+++ b/src/applications/metamta/receiver/PhabricatorMailReceiver.php
@@ -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 @@
$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(
diff --git a/src/applications/metamta/storage/PhabricatorMetaMTAApplicationEmail.php b/src/applications/metamta/storage/PhabricatorMetaMTAApplicationEmail.php
--- a/src/applications/metamta/storage/PhabricatorMetaMTAApplicationEmail.php
+++ b/src/applications/metamta/storage/PhabricatorMetaMTAApplicationEmail.php
@@ -10,6 +10,8 @@
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 @@
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 )----------------------------------------- */
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 17, 9:37 AM (1 d, 7 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6737998
Default Alt Text
D11446.diff (10 KB)
Attached To
Mode
D11446: MetaMTA - add support for "Default Author"
Attached
Detach File
Event Timeline
Log In to Comment