diff --git a/src/applications/people/controller/PhabricatorPeopleProfileController.php b/src/applications/people/controller/PhabricatorPeopleProfileController.php --- a/src/applications/people/controller/PhabricatorPeopleProfileController.php +++ b/src/applications/people/controller/PhabricatorPeopleProfileController.php @@ -136,11 +136,14 @@ ->setWorkflow(true) ->setHref($this->getApplicationURI('delete/'.$user->getID().'/'))); + $can_welcome = $user->canEstablishWebSessions(); + $actions->addAction( id(new PhabricatorActionView()) ->setIcon('fa-envelope') ->setName(pht('Send Welcome Email')) ->setWorkflow(true) + ->setDisabled(!$can_welcome) ->setHref($this->getApplicationURI('welcome/'.$user->getID().'/'))); } diff --git a/src/applications/people/controller/PhabricatorPeopleWelcomeController.php b/src/applications/people/controller/PhabricatorPeopleWelcomeController.php --- a/src/applications/people/controller/PhabricatorPeopleWelcomeController.php +++ b/src/applications/people/controller/PhabricatorPeopleWelcomeController.php @@ -3,19 +3,12 @@ final class PhabricatorPeopleWelcomeController extends PhabricatorPeopleController { - private $id; - - public function willProcessRequest(array $data) { - $this->id = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); - $admin = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $admin = $this->getViewer(); $user = id(new PhabricatorPeopleQuery()) ->setViewer($admin) - ->withIDs(array($this->id)) + ->withIDs(array($request->getURIData('id'))) ->executeOne(); if (!$user) { return new Aphront404Response(); @@ -23,6 +16,18 @@ $profile_uri = '/p/'.$user->getUsername().'/'; + if (!$user->canEstablishWebSessions()) { + return $this->newDialog() + ->setTitle(pht('Not a Normal User')) + ->appendParagraph( + 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')); + } + if ($request->isFormPost()) { $user->sendWelcomeEmail($admin); return id(new AphrontRedirectResponse())->setURI($profile_uri); diff --git a/src/applications/people/storage/PhabricatorUser.php b/src/applications/people/storage/PhabricatorUser.php --- a/src/applications/people/storage/PhabricatorUser.php +++ b/src/applications/people/storage/PhabricatorUser.php @@ -587,6 +587,13 @@ } public function sendWelcomeEmail(PhabricatorUser $admin) { + if (!$this->canEstablishWebSessions()) { + throw new Exception( + pht( + 'Can not send welcome mail to users who can not establish '. + 'web sessions!')); + } + $admin_username = $admin->getUserName(); $admin_realname = $admin->getRealName(); $user_username = $this->getUserName();