Skip to content

Commit f53cde8

Browse files
Zedstarepriestley
authored andcommitted
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
1 parent 09ed955 commit f53cde8

File tree

4 files changed

+65
-25
lines changed

4 files changed

+65
-25
lines changed

conf/default.conf.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,6 @@
547547
// preferences.
548548
'metamta.vary-subjects' => true,
549549

550-
551550
// -- Auth ------------------------------------------------------------------ //
552551

553552
// Can users login with a username/password, or by following the link from
@@ -850,6 +849,9 @@
850849
// Contains a list of uninstalled applications
851850
'phabricator.uninstalled-applications' => array(),
852851

852+
// Allowing non-members to interact with tasks over email.
853+
'phabricator.allow-email-users' => false,
854+
853855
// -- Welcome Screen -------------------------------------------------------- //
854856

855857
// The custom HTML content for the Phabricator welcome screen.

src/applications/config/option/PhabricatorCoreConfigOptions.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ public function getOptions() {
153153
$this->newOption('phabricator.cache-namespace', 'string', null)
154154
->setLocked(true)
155155
->setDescription(pht('Cache namespace.')),
156+
$this->newOption('phabricator.allow-email-users', 'bool', false)
157+
->setBoolOptions(
158+
array(
159+
pht('Allow'),
160+
pht('Disallow'),
161+
))->setDescription(
162+
pht(
163+
'Allow non-members to interact with tasks over email.')),
156164
);
157165

158166
}

src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -211,29 +211,52 @@ public function processReceivedMail() {
211211
if ($user) {
212212
$this->setAuthorPHID($user->getPHID());
213213
} else {
214-
$default_author = PhabricatorEnv::getEnvConfig(
215-
'metamta.maniphest.default-public-author');
216-
217-
if ($default_author) {
218-
$user = id(new PhabricatorUser())->loadOneWhere(
219-
'username = %s',
220-
$default_author);
221-
if ($user) {
222-
$receiver->setOriginalEmailSource($from);
223-
} else {
224-
throw new Exception(
225-
"Phabricator is misconfigured, the configuration key ".
226-
"'metamta.maniphest.default-public-author' is set to user ".
227-
"'{$default_author}' but that user does not exist.");
214+
$allow_email_users = PhabricatorEnv::getEnvConfig(
215+
'phabricator.allow-email-users');
216+
217+
if ($allow_email_users) {
218+
$email = new PhutilEmailAddress($from);
219+
220+
$user = id(new PhabricatorExternalAccount())->loadOneWhere(
221+
'accountType = %s AND accountDomain IS NULL and accountID = %s',
222+
'email', $email->getAddress());
223+
224+
if (!$user) {
225+
$user = new PhabricatorExternalAccount();
226+
$user->setAccountID($email->getAddress());
227+
$user->setAccountType('email');
228+
$user->setDisplayName($email->getDisplayName());
229+
$user->save();
230+
228231
}
232+
229233
} else {
230-
// TODO: We should probably bounce these since from the user's
231-
// perspective their email vanishes into a black hole.
232-
return $this->setMessage("Invalid public user '{$from}'.")->save();
234+
$default_author = PhabricatorEnv::getEnvConfig(
235+
'metamta.maniphest.default-public-author');
236+
237+
if ($default_author) {
238+
$user = id(new PhabricatorUser())->loadOneWhere(
239+
'username = %s',
240+
$default_author);
241+
242+
if (!$user) {
243+
throw new Exception(
244+
"Phabricator is misconfigured, the configuration key ".
245+
"'metamta.maniphest.default-public-author' is set to user ".
246+
"'{$default_author}' but that user does not exist.");
247+
}
248+
249+
} else {
250+
// TODO: We should probably bounce these since from the user's
251+
// perspective their email vanishes into a black hole.
252+
return $this->setMessage("Invalid public user '{$from}'.")->save();
253+
}
233254
}
255+
234256
}
235257

236258
$receiver->setAuthorPHID($user->getPHID());
259+
$receiver->setOriginalEmailSource($from);
237260
$receiver->setPriority(ManiphestTaskPriority::PRIORITY_TRIAGE);
238261

239262
$editor = new ManiphestTransactionEditor();
@@ -242,7 +265,7 @@ public function processReceivedMail() {
242265

243266
$handler->setActor($user);
244267
$handler->setExcludeMailRecipientPHIDs(
245-
$this->loadExcludeMailRecipientPHIDs());
268+
$this->loadExcludeMailRecipientPHIDs());
246269
$handler->processEmail($this);
247270

248271
$this->setRelatedPHID($receiver->getPHID());

src/applications/people/storage/PhabricatorExternalAccount.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@
22

33
final class PhabricatorExternalAccount extends PhabricatorUserDAO {
44

5-
private $userPHID;
6-
private $accountType;
7-
private $accountDomain;
8-
private $accountSecret;
9-
private $accountID;
10-
private $displayName;
5+
protected $userPHID;
6+
protected $accountType;
7+
protected $accountDomain;
8+
protected $accountSecret;
9+
protected $accountID;
10+
protected $displayName;
1111

1212
public function generatePHID() {
1313
return PhabricatorPHID::generateNewPHID(
1414
PhabricatorPHIDConstants::PHID_TYPE_XUSR);
1515
}
16+
17+
public function getConfiguration() {
18+
return array(
19+
self::CONFIG_AUX_PHID => true,
20+
) + parent::getConfiguration();
21+
}
22+
1623
}

0 commit comments

Comments
 (0)