Differential D19989 Diff 47748 src/applications/people/controller/PhabricatorPeopleWelcomeController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/people/controller/PhabricatorPeopleWelcomeController.php
<?php | <?php | ||||
final class PhabricatorPeopleWelcomeController | final class PhabricatorPeopleWelcomeController | ||||
extends PhabricatorPeopleController { | extends PhabricatorPeopleController { | ||||
public function shouldRequireAdmin() { | |||||
// You need to be an administrator to actually send welcome email, but | |||||
// we let anyone hit this page so they can get a nice error dialog | |||||
// explaining the issue. | |||||
return false; | |||||
} | |||||
public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
$admin = $this->getViewer(); | $admin = $this->getViewer(); | ||||
$user = id(new PhabricatorPeopleQuery()) | $user = id(new PhabricatorPeopleQuery()) | ||||
->setViewer($admin) | ->setViewer($admin) | ||||
->withIDs(array($request->getURIData('id'))) | ->withIDs(array($request->getURIData('id'))) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$user) { | if (!$user) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$profile_uri = '/p/'.$user->getUsername().'/'; | $id = $user->getID(); | ||||
$profile_uri = "/people/manage/{$id}/"; | |||||
if (!$user->canEstablishWebSessions()) { | $welcome_engine = id(new PhabricatorPeopleWelcomeMailEngine()) | ||||
->setSender($admin) | |||||
->setRecipient($user); | |||||
try { | |||||
$welcome_engine->validateMail(); | |||||
} catch (PhabricatorPeopleMailEngineException $ex) { | |||||
return $this->newDialog() | return $this->newDialog() | ||||
->setTitle(pht('Not a Normal User')) | ->setTitle($ex->getTitle()) | ||||
->appendParagraph( | ->appendParagraph($ex->getBody()) | ||||
pht( | |||||
'You can not send this user a welcome mail because they are not '. | |||||
'a normal user and can not log in to the web interface. Special '. | |||||
'users (like bots and mailing lists) are unable to establish web '. | |||||
'sessions.')) | |||||
->addCancelButton($profile_uri, pht('Done')); | ->addCancelButton($profile_uri, pht('Done')); | ||||
} | } | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$user->sendWelcomeEmail($admin); | $welcome_engine->sendMail(); | ||||
return id(new AphrontRedirectResponse())->setURI($profile_uri); | return id(new AphrontRedirectResponse())->setURI($profile_uri); | ||||
} | } | ||||
return $this->newDialog() | return $this->newDialog() | ||||
->setTitle(pht('Send Welcome Email')) | ->setTitle(pht('Send Welcome Email')) | ||||
->appendParagraph( | ->appendParagraph( | ||||
pht( | pht( | ||||
'This will send the user another copy of the "Welcome to '. | 'This will send the user another copy of the "Welcome to '. | ||||
Show All 13 Lines |