Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / people / controller / PhabricatorPeopleInviteSendController.php
blobe611606a794af35796f4e893aec92a65b8c71ced
1 <?php
3 final class PhabricatorPeopleInviteSendController
4 extends PhabricatorPeopleInviteController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $this->getViewer();
9 $this->requireApplicationCapability(
10 PeopleCreateUsersCapability::CAPABILITY);
12 $is_confirm = false;
13 $errors = array();
14 $confirm_errors = array();
15 $e_emails = true;
17 $message = $request->getStr('message');
18 $emails = $request->getStr('emails');
19 $severity = PHUIInfoView::SEVERITY_ERROR;
20 if ($request->isFormPost()) {
21 // NOTE: We aren't using spaces as a delimiter here because email
22 // addresses with names often include spaces.
23 $email_list = preg_split('/[,;\n]+/', $emails);
24 foreach ($email_list as $key => $email) {
25 if (!strlen(trim($email))) {
26 unset($email_list[$key]);
30 if ($email_list) {
31 $e_emails = null;
32 } else {
33 $e_emails = pht('Required');
34 $errors[] = pht(
35 'To send invites, you must enter at least one email address.');
38 if (!$errors) {
39 $is_confirm = true;
41 $actions = PhabricatorAuthInviteAction::newActionListFromAddresses(
42 $viewer,
43 $email_list);
45 $any_valid = false;
46 $all_valid = true;
47 foreach ($actions as $action) {
48 if ($action->willSend()) {
49 $any_valid = true;
50 } else {
51 $all_valid = false;
55 if (!$any_valid) {
56 $confirm_errors[] = pht(
57 'None of the provided addresses are valid invite recipients. '.
58 'Review the table below for details. Revise the address list '.
59 'to continue.');
60 } else if ($all_valid) {
61 $confirm_errors[] = pht(
62 'All of the addresses appear to be valid invite recipients. '.
63 'Confirm the actions below to continue.');
64 $severity = PHUIInfoView::SEVERITY_NOTICE;
65 } else {
66 $confirm_errors[] = pht(
67 'Some of the addresses you entered do not appear to be '.
68 'valid recipients. Review the table below. You can revise '.
69 'the address list, or ignore these errors and continue.');
70 $severity = PHUIInfoView::SEVERITY_WARNING;
73 if ($any_valid && $request->getBool('confirm')) {
75 // TODO: The copywriting on this mail could probably be more
76 // engaging and we could have a fancy HTML version.
78 $template = array();
79 $template[] = pht(
80 '%s has invited you to join Phabricator.',
81 $viewer->getFullName());
83 if (strlen(trim($message))) {
84 $template[] = $message;
87 $template[] = pht(
88 'To register an account and get started, follow this link:');
90 // This isn't a variable; it will be replaced later on in the
91 // daemons once they generate the URI.
92 $template[] = '{$INVITE_URI}';
94 $template[] = pht(
95 'If you already have an account, you can follow the link to '.
96 'quickly verify this email address.');
98 $template = implode("\n\n", $template);
100 foreach ($actions as $action) {
101 if ($action->willSend()) {
102 $action->sendInvite($viewer, $template);
106 // TODO: This is a bit anticlimactic. We don't really have anything
107 // to show the user because the action is happening in the background
108 // and the invites won't exist yet. After T5166 we can show a
109 // better progress bar.
110 return id(new AphrontRedirectResponse())
111 ->setURI($this->getApplicationURI());
116 if ($is_confirm) {
117 $title = pht('Confirm Invites');
118 } else {
119 $title = pht('Invite Users');
122 $crumbs = $this->buildApplicationCrumbs();
123 if ($is_confirm) {
124 $crumbs->addTextCrumb(pht('Confirm'));
125 } else {
126 $crumbs->addTextCrumb(pht('Invite Users'));
128 $crumbs->setBorder(true);
130 $confirm_box = null;
131 $info_view = null;
132 if ($is_confirm) {
134 $handles = array();
135 if ($actions) {
136 $handles = $this->loadViewerHandles(mpull($actions, 'getUserPHID'));
139 $invite_table = id(new PhabricatorAuthInviteActionTableView())
140 ->setUser($viewer)
141 ->setInviteActions($actions)
142 ->setHandles($handles);
144 $confirm_form = null;
145 if ($any_valid) {
146 $confirm_form = id(new AphrontFormView())
147 ->setUser($viewer)
148 ->addHiddenInput('message', $message)
149 ->addHiddenInput('emails', $emails)
150 ->addHiddenInput('confirm', true)
151 ->appendRemarkupInstructions(
152 pht(
153 'If everything looks good, click **Send Invitations** to '.
154 'deliver email invitations these users. Otherwise, edit the '.
155 'email list or personal message at the bottom of the page to '.
156 'revise the invitations.'))
157 ->appendChild(
158 id(new AphrontFormSubmitControl())
159 ->setValue(pht('Send Invitations')));
162 $info_view = id(new PHUIInfoView())
163 ->setErrors($confirm_errors)
164 ->setSeverity($severity);
166 $confirm_box = id(new PHUIObjectBoxView())
167 ->setHeaderText(pht('Confirm Invites'))
168 ->setTable($invite_table)
169 ->appendChild($confirm_form)
170 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);
173 $form = id(new AphrontFormView())
174 ->setUser($viewer)
175 ->appendRemarkupInstructions(
176 pht(
177 'To invite users to Phabricator, enter their email addresses below. '.
178 'Separate addresses with commas or newlines.'))
179 ->appendChild(
180 id(new AphrontFormTextAreaControl())
181 ->setLabel(pht('Email Addresses'))
182 ->setName(pht('emails'))
183 ->setValue($emails)
184 ->setError($e_emails)
185 ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL))
186 ->appendRemarkupInstructions(
187 pht(
188 'You can optionally include a heartfelt personal message in '.
189 'the email.'))
190 ->appendChild(
191 id(new AphrontFormTextAreaControl())
192 ->setLabel(pht('Message'))
193 ->setName(pht('message'))
194 ->setValue($message))
195 ->appendChild(
196 id(new AphrontFormSubmitControl())
197 ->setValue(
198 $is_confirm
199 ? pht('Update Preview')
200 : pht('Continue'))
201 ->addCancelButton($this->getApplicationURI('invite/')));
203 $header = id(new PHUIHeaderView())
204 ->setHeader($title)
205 ->setHeaderIcon('fa-group');
207 $box = id(new PHUIObjectBoxView())
208 ->setHeaderText(
209 $is_confirm
210 ? pht('Revise Invites')
211 : pht('Invite Users'))
212 ->setFormErrors($errors)
213 ->setForm($form)
214 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);
216 $view = id(new PHUITwoColumnView())
217 ->setHeader($header)
218 ->setFooter(array(
219 $info_view,
220 $confirm_box,
221 $box,
224 return $this->newPage()
225 ->setTitle($title)
226 ->setCrumbs($crumbs)
227 ->appendChild($view);