From f53cde8f92f8ca00d61490b497d5dc88b66cd1c5 Mon Sep 17 00:00:00 2001 From: Zedstar Date: Sun, 28 Apr 2013 13:22:05 -0700 Subject: [PATCH] Using PhabricatorExternalAccount Summary: Using PhabricatorExternalAccount in place maniphest.default-public-author. Test Plan: Using receivemail to see if the a new entry is made in the 'phabircator_user.user_externalaccount' table. Few things, I noticed that phabricator creates table 'user_externalaccout'. And now it throws up error 'Unknown column 'dateCreated' in 'field list''. Awaiting your comments. {F41370} Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin, AnhNhan Maniphest Tasks: T1205 Differential Revision: https://secure.phabricator.com/D5747 --- conf/default.conf.php | 4 +- .../option/PhabricatorCoreConfigOptions.php | 8 +++ .../PhabricatorMetaMTAReceivedMail.php | 57 +++++++++++++------ .../storage/PhabricatorExternalAccount.php | 19 +++++-- 4 files changed, 64 insertions(+), 24 deletions(-) diff --git a/conf/default.conf.php b/conf/default.conf.php index a66dcf1161..00e0ca3b80 100644 --- a/conf/default.conf.php +++ b/conf/default.conf.php @@ -547,7 +547,6 @@ return array( // preferences. 'metamta.vary-subjects' => true, - // -- Auth ------------------------------------------------------------------ // // Can users login with a username/password, or by following the link from @@ -850,6 +849,9 @@ return array( // Contains a list of uninstalled applications 'phabricator.uninstalled-applications' => array(), + // Allowing non-members to interact with tasks over email. + 'phabricator.allow-email-users' => false, + // -- Welcome Screen -------------------------------------------------------- // // The custom HTML content for the Phabricator welcome screen. diff --git a/src/applications/config/option/PhabricatorCoreConfigOptions.php b/src/applications/config/option/PhabricatorCoreConfigOptions.php index 604cedf476..053c5d1390 100644 --- a/src/applications/config/option/PhabricatorCoreConfigOptions.php +++ b/src/applications/config/option/PhabricatorCoreConfigOptions.php @@ -153,6 +153,14 @@ final class PhabricatorCoreConfigOptions $this->newOption('phabricator.cache-namespace', 'string', null) ->setLocked(true) ->setDescription(pht('Cache namespace.')), + $this->newOption('phabricator.allow-email-users', 'bool', false) + ->setBoolOptions( + array( + pht('Allow'), + pht('Disallow'), + ))->setDescription( + pht( + 'Allow non-members to interact with tasks over email.')), ); } diff --git a/src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php b/src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php index a63d8a5241..c2418370a6 100644 --- a/src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php +++ b/src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php @@ -211,29 +211,52 @@ final class PhabricatorMetaMTAReceivedMail extends PhabricatorMetaMTADAO { if ($user) { $this->setAuthorPHID($user->getPHID()); } else { - $default_author = PhabricatorEnv::getEnvConfig( - 'metamta.maniphest.default-public-author'); + $allow_email_users = PhabricatorEnv::getEnvConfig( + 'phabricator.allow-email-users'); + + if ($allow_email_users) { + $email = new PhutilEmailAddress($from); + + $user = id(new PhabricatorExternalAccount())->loadOneWhere( + 'accountType = %s AND accountDomain IS NULL and accountID = %s', + 'email', $email->getAddress()); + + if (!$user) { + $user = new PhabricatorExternalAccount(); + $user->setAccountID($email->getAddress()); + $user->setAccountType('email'); + $user->setDisplayName($email->getDisplayName()); + $user->save(); - if ($default_author) { - $user = id(new PhabricatorUser())->loadOneWhere( - 'username = %s', - $default_author); - if ($user) { - $receiver->setOriginalEmailSource($from); - } else { - throw new Exception( - "Phabricator is misconfigured, the configuration key ". - "'metamta.maniphest.default-public-author' is set to user ". - "'{$default_author}' but that user does not exist."); } + } else { - // TODO: We should probably bounce these since from the user's - // perspective their email vanishes into a black hole. - return $this->setMessage("Invalid public user '{$from}'.")->save(); + $default_author = PhabricatorEnv::getEnvConfig( + 'metamta.maniphest.default-public-author'); + + if ($default_author) { + $user = id(new PhabricatorUser())->loadOneWhere( + 'username = %s', + $default_author); + + if (!$user) { + throw new Exception( + "Phabricator is misconfigured, the configuration key ". + "'metamta.maniphest.default-public-author' is set to user ". + "'{$default_author}' but that user does not exist."); + } + + } else { + // TODO: We should probably bounce these since from the user's + // perspective their email vanishes into a black hole. + return $this->setMessage("Invalid public user '{$from}'.")->save(); + } } + } $receiver->setAuthorPHID($user->getPHID()); + $receiver->setOriginalEmailSource($from); $receiver->setPriority(ManiphestTaskPriority::PRIORITY_TRIAGE); $editor = new ManiphestTransactionEditor(); @@ -242,7 +265,7 @@ final class PhabricatorMetaMTAReceivedMail extends PhabricatorMetaMTADAO { $handler->setActor($user); $handler->setExcludeMailRecipientPHIDs( - $this->loadExcludeMailRecipientPHIDs()); + $this->loadExcludeMailRecipientPHIDs()); $handler->processEmail($this); $this->setRelatedPHID($receiver->getPHID()); diff --git a/src/applications/people/storage/PhabricatorExternalAccount.php b/src/applications/people/storage/PhabricatorExternalAccount.php index 8614ba789b..cffffdb482 100644 --- a/src/applications/people/storage/PhabricatorExternalAccount.php +++ b/src/applications/people/storage/PhabricatorExternalAccount.php @@ -2,15 +2,22 @@ final class PhabricatorExternalAccount extends PhabricatorUserDAO { - private $userPHID; - private $accountType; - private $accountDomain; - private $accountSecret; - private $accountID; - private $displayName; + protected $userPHID; + protected $accountType; + protected $accountDomain; + protected $accountSecret; + protected $accountID; + protected $displayName; public function generatePHID() { return PhabricatorPHID::generateNewPHID( PhabricatorPHIDConstants::PHID_TYPE_XUSR); } + + public function getConfiguration() { + return array( + self::CONFIG_AUX_PHID => true, + ) + parent::getConfiguration(); + } + }