2015-02-11 15:05:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorPeopleInviteSendController
|
|
|
|
extends PhabricatorPeopleInviteController {
|
|
|
|
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
$this->requireApplicationCapability(
|
|
|
|
PeopleCreateUsersCapability::CAPABILITY);
|
|
|
|
|
|
|
|
$is_confirm = false;
|
|
|
|
$errors = array();
|
|
|
|
$confirm_errors = array();
|
|
|
|
$e_emails = true;
|
|
|
|
|
|
|
|
$message = $request->getStr('message');
|
|
|
|
$emails = $request->getStr('emails');
|
2015-03-01 23:45:56 +01:00
|
|
|
$severity = PHUIInfoView::SEVERITY_ERROR;
|
2015-02-11 15:05:53 +01:00
|
|
|
if ($request->isFormPost()) {
|
|
|
|
// NOTE: We aren't using spaces as a delimiter here because email
|
|
|
|
// addresses with names often include spaces.
|
|
|
|
$email_list = preg_split('/[,;\n]+/', $emails);
|
|
|
|
foreach ($email_list as $key => $email) {
|
|
|
|
if (!strlen(trim($email))) {
|
|
|
|
unset($email_list[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($email_list) {
|
|
|
|
$e_emails = null;
|
|
|
|
} else {
|
|
|
|
$e_emails = pht('Required');
|
|
|
|
$errors[] = pht(
|
|
|
|
'To send invites, you must enter at least one email address.');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$errors) {
|
|
|
|
$is_confirm = true;
|
|
|
|
|
|
|
|
$actions = PhabricatorAuthInviteAction::newActionListFromAddresses(
|
|
|
|
$viewer,
|
|
|
|
$email_list);
|
|
|
|
|
|
|
|
$any_valid = false;
|
|
|
|
$all_valid = true;
|
|
|
|
foreach ($actions as $action) {
|
2015-02-11 15:06:09 +01:00
|
|
|
if ($action->willSend()) {
|
2015-02-11 15:05:53 +01:00
|
|
|
$any_valid = true;
|
|
|
|
} else {
|
|
|
|
$all_valid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$any_valid) {
|
|
|
|
$confirm_errors[] = pht(
|
|
|
|
'None of the provided addresses are valid invite recipients. '.
|
|
|
|
'Review the table below for details. Revise the address list '.
|
|
|
|
'to continue.');
|
|
|
|
} else if ($all_valid) {
|
|
|
|
$confirm_errors[] = pht(
|
|
|
|
'All of the addresses appear to be valid invite recipients. '.
|
|
|
|
'Confirm the actions below to continue.');
|
2015-03-01 23:45:56 +01:00
|
|
|
$severity = PHUIInfoView::SEVERITY_NOTICE;
|
2015-02-11 15:05:53 +01:00
|
|
|
} else {
|
|
|
|
$confirm_errors[] = pht(
|
|
|
|
'Some of the addresses you entered do not appear to be '.
|
|
|
|
'valid recipients. Review the table below. You can revise '.
|
|
|
|
'the address list, or ignore these errors and continue.');
|
2015-03-01 23:45:56 +01:00
|
|
|
$severity = PHUIInfoView::SEVERITY_WARNING;
|
2015-02-11 15:05:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($any_valid && $request->getBool('confirm')) {
|
2015-02-11 15:06:09 +01:00
|
|
|
|
|
|
|
// TODO: The copywriting on this mail could probably be more
|
|
|
|
// engaging and we could have a fancy HTML version.
|
|
|
|
|
|
|
|
$template = array();
|
|
|
|
$template[] = pht(
|
|
|
|
'%s has invited you to join Phabricator.',
|
|
|
|
$viewer->getFullName());
|
|
|
|
|
|
|
|
if (strlen(trim($message))) {
|
|
|
|
$template[] = $message;
|
|
|
|
}
|
|
|
|
|
|
|
|
$template[] = pht(
|
|
|
|
'To register an account and get started, follow this link:');
|
|
|
|
|
|
|
|
// This isn't a variable; it will be replaced later on in the
|
|
|
|
// daemons once they generate the URI.
|
|
|
|
$template[] = '{$INVITE_URI}';
|
|
|
|
|
|
|
|
$template[] = pht(
|
|
|
|
'If you already have an account, you can follow the link to '.
|
|
|
|
'quickly verify this email address.');
|
|
|
|
|
|
|
|
$template = implode("\n\n", $template);
|
|
|
|
|
|
|
|
foreach ($actions as $action) {
|
|
|
|
if ($action->willSend()) {
|
|
|
|
$action->sendInvite($viewer, $template);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: This is a bit anticlimactic. We don't really have anything
|
|
|
|
// to show the user because the action is happening in the background
|
|
|
|
// and the invites won't exist yet. After T5166 we can show a
|
|
|
|
// better progress bar.
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI($this->getApplicationURI());
|
2015-02-11 15:05:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($is_confirm) {
|
|
|
|
$title = pht('Confirm Invites');
|
|
|
|
} else {
|
|
|
|
$title = pht('Invite Users');
|
|
|
|
}
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
if ($is_confirm) {
|
|
|
|
$crumbs->addTextCrumb(pht('Confirm'));
|
|
|
|
} else {
|
|
|
|
$crumbs->addTextCrumb(pht('Invite Users'));
|
|
|
|
}
|
2016-04-04 06:01:48 +02:00
|
|
|
$crumbs->setBorder(true);
|
2015-02-11 15:05:53 +01:00
|
|
|
|
|
|
|
$confirm_box = null;
|
2016-04-04 06:01:48 +02:00
|
|
|
$info_view = null;
|
2015-02-11 15:05:53 +01:00
|
|
|
if ($is_confirm) {
|
|
|
|
|
|
|
|
$handles = array();
|
|
|
|
if ($actions) {
|
|
|
|
$handles = $this->loadViewerHandles(mpull($actions, 'getUserPHID'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$invite_table = id(new PhabricatorAuthInviteActionTableView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setInviteActions($actions)
|
|
|
|
->setHandles($handles);
|
|
|
|
|
|
|
|
$confirm_form = null;
|
|
|
|
if ($any_valid) {
|
|
|
|
$confirm_form = id(new AphrontFormView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->addHiddenInput('message', $message)
|
|
|
|
->addHiddenInput('emails', $emails)
|
|
|
|
->addHiddenInput('confirm', true)
|
|
|
|
->appendRemarkupInstructions(
|
|
|
|
pht(
|
|
|
|
'If everything looks good, click **Send Invitations** to '.
|
|
|
|
'deliver email invitations these users. Otherwise, edit the '.
|
|
|
|
'email list or personal message at the bottom of the page to '.
|
|
|
|
'revise the invitations.'))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->setValue(pht('Send Invitations')));
|
|
|
|
}
|
|
|
|
|
2016-04-04 06:01:48 +02:00
|
|
|
$info_view = id(new PHUIInfoView())
|
|
|
|
->setErrors($confirm_errors)
|
|
|
|
->setSeverity($severity);
|
|
|
|
|
2015-02-11 15:05:53 +01:00
|
|
|
$confirm_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeaderText(pht('Confirm Invites'))
|
[Redesign] Add Table, Collapse support to ObjectBox
Summary: Converts most all tables to be directly set via `setTable` to an ObjectBox. I think this path is more flexible design wise, as we can change the box based on children, and not just CSS. We also already do this with PropertyList, Forms, ObjectList, and Header. `setCollapsed` is added to ObjectBox to all children objects to bleed to the edges (like diffs).
Test Plan: I did a grep of `appendChild($table)` as well as searches for `PHUIObjectBoxView`, also with manual opening of hundreds of files. I'm sure I missed 5-8 places. If you just appendChild($table) nothing breaks, it just looks a little funny.
Reviewers: epriestley, btrahan
Subscribers: Korvin, epriestley
Differential Revision: https://secure.phabricator.com/D12955
2015-05-20 21:43:34 +02:00
|
|
|
->setTable($invite_table)
|
2016-04-04 06:01:48 +02:00
|
|
|
->appendChild($confirm_form)
|
|
|
|
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);
|
2015-02-11 15:05:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->appendRemarkupInstructions(
|
|
|
|
pht(
|
|
|
|
'To invite users to Phabricator, enter their email addresses below. '.
|
|
|
|
'Separate addresses with commas or newlines.'))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextAreaControl())
|
|
|
|
->setLabel(pht('Email Addresses'))
|
|
|
|
->setName(pht('emails'))
|
|
|
|
->setValue($emails)
|
|
|
|
->setError($e_emails)
|
|
|
|
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL))
|
|
|
|
->appendRemarkupInstructions(
|
|
|
|
pht(
|
|
|
|
'You can optionally include a heartfelt personal message in '.
|
|
|
|
'the email.'))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextAreaControl())
|
|
|
|
->setLabel(pht('Message'))
|
|
|
|
->setName(pht('message'))
|
2015-02-16 20:09:07 +01:00
|
|
|
->setValue($message))
|
2015-02-11 15:05:53 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->setValue(
|
|
|
|
$is_confirm
|
|
|
|
? pht('Update Preview')
|
|
|
|
: pht('Continue'))
|
|
|
|
->addCancelButton($this->getApplicationURI('invite/')));
|
|
|
|
|
2016-04-04 06:01:48 +02:00
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader($title)
|
|
|
|
->setHeaderIcon('fa-group');
|
|
|
|
|
2015-02-11 15:05:53 +01:00
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeaderText(
|
|
|
|
$is_confirm
|
|
|
|
? pht('Revise Invites')
|
|
|
|
: pht('Invite Users'))
|
|
|
|
->setFormErrors($errors)
|
2016-04-04 06:01:48 +02:00
|
|
|
->setForm($form)
|
|
|
|
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);
|
2015-02-11 15:05:53 +01:00
|
|
|
|
2016-04-04 06:01:48 +02:00
|
|
|
$view = id(new PHUITwoColumnView())
|
|
|
|
->setHeader($header)
|
|
|
|
->setFooter(array(
|
|
|
|
$info_view,
|
2015-02-11 15:05:53 +01:00
|
|
|
$confirm_box,
|
|
|
|
$box,
|
|
|
|
));
|
2016-04-04 06:01:48 +02:00
|
|
|
|
|
|
|
return $this->newPage()
|
|
|
|
->setTitle($title)
|
|
|
|
->setCrumbs($crumbs)
|
|
|
|
->appendChild($view);
|
|
|
|
|
2015-02-11 15:05:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|