@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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