mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 04:20:55 +01:00
Don't allow welcome mail to be sent to users who can't login
Summary: Fixes T9446. We allow administrators to send "Welcome" mail to bots and mailing lists. This is harmless (these links do not function), but confusing. Instead, disable this option in the UI and explain why it is disabled when it is clicked. Also prevent generation of this mail lower in the stack. Test Plan: - Viewed a bot page, saw action disabled, clicked it, got explanation. - Viewed a normal user page, saw action enabled, clicked it, sent welcome email. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9446 Differential Revision: https://secure.phabricator.com/D14134
This commit is contained in:
parent
9ea6249a18
commit
a0ed843d47
3 changed files with 25 additions and 10 deletions
|
@ -136,11 +136,14 @@ final class PhabricatorPeopleProfileController
|
|||
->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().'/')));
|
||||
}
|
||||
|
||||
|
|
|
@ -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 @@ final class PhabricatorPeopleWelcomeController
|
|||
|
||||
$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);
|
||||
|
|
|
@ -587,6 +587,13 @@ final class PhabricatorUser
|
|||
}
|
||||
|
||||
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();
|
||||
|
|
Loading…
Reference in a new issue