Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/people/controller/PhabricatorPeopleInviteSendController.php
12262 views
1
<?php
2
3
final class PhabricatorPeopleInviteSendController
4
extends PhabricatorPeopleInviteController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$viewer = $this->getViewer();
8
9
$this->requireApplicationCapability(
10
PeopleCreateUsersCapability::CAPABILITY);
11
12
$is_confirm = false;
13
$errors = array();
14
$confirm_errors = array();
15
$e_emails = true;
16
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]);
27
}
28
}
29
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.');
36
}
37
38
if (!$errors) {
39
$is_confirm = true;
40
41
$actions = PhabricatorAuthInviteAction::newActionListFromAddresses(
42
$viewer,
43
$email_list);
44
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;
52
}
53
}
54
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;
71
}
72
73
if ($any_valid && $request->getBool('confirm')) {
74
75
// TODO: The copywriting on this mail could probably be more
76
// engaging and we could have a fancy HTML version.
77
78
$template = array();
79
$template[] = pht(
80
'%s has invited you to join %s.',
81
$viewer->getFullName(),
82
PlatformSymbols::getPlatformServerName());
83
84
if (strlen(trim($message))) {
85
$template[] = $message;
86
}
87
88
$template[] = pht(
89
'To register an account and get started, follow this link:');
90
91
// This isn't a variable; it will be replaced later on in the
92
// daemons once they generate the URI.
93
$template[] = '{$INVITE_URI}';
94
95
$template[] = pht(
96
'If you already have an account, you can follow the link to '.
97
'quickly verify this email address.');
98
99
$template = implode("\n\n", $template);
100
101
foreach ($actions as $action) {
102
if ($action->willSend()) {
103
$action->sendInvite($viewer, $template);
104
}
105
}
106
107
// TODO: This is a bit anticlimactic. We don't really have anything
108
// to show the user because the action is happening in the background
109
// and the invites won't exist yet. After T5166 we can show a
110
// better progress bar.
111
return id(new AphrontRedirectResponse())
112
->setURI($this->getApplicationURI());
113
}
114
}
115
}
116
117
if ($is_confirm) {
118
$title = pht('Confirm Invites');
119
} else {
120
$title = pht('Invite Users');
121
}
122
123
$crumbs = $this->buildApplicationCrumbs();
124
if ($is_confirm) {
125
$crumbs->addTextCrumb(pht('Confirm'));
126
} else {
127
$crumbs->addTextCrumb(pht('Invite Users'));
128
}
129
$crumbs->setBorder(true);
130
131
$confirm_box = null;
132
$info_view = null;
133
if ($is_confirm) {
134
135
$handles = array();
136
if ($actions) {
137
$handles = $this->loadViewerHandles(mpull($actions, 'getUserPHID'));
138
}
139
140
$invite_table = id(new PhabricatorAuthInviteActionTableView())
141
->setUser($viewer)
142
->setInviteActions($actions)
143
->setHandles($handles);
144
145
$confirm_form = null;
146
if ($any_valid) {
147
$confirm_form = id(new AphrontFormView())
148
->setUser($viewer)
149
->addHiddenInput('message', $message)
150
->addHiddenInput('emails', $emails)
151
->addHiddenInput('confirm', true)
152
->appendRemarkupInstructions(
153
pht(
154
'If everything looks good, click **Send Invitations** to '.
155
'deliver email invitations these users. Otherwise, edit the '.
156
'email list or personal message at the bottom of the page to '.
157
'revise the invitations.'))
158
->appendChild(
159
id(new AphrontFormSubmitControl())
160
->setValue(pht('Send Invitations')));
161
}
162
163
$info_view = id(new PHUIInfoView())
164
->setErrors($confirm_errors)
165
->setSeverity($severity);
166
167
$confirm_box = id(new PHUIObjectBoxView())
168
->setHeaderText(pht('Confirm Invites'))
169
->setTable($invite_table)
170
->appendChild($confirm_form)
171
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);
172
}
173
174
$form = id(new AphrontFormView())
175
->setUser($viewer)
176
->appendRemarkupInstructions(
177
pht(
178
'To invite users, enter their email addresses below. '.
179
'Separate addresses with commas or newlines.'))
180
->appendChild(
181
id(new AphrontFormTextAreaControl())
182
->setLabel(pht('Email Addresses'))
183
->setName(pht('emails'))
184
->setValue($emails)
185
->setError($e_emails)
186
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL))
187
->appendRemarkupInstructions(
188
pht(
189
'You can optionally include a heartfelt personal message in '.
190
'the email.'))
191
->appendChild(
192
id(new AphrontFormTextAreaControl())
193
->setLabel(pht('Message'))
194
->setName(pht('message'))
195
->setValue($message))
196
->appendChild(
197
id(new AphrontFormSubmitControl())
198
->setValue(
199
$is_confirm
200
? pht('Update Preview')
201
: pht('Continue'))
202
->addCancelButton($this->getApplicationURI('invite/')));
203
204
$header = id(new PHUIHeaderView())
205
->setHeader($title)
206
->setHeaderIcon('fa-group');
207
208
$box = id(new PHUIObjectBoxView())
209
->setHeaderText(
210
$is_confirm
211
? pht('Revise Invites')
212
: pht('Invite Users'))
213
->setFormErrors($errors)
214
->setForm($form)
215
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);
216
217
$view = id(new PHUITwoColumnView())
218
->setHeader($header)
219
->setFooter(array(
220
$info_view,
221
$confirm_box,
222
$box,
223
));
224
225
return $this->newPage()
226
->setTitle($title)
227
->setCrumbs($crumbs)
228
->appendChild($view);
229
230
}
231
232
}
233
234