public function render() { $question = $this->question; $viewer = $this->user; $authors = mpull($question->getAnswers(), null, 'getAuthorPHID'); if (isset($authors[$viewer->getPHID()])) { $view = id(new PHUIInfoView())->setSeverity(PHUIInfoView::SEVERITY_NOTICE)->setTitle(pht('Already Answered'))->appendChild(pht('You have already answered this question. You can not answer ' . 'twice, but you can edit your existing answer.')); return phutil_tag_div('ponder-add-answer-view', $view); } $info_panel = null; if ($question->getStatus() != PonderQuestionStatus::STATUS_OPEN) { $info_panel = id(new PHUIInfoView())->setSeverity(PHUIInfoView::SEVERITY_NOTICE)->appendChild(pht('This question has been marked as closed, but you can still leave a new answer.')); } $box_style = null; $header = id(new PHUIHeaderView())->setHeader(pht('New Answer'))->addClass('ponder-add-answer-header'); $form = new AphrontFormView(); $form->setUser($this->user)->setAction($this->actionURI)->setWorkflow(true)->addHiddenInput('question_id', $question->getID())->appendChild(id(new PhabricatorRemarkupControl())->setName('answer')->setLabel(pht('Answer'))->setError(true)->setID('answer-content')->setUser($this->user))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Add Answer'))); if (!$viewer->isLoggedIn()) { $login_href = id(new PhutilURI('/auth/start/'))->setQueryParam('next', '/Q' . $question->getID()); $form = id(new PHUIFormLayoutView())->addClass('login-to-participate')->appendChild(id(new PHUIButtonView())->setTag('a')->setText(pht('Login to Answer'))->setHref((string) $login_href)); } $box = id(new PHUIObjectBoxView())->appendChild($form)->setHeaderText('Answer')->addClass('ponder-add-answer-view'); if ($info_panel) { $box->setInfoView($info_panel); } return array($header, $box); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); if ($request->isFormPost()) { $receiver = PhabricatorMetaMTAReceivedMail::loadReceiverObject($request->getStr('obj')); if (!$receiver) { throw new Exception("No such task or revision!"); } $hash = PhabricatorMetaMTAReceivedMail::computeMailHash($receiver->getMailKey(), $user->getPHID()); $received = new PhabricatorMetaMTAReceivedMail(); $received->setHeaders(array('to' => $request->getStr('obj') . '+' . $user->getID() . '+' . $hash . '@')); $received->setBodies(array('text' => $request->getStr('body'))); $received->save(); $received->processReceivedMail(); $phid = $receiver->getPHID(); $handles = $this->loadViewerHandles(array($phid)); $uri = $handles[$phid]->getURI(); return id(new AphrontRedirectResponse())->setURI($uri); } $form = new AphrontFormView(); $form->setUser($request->getUser()); $form->setAction($this->getApplicationURI('/receive/')); $form->appendChild('<p class="aphront-form-instructions">This form will simulate ' . 'sending mail to an object.</p>')->appendChild(id(new AphrontFormTextControl())->setLabel('To')->setName('obj')->setCaption('e.g. <tt>D1234</tt> or <tt>T1234</tt>'))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Body')->setName('body'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Receive Mail')); $panel = new AphrontPanelView(); $panel->setHeader('Receive Email'); $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $nav = $this->buildSideNavView(); $nav->selectFilter('receive'); $nav->appendChild($panel); return $this->buildApplicationPage($nav, array('title' => 'Receive Test')); }
public function processRequest(AphrontRequest $request) { $user = $request->getUser(); $ldap_info = id(new PhabricatorUserLDAPInfo())->loadOneWhere('userID = %d', $user->getID()); $forms = array(); if (!$ldap_info) { $unlink = 'Link LDAP Account'; $unlink_form = new AphrontFormView(); $unlink_form->setUser($user)->setAction('/ldap/login/')->appendChild('<p class="aphront-form-instructions">There is currently no ' . 'LDAP account linked to your Phabricator account. You can link an ' . 'account, which will allow you to use it to log into Phabricator</p>')->appendChild(id(new AphrontFormTextControl())->setLabel('LDAP username')->setName('username'))->appendChild(id(new AphrontFormPasswordControl())->setLabel('Password')->setName('password'))->appendChild(id(new AphrontFormSubmitControl())->setValue("Link LDAP Account »")); $forms['Link Account'] = $unlink_form; } else { $unlink = 'Unlink LDAP Account'; $unlink_form = new AphrontFormView(); $unlink_form->setUser($user)->appendChild('<p class="aphront-form-instructions">You may unlink this account ' . 'from your LDAP account. This will prevent you from logging in with ' . 'your LDAP credentials.</p>')->appendChild(id(new AphrontFormSubmitControl())->addCancelButton('/ldap/unlink/', $unlink)); $forms['Unlink Account'] = $unlink_form; } $panel = new AphrontPanelView(); $panel->setHeader('LDAP Account Settings'); $panel->setWidth(AphrontPanelView::WIDTH_FORM); foreach ($forms as $name => $form) { if ($name) { $panel->appendChild('<br /><h1>' . $name . '</h1><br />'); } $panel->appendChild($form); } return array($panel); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $editable = $this->getAccountEditable(); // There's no sense in showing a change password panel if the user // can't change their password if (!$editable || !PhabricatorEnv::getEnvConfig('auth.password-auth-enabled')) { return new Aphront400Response(); } $errors = array(); if ($request->isFormPost()) { if ($user->comparePassword($request->getStr('old_pw'))) { $pass = $request->getStr('new_pw'); $conf = $request->getStr('conf_pw'); if ($pass === $conf) { if (strlen($pass)) { $user->setPassword($pass); // This write is unguarded because the CSRF token has already // been checked in the call to $request->isFormPost() and // the CSRF token depends on the password hash, so when it // is changed here the CSRF token check will fail. $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); $user->save(); unset($unguarded); return id(new AphrontRedirectResponse())->setURI('/settings/page/password/?saved=true'); } else { $errors[] = 'Your new password is too short.'; } } else { $errors[] = 'New password and confirmation do not match.'; } } else { $errors[] = 'The old password you entered is incorrect.'; } } $notice = null; if (!$errors) { if ($request->getStr('saved')) { $notice = new AphrontErrorView(); $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE); $notice->setTitle('Changes Saved'); $notice->appendChild('<p>Your password has been updated.</p>'); } } else { $notice = new AphrontErrorView(); $notice->setTitle('Error Changing Password'); $notice->setErrors($errors); } $form = new AphrontFormView(); $form->setUser($user)->appendChild(id(new AphrontFormPasswordControl())->setLabel('Old Password')->setName('old_pw')); $form->appendChild(id(new AphrontFormPasswordControl())->setLabel('New Password')->setName('new_pw')); $form->appendChild(id(new AphrontFormPasswordControl())->setLabel('Confirm Password')->setName('conf_pw')); $form->appendChild(id(new AphrontFormSubmitControl())->setValue('Save')); $panel = new AphrontPanelView(); $panel->setHeader('Change Password'); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $panel->appendChild($form); return id(new AphrontNullView())->appendChild(array($notice, $panel)); }
public function processRequest(AphrontRequest $request) { $user = $request->getUser(); $username = $user->getUsername(); $pref_time = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT; $pref_date = PhabricatorUserPreferences::PREFERENCE_DATE_FORMAT; $pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY; $preferences = $user->loadPreferences(); $errors = array(); if ($request->isFormPost()) { $new_timezone = $request->getStr('timezone'); if (in_array($new_timezone, DateTimeZone::listIdentifiers(), true)) { $user->setTimezoneIdentifier($new_timezone); } else { $errors[] = pht('The selected timezone is not a valid timezone.'); } $preferences->setPreference($pref_time, $request->getStr($pref_time))->setPreference($pref_date, $request->getStr($pref_date))->setPreference($pref_week_start, $request->getStr($pref_week_start)); if (!$errors) { $preferences->save(); $user->save(); return id(new AphrontRedirectResponse())->setURI($this->getPanelURI('?saved=true')); } } $timezone_ids = DateTimeZone::listIdentifiers(); $timezone_id_map = array_fuse($timezone_ids); $form = new AphrontFormView(); $form->setUser($user)->appendChild(id(new AphrontFormSelectControl())->setLabel(pht('Timezone'))->setName('timezone')->setOptions($timezone_id_map)->setValue($user->getTimezoneIdentifier()))->appendChild(id(new AphrontFormSelectControl())->setLabel(pht('Time-of-Day Format'))->setName($pref_time)->setOptions(array('g:i A' => pht('12-hour (2:34 PM)'), 'H:i' => pht('24-hour (14:34)')))->setCaption(pht('Format used when rendering a time of day.'))->setValue($preferences->getPreference($pref_time)))->appendChild(id(new AphrontFormSelectControl())->setLabel(pht('Date Format'))->setName($pref_date)->setOptions(array('Y-m-d' => pht('ISO 8601 (2000-02-28)'), 'n/j/Y' => pht('US (2/28/2000)'), 'd-m-Y' => pht('European (28-02-2000)')))->setCaption(pht('Format used when rendering a date.'))->setValue($preferences->getPreference($pref_date)))->appendChild(id(new AphrontFormSelectControl())->setLabel(pht('Week Starts On'))->setOptions($this->getWeekDays())->setName($pref_week_start)->setCaption(pht('Calendar weeks will start with this day.'))->setValue($preferences->getPreference($pref_week_start, 0)))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Save Account Settings'))); $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Date and Time Settings'))->setFormSaved($request->getStr('saved'))->setFormErrors($errors)->setForm($form); return array($form_box); }
public function processRequest() { if ($this->id) { $macro = id(new PhabricatorFileImageMacro())->load($this->id); if (!$macro) { return new Aphront404Response(); } } else { $macro = new PhabricatorFileImageMacro(); } $errors = array(); $e_name = true; $request = $this->getRequest(); $user = $request->getUser(); if ($request->isFormPost()) { $macro->setName($request->getStr('name')); if (!strlen($macro->getName())) { $errors[] = 'Macro name is required.'; $e_name = 'Required'; } else { if (!preg_match('/^[a-z0-9_-]{3,}$/', $macro->getName())) { $errors[] = 'Macro must be at least three characters long and contain ' . 'only lowercase letters, digits, hyphen and underscore.'; $e_name = 'Invalid'; } else { $e_name = null; } } if (!$errors) { $file = PhabricatorFile::newFromPHPUpload(idx($_FILES, 'file'), array('name' => $request->getStr('name'), 'authorPHID' => $user->getPHID())); $macro->setFilePHID($file->getPHID()); try { $macro->save(); return id(new AphrontRedirectResponse())->setURI('/file/macro/'); } catch (AphrontQueryDuplicateKeyException $ex) { $errors[] = 'Macro name is not unique!'; $e_name = 'Duplicate'; } } } if ($errors) { $error_view = new AphrontErrorView(); $error_view->setTitle('Form Errors'); $error_view->setErrors($errors); } else { $error_view = null; } $form = new AphrontFormView(); $form->setAction('/file/macro/edit/'); $form->setUser($request->getUser()); $form->setEncType('multipart/form-data')->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($macro->getName())->setCaption('This word or phrase will be replaced with the image.')->setError($e_name))->appendChild(id(new AphrontFormFileControl())->setLabel('File')->setName('file')->setError(true))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save Image Macro')->addCancelButton('/file/macro/')); $panel = new AphrontPanelView(); if ($macro->getID()) { $panel->setHeader('Edit Image Macro'); } else { $panel->setHeader('Create Image Macro'); } $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Image Macro')); }
public function processRequest() { $event = id(new PhabricatorTimelineEvent('NULL'))->load($this->id); if (!$event) { return new Aphront404Response(); } $request = $this->getRequest(); $user = $request->getUser(); if ($event->getDataID()) { $data = id(new PhabricatorTimelineEventData())->load($event->getDataID()); } if ($data) { $data = json_encode($data->getEventData()); } else { $data = 'null'; } $form = new AphrontFormView(); $form->setUser($user)->appendChild(id(new AphrontFormStaticControl())->setLabel('ID')->setValue($event->getID()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Type')->setValue($event->getType()))->appendChild(id(new AphrontFormTextAreaControl())->setDisabled(true)->setLabel('Data')->setValue($data))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton('/daemon/timeline/')); $panel = new AphrontPanelView(); $panel->setHeader('Event'); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $panel->appendChild($form); $nav = $this->buildSideNavView(); $nav->selectFilter('timeline'); $nav->appendChild($panel); return $this->buildApplicationPage($nav, array('title' => 'Timeline Event')); }
public function processRequest() { $request = $this->getRequest(); $phids = $request->getStrList('phids'); if ($phids) { $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); $rows = array(); foreach ($handles as $handle) { if ($handle->getURI()) { $link = phutil_render_tag('a', array('href' => $handle->getURI()), phutil_escape_html($handle->getURI())); } else { $link = null; } $rows[] = array(phutil_escape_html($handle->getPHID()), phutil_escape_html($handle->getType()), phutil_escape_html($handle->getName()), $link); } $table = new AphrontTableView($rows); $table->setHeaders(array('PHID', 'Type', 'Name', 'URI')); $table->setColumnClasses(array(null, null, null, 'wide')); $panel = new AphrontPanelView(); $panel->setHeader('PHID Handles'); $panel->appendChild($table); return $this->buildStandardPageResponse($panel, array('title' => 'PHID Lookup Results')); } $lookup_form = new AphrontFormView(); $lookup_form->setUser($request->getUser()); $lookup_form->setAction('/phid/')->appendChild(id(new AphrontFormTextAreaControl())->setName('phids')->setCaption('Enter PHIDs separated by spaces or commas.'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Lookup PHIDs')); $lookup_panel = new AphrontPanelView(); $lookup_panel->setHeader('Lookup PHIDs'); $lookup_panel->appendChild($lookup_form); $lookup_panel->setWidth(AphrontPanelView::WIDTH_WIDE); return $this->buildStandardPageResponse(array($lookup_panel), array('title' => 'PHID Lookup')); }
public function render() { $question = $this->question; $viewer = $this->user; $authors = mpull($question->getAnswers(), null, 'getAuthorPHID'); if (isset($authors[$viewer->getPHID()])) { return id(new PHUIInfoView())->setSeverity(PHUIInfoView::SEVERITY_NOTICE)->setTitle(pht('Already Answered'))->appendChild(pht('You have already answered this question. You can not answer ' . 'twice, but you can edit your existing answer.')); } $info_panel = null; if ($question->getStatus() != PonderQuestionStatus::STATUS_OPEN) { $info_panel = id(new PHUIInfoView())->setSeverity(PHUIInfoView::SEVERITY_NOTICE)->appendChild(pht('This question has been marked as closed, but you can still leave a new answer.')); } $box_style = null; $own_question = null; $hide_action_id = celerity_generate_unique_node_id(); $show_action_id = celerity_generate_unique_node_id(); if ($question->getAuthorPHID() == $viewer->getPHID()) { $box_style = 'display: none;'; $open_link = javelin_tag('a', array('sigil' => 'reveal-content', 'class' => 'mml', 'id' => $hide_action_id, 'href' => '#', 'meta' => array('showIDs' => array($show_action_id), 'hideIDs' => array($hide_action_id))), pht('Add an answer.')); $own_question = id(new PHUIInfoView())->setSeverity(PHUIInfoView::SEVERITY_WARNING)->setID($hide_action_id)->appendChild(pht('This is your own question. You are welcome to provide an answer if you have found a resolution.'))->appendChild($open_link); } $header = id(new PHUIHeaderView())->setHeader(pht('Add Answer')); $form = new AphrontFormView(); $form->setUser($this->user)->setAction($this->actionURI)->setWorkflow(true)->addHiddenInput('question_id', $question->getID())->appendChild(id(new PhabricatorRemarkupControl())->setName('answer')->setLabel(pht('Answer'))->setError(true)->setID('answer-content')->setUser($this->user))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Add Answer'))); $box = id(new PHUIObjectBoxView())->setHeader($header)->appendChild($form); if ($info_panel) { $box->setInfoView($info_panel); } $box = phutil_tag('div', array('style' => $box_style, 'class' => 'mlt', 'id' => $show_action_id), $box); return array($own_question, $box); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $project = new PhabricatorProject(); $project->setAuthorPHID($user->getPHID()); $profile = new PhabricatorProjectProfile(); $e_name = true; $errors = array(); if ($request->isFormPost()) { try { $editor = new PhabricatorProjectEditor($project); $editor->setUser($user); $editor->setName($request->getStr('name')); $editor->save(); } catch (PhabricatorProjectNameCollisionException $ex) { $e_name = 'Not Unique'; $errors[] = $ex->getMessage(); } $project->setStatus(PhabricatorProjectStatus::ONGOING); $profile->setBlurb($request->getStr('blurb')); if (!$errors) { $project->save(); $profile->setProjectPHID($project->getPHID()); $profile->save(); id(new PhabricatorProjectAffiliation())->setUserPHID($user->getPHID())->setProjectPHID($project->getPHID())->setRole('Owner')->setIsOwner(true)->save(); if ($request->isAjax()) { return id(new AphrontAjaxResponse())->setContent(array('phid' => $project->getPHID(), 'name' => $project->getName())); } else { return id(new AphrontRedirectResponse())->setURI('/project/view/' . $project->getID() . '/'); } } } $error_view = null; if ($errors) { $error_view = new AphrontErrorView(); $error_view->setTitle('Form Errors'); $error_view->setErrors($errors); } if ($request->isAjax()) { $form = new AphrontFormLayoutView(); } else { $form = new AphrontFormView(); $form->setUser($user); } $form->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($project->getName())->setError($e_name))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Blurb')->setName('blurb')->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)->setValue($profile->getBlurb())); if ($request->isAjax()) { if ($error_view) { $error_view->setWidth(AphrontErrorView::WIDTH_DIALOG); } $dialog = id(new AphrontDialogView())->setUser($user)->setWidth(AphrontDialogView::WIDTH_FORM)->setTitle('Create a New Project')->appendChild($error_view)->appendChild($form)->addSubmitButton('Create Project')->addCancelButton('/project/'); return id(new AphrontDialogResponse())->setDialog($dialog); } else { $form->appendChild(id(new AphrontFormSubmitControl())->setValue('Create')->addCancelButton('/project/')); $panel = new AphrontPanelView(); $panel->setWidth(AphrontPanelView::WIDTH_FORM)->setHeader('Create a New Project')->appendChild($form); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Create new Project')); } }
public function render() { $question = $this->question; $header = id(new PHUIHeaderView())->setHeader(pht('Add Answer')); $form = new AphrontFormView(); $form->setUser($this->user)->setAction($this->actionURI)->setWorkflow(true)->addHiddenInput('question_id', $question->getID())->appendChild(id(new PhabricatorRemarkupControl())->setName('answer')->setLabel(pht('Answer'))->setError(true)->setID('answer-content')->setUser($this->user))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Add Answer'))); return id(new PHUIObjectBoxView())->setHeader($header)->appendChild($form); }
public function renderExample() { $filter = new AphrontListFilterView(); $form = new AphrontFormView(); $form->setUser($this->getRequest()->getUser()); $form->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Query')))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Search'))); $filter->appendChild($form); return $filter; }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $e_name = true; $e_callsign = true; $repository = new PhabricatorRepository(); $type_map = PhabricatorRepositoryType::getAllRepositoryTypes(); $errors = array(); if ($request->isFormPost()) { $repository->setName($request->getStr('name')); $repository->setCallsign($request->getStr('callsign')); $repository->setVersionControlSystem($request->getStr('type')); if (!strlen($repository->getName())) { $e_name = 'Required'; $errors[] = 'Repository name is required.'; } else { $e_name = null; } if (!strlen($repository->getCallsign())) { $e_callsign = 'Required'; $errors[] = 'Callsign is required.'; } else { if (!preg_match('/^[A-Z]+$/', $repository->getCallsign())) { $e_callsign = 'Invalid'; $errors[] = 'Callsign must be ALL UPPERCASE LETTERS.'; } else { $e_callsign = null; } } if (empty($type_map[$repository->getVersionControlSystem()])) { $errors[] = 'Invalid version control system.'; } if (!$errors) { try { $repository->save(); return id(new AphrontRedirectResponse())->setURI('/repository/edit/' . $repository->getID() . '/'); } catch (AphrontQueryDuplicateKeyException $ex) { $e_callsign = 'Duplicate'; $errors[] = 'Callsign must be unique. Another repository already ' . 'uses that callsign.'; } } } $error_view = null; if ($errors) { $error_view = new AphrontErrorView(); $error_view->setErrors($errors); $error_view->setTitle('Form Errors'); } $form = new AphrontFormView(); $form->setUser($user)->setAction('/repository/create/')->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($repository->getName())->setError($e_name)->setCaption('Human-readable repository name.'))->appendChild('<p class="aphront-form-instructions">Select a "Callsign" — a ' . 'short, uppercase string to identify revisions in this repository. If ' . 'you choose "EX", revisions in this repository will be identified ' . 'with the prefix "rEX".</p>')->appendChild(id(new AphrontFormTextControl())->setLabel('Callsign')->setName('callsign')->setValue($repository->getCallsign())->setError($e_callsign)->setCaption('Short, UPPERCASE identifier. Once set, it can not be changed.'))->appendChild(id(new AphrontFormSelectControl())->setLabel('Type')->setName('type')->setOptions($type_map)->setValue($repository->getVersionControlSystem()))->appendChild(id(new AphrontFormSubmitControl())->setValue('Create Repository')->addCancelButton('/repository/')); $panel = new AphrontPanelView(); $panel->setHeader('Create Repository'); $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Create Repository')); }
public function processRequest() { if ($this->id) { $item = id(new PhabricatorDirectoryItem())->load($this->id); if (!$item) { return new Aphront404Response(); } } else { $item = new PhabricatorDirectoryItem(); } $e_name = true; $e_href = true; $errors = array(); $request = $this->getRequest(); if ($request->isFormPost()) { $item->setName($request->getStr('name')); $item->setHref($request->getStr('href')); $item->setDescription($request->getStr('description')); $item->setCategoryID($request->getStr('categoryID')); $item->setSequence($request->getStr('sequence')); if (!strlen($item->getName())) { $errors[] = 'Item name is required.'; $e_name = 'Required'; } if (!strlen($item->getHref())) { $errors[] = 'Item link is required.'; $e_href = 'Required'; } if (!$errors) { $item->save(); return id(new AphrontRedirectResponse())->setURI('/directory/item/'); } } $error_view = null; if ($errors) { $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors); } $form = new AphrontFormView(); $form->setUser($request->getUser()); if ($item->getID()) { $form->setAction('/directory/item/edit/' . $item->getID() . '/'); } else { $form->setAction('/directory/item/edit/'); } $categories = id(new PhabricatorDirectoryCategory())->loadAll(); $category_map = mpull($categories, 'getName', 'getID'); $form->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($item->getName())->setError($e_name))->appendChild(id(new AphrontFormSelectControl())->setLabel('Category')->setName('categoryID')->setOptions($category_map)->setValue($item->getCategoryID()))->appendChild(id(new AphrontFormTextControl())->setLabel('Link')->setName('href')->setValue($item->getHref())->setError($e_href))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Description')->setName('description')->setValue($item->getDescription()))->appendChild(id(new AphrontFormTextControl())->setLabel('Order')->setName('sequence')->setCaption('Items in a category are sorted by "order", then by name.')->setValue((int) $item->getSequence()))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save')->addCancelButton('/directory/item/')); $panel = new AphrontPanelView(); if ($item->getID()) { $panel->setHeader('Edit Directory Item'); } else { $panel->setHeader('Create New Directory Item'); } $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Directory Item')); }
public function processRequest() { $request = $this->getRequest(); if (!PhabricatorEnv::getEnvConfig('auth.password-auth-enabled')) { return new Aphront400Response(); } $token = $this->token; $email = $request->getStr('email'); $target_user = id(new PhabricatorUser())->loadOneWhere('email = %s', $email); if (!$target_user || !$target_user->validateEmailToken($token)) { $view = new AphrontRequestFailureView(); $view->setHeader('Unable to Login'); $view->appendChild('<p>The authentication information in the link you clicked is ' . 'invalid or out of date. Make sure you are copy-and-pasting the ' . 'entire link into your browser. You can try again, or request ' . 'a new email.</p>'); $view->appendChild('<div class="aphront-failure-continue">' . '<a class="button" href="/login/email/">Send Another Email</a>' . '</div>'); return $this->buildStandardPageResponse($view, array('title' => 'Email Sent')); } if ($request->getUser()->getPHID() != $target_user->getPHID()) { $session_key = $target_user->establishSession('web'); $request->setCookie('phusr', $target_user->getUsername()); $request->setCookie('phsid', $session_key); } $errors = array(); $e_pass = true; $e_confirm = true; if ($request->isFormPost()) { $e_pass = '******'; $e_confirm = 'Error'; $pass = $request->getStr('password'); $confirm = $request->getStr('confirm'); if (strlen($pass) < 3) { $errors[] = 'That password is ridiculously short.'; } if ($pass !== $confirm) { $errors[] = "Passwords do not match."; } if (!$errors) { $target_user->setPassword($pass); $target_user->save(); return id(new AphrontRedirectResponse())->setURI('/'); } } if ($errors) { $error_view = new AphrontErrorView(); $error_view->setTitle('Password Reset Failed'); $error_view->setErrors($errors); } else { $error_view = null; } $form = new AphrontFormView(); $form->setUser($target_user)->setAction('/login/etoken/' . $token . '/')->addHiddenInput('email', $email)->appendChild(id(new AphrontFormPasswordControl())->setLabel('New Password')->setName('password')->setError($e_pass))->appendChild(id(new AphrontFormPasswordControl())->setLabel('Confirm Password')->setName('confirm')->setError($e_confirm))->appendChild(id(new AphrontFormSubmitControl())->setValue('Reset Password')->addCancelButton('/', 'Skip')); $panel = new AphrontPanelView(); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $panel->setHeader('Reset Password'); $panel->appendChild($form); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Create New Account')); }
public function renderExample() { $filter = new AphrontListFilterView(); $filter->addButton(phutil_render_tag('a', array('href' => '#', 'class' => 'button green'), 'Create New Thing')); $form = new AphrontFormView(); $form->setUser($this->getRequest()->getUser()); $form->appendChild(id(new AphrontFormTextControl())->setLabel('Query'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Search')); $filter->appendChild($form); return $filter; }
public function processRequest() { $request = $this->getRequest(); if ($request->isFormPost()) { $mail = new PhabricatorMetaMTAMail(); $mail->addTos($request->getArr('to')); $mail->addCCs($request->getArr('cc')); $mail->setSubject($request->getStr('subject')); $mail->setBody($request->getStr('body')); $files = $request->getArr('files'); if ($files) { foreach ($files as $phid) { $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $phid); $mail->addAttachment(new PhabricatorMetaMTAAttachment($file->loadFileData(), $file->getName(), $file->getMimeType())); } } $mail->setFrom($request->getUser()->getPHID()); $mail->setSimulatedFailureCount($request->getInt('failures')); $mail->setIsHTML($request->getInt('html')); $mail->setIsBulk($request->getInt('bulk')); $mail->setMailTags($request->getStrList('mailtags')); $mail->save(); if ($request->getInt('immediately')) { $mail->sendNow(); } return id(new AphrontRedirectResponse())->setURI($this->getApplicationURI('/view/' . $mail->getID() . '/')); } $failure_caption = "Enter a number to simulate that many consecutive send failures before " . "really attempting to deliver via the underlying MTA."; $doclink_href = PhabricatorEnv::getDoclink('article/Configuring_Outbound_Email.html'); $doclink = phutil_render_tag('a', array('href' => $doclink_href, 'target' => '_blank'), 'Configuring Outbound Email'); $instructions = '<p class="aphront-form-instructions">This form will send a normal ' . 'email using the settings you have configured for Phabricator. For more ' . 'information, see ' . $doclink . '.</p>'; $adapter = PhabricatorEnv::getEnvConfig('metamta.mail-adapter'); $warning = null; if ($adapter == 'PhabricatorMailImplementationTestAdapter') { $warning = new AphrontErrorView(); $warning->setTitle('Email is Disabled'); $warning->setSeverity(AphrontErrorView::SEVERITY_WARNING); $warning->appendChild('<p>This installation of Phabricator is currently set to use ' . '<tt>PhabricatorMailImplementationTestAdapter</tt> to deliver ' . 'outbound email. This completely disables outbound email! All ' . 'outbound email will be thrown in a deep, dark hole until you ' . 'configure a real adapter.</p>'); } $panel_id = celerity_generate_unique_node_id(); $phdlink_href = PhabricatorEnv::getDoclink('article/Managing_Daemons_with_phd.html'); $phdlink = phutil_render_tag('a', array('href' => $phdlink_href, 'target' => '_blank'), '"phd start"'); $form = new AphrontFormView(); $form->setUser($request->getUser()); $form->appendChild($instructions)->appendChild(id(new AphrontFormStaticControl())->setLabel('Adapter')->setValue($adapter))->appendChild(id(new AphrontFormTokenizerControl())->setLabel('To')->setName('to')->setDatasource('/typeahead/common/mailable/'))->appendChild(id(new AphrontFormTokenizerControl())->setLabel('CC')->setName('cc')->setDatasource('/typeahead/common/mailable/'))->appendChild(id(new AphrontFormTextControl())->setLabel('Subject')->setName('subject'))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Body')->setName('body'))->appendChild(id(new AphrontFormTextControl())->setLabel('Mail Tags')->setName('mailtags')->setCaption('Example: <tt>differential-cc, differential-comment</tt>'))->appendChild(id(new AphrontFormDragAndDropUploadControl())->setLabel('Attach Files')->setName('files')->setDragAndDropTarget($panel_id)->setActivatedClass('aphront-panel-view-drag-and-drop'))->appendChild(id(new AphrontFormTextControl())->setLabel('Simulate Failures')->setName('failures')->setCaption($failure_caption))->appendChild(id(new AphrontFormCheckboxControl())->setLabel('HTML')->addCheckbox('html', '1', 'Send as HTML email.'))->appendChild(id(new AphrontFormCheckboxControl())->setLabel('Bulk')->addCheckbox('bulk', '1', 'Send with bulk email headers.'))->appendChild(id(new AphrontFormCheckboxControl())->setLabel('Send Now')->addCheckbox('immediately', '1', 'Send immediately. (Do not enqueue for daemons.)', PhabricatorEnv::getEnvConfig('metamta.send-immediately'))->setCaption('Daemons can be started with ' . $phdlink . '.'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Send Mail')); $panel = new AphrontPanelView(); $panel->setHeader('Send Email'); $panel->appendChild($form); $panel->setID($panel_id); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $nav = $this->buildSideNavView(); $nav->selectFilter('send'); $nav->appendChild(array($warning, $panel)); return $this->buildApplicationPage($nav, array('title' => 'Send Test')); }
public function render() { require_celerity_resource('ponder-comment-table-css'); $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); $questionID = $this->questionID; $target = $this->target; $form = new AphrontFormView(); $form->setUser($this->user)->setAction($this->actionURI)->setWorkflow(true)->addHiddenInput('target', $target)->addHiddenInput('question_id', $questionID)->appendChild(id(new AphrontFormTextAreaControl())->setName('content'))->appendChild(id(new AphrontFormSubmitControl())->setValue($is_serious ? 'Submit' : 'Editorialize')); $view = id(new AphrontMoreView())->setSome(id(new AphrontNullView())->render())->setMore($form->render())->setExpandText('Add Comment'); return $view->render(); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $this->phid); if (!$file) { return new Aphront404Response(); } $author_child = null; if ($file->getAuthorPHID()) { $author = id(new PhabricatorUser())->loadOneWhere('phid = %s', $file->getAuthorPHID()); if ($author) { $author_child = id(new AphrontFormStaticControl())->setLabel('Author')->setName('author')->setValue($author->getUserName()); } } $form = new AphrontFormView(); $submit = new AphrontFormSubmitControl(); $form->setAction($file->getViewURI()); if ($file->isViewableInBrowser()) { $submit->setValue('View File'); } else { $submit->setValue('Download File'); } if ($user->getPHID() == $file->getAuthorPHID() || $user->getIsAdmin()) { $submit->addCancelButton('/file/delete/' . $file->getID() . '/', 'Delete File'); } $file_id = 'F' . $file->getID(); $form->setUser($user); $form->appendChild(id(new AphrontFormStaticControl())->setLabel('Name')->setName('name')->setValue($file->getName()))->appendChild(id(new AphrontFormStaticControl())->setLabel('ID')->setName('id')->setValue($file_id)->setCaption('Download this file with: <tt>arc download ' . phutil_escape_html($file_id) . '</tt>'))->appendChild(id(new AphrontFormStaticControl())->setLabel('PHID')->setName('phid')->setValue($file->getPHID()))->appendChild($author_child)->appendChild(id(new AphrontFormStaticControl())->setLabel('Created')->setName('created')->setValue(phabricator_datetime($file->getDateCreated(), $user)))->appendChild(id(new AphrontFormStaticControl())->setLabel('Mime Type')->setName('mime')->setValue($file->getMimeType()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Size')->setName('size')->setValue($file->getByteSize() . ' bytes'))->appendChild(id(new AphrontFormStaticControl())->setLabel('Engine')->setName('storageEngine')->setValue($file->getStorageEngine()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Format')->setName('storageFormat')->setValue($file->getStorageFormat()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Handle')->setName('storageHandle')->setValue($file->getStorageHandle()))->appendChild(id($submit)); $panel = new AphrontPanelView(); $panel->setHeader('File Info - ' . $file->getName()); $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $xform_panel = null; $transformations = id(new PhabricatorTransformedFile())->loadAllWhere('originalPHID = %s', $file->getPHID()); if ($transformations) { $transformed_phids = mpull($transformations, 'getTransformedPHID'); $transformed_files = id(new PhabricatorFile())->loadAllWhere('phid in (%Ls)', $transformed_phids); $transformed_map = mpull($transformed_files, null, 'getPHID'); $rows = array(); foreach ($transformations as $transformed) { $phid = $transformed->getTransformedPHID(); $rows[] = array(phutil_escape_html($transformed->getTransform()), phutil_render_tag('a', array('href' => $transformed_map[$phid]->getBestURI()), $phid)); } $table = new AphrontTableView($rows); $table->setHeaders(array('Transform', 'File')); $xform_panel = new AphrontPanelView(); $xform_panel->appendChild($table); $xform_panel->setWidth(AphrontPanelView::WIDTH_FORM); $xform_panel->setHeader('Transformations'); } return $this->buildStandardPageResponse(array($panel, $xform_panel), array('title' => 'File Info - ' . $file->getName())); }
public function processRequest() { $this->requireApplicationCapability(ManiphestBulkEditCapability::CAPABILITY); $request = $this->getRequest(); $user = $request->getUser(); $task_ids = $request->getArr('batch'); $tasks = id(new ManiphestTaskQuery())->setViewer($user)->withIDs($task_ids)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->execute(); $actions = $request->getStr('actions'); if ($actions) { $actions = json_decode($actions, true); } if ($request->isFormPost() && is_array($actions)) { foreach ($tasks as $task) { $field_list = PhabricatorCustomField::getObjectFields($task, PhabricatorCustomField::ROLE_EDIT); $field_list->readFieldsFromStorage($task); $xactions = $this->buildTransactions($actions, $task); if ($xactions) { // TODO: Set content source to "batch edit". $editor = id(new ManiphestTransactionEditor())->setActor($user)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setContinueOnMissingFields(true)->applyTransactions($task, $xactions); } } $task_ids = implode(',', mpull($tasks, 'getID')); return id(new AphrontRedirectResponse())->setURI('/maniphest/?ids=' . $task_ids); } $handles = ManiphestTaskListView::loadTaskHandles($user, $tasks); $list = new ManiphestTaskListView(); $list->setTasks($tasks); $list->setUser($user); $list->setHandles($handles); $template = new AphrontTokenizerTemplateView(); $template = $template->render(); $projects_source = new PhabricatorProjectDatasource(); $mailable_source = new PhabricatorMetaMTAMailableDatasource(); $owner_source = new PhabricatorTypeaheadOwnerDatasource(); require_celerity_resource('maniphest-batch-editor'); Javelin::initBehavior('maniphest-batch-editor', array('root' => 'maniphest-batch-edit-form', 'tokenizerTemplate' => $template, 'sources' => array('project' => array('src' => $projects_source->getDatasourceURI(), 'placeholder' => $projects_source->getPlaceholderText()), 'owner' => array('src' => $owner_source->getDatasourceURI(), 'placeholder' => $owner_source->getPlaceholderText(), 'limit' => 1), 'cc' => array('src' => $mailable_source->getDatasourceURI(), 'placeholder' => $mailable_source->getPlaceholderText())), 'input' => 'batch-form-actions', 'priorityMap' => ManiphestTaskPriority::getTaskPriorityMap(), 'statusMap' => ManiphestTaskStatus::getTaskStatusMap())); $form = new AphrontFormView(); $form->setUser($user); $form->setID('maniphest-batch-edit-form'); foreach ($tasks as $task) { $form->appendChild(phutil_tag('input', array('type' => 'hidden', 'name' => 'batch[]', 'value' => $task->getID()))); } $form->appendChild(phutil_tag('input', array('type' => 'hidden', 'name' => 'actions', 'id' => 'batch-form-actions'))); $form->appendChild(phutil_tag('p', array(), pht('These tasks will be edited:'))); $form->appendChild($list); $form->appendChild(id(new AphrontFormInsetView())->setTitle('Actions')->setRightButton(javelin_tag('a', array('href' => '#', 'class' => 'button green', 'sigil' => 'add-action', 'mustcapture' => true), pht('Add Another Action')))->setContent(javelin_tag('table', array('sigil' => 'maniphest-batch-actions', 'class' => 'maniphest-batch-actions-table'), '')))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Update Tasks'))->addCancelButton('/maniphest/')); $title = pht('Batch Editor'); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($title); $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Batch Edit Tasks'))->setForm($form); return $this->buildApplicationPage(array($crumbs, $form_box), array('title' => $title, 'device' => false)); }
public function processRequest() { $request = $this->getRequest(); $methods = $this->getAllMethods(); if (empty($methods[$this->method])) { return new Aphront404Response(); } $this->setFilter('method/' . $this->method); $method_class = $methods[$this->method]; $method_object = newv($method_class, array()); $status = $method_object->getMethodStatus(); $reason = $method_object->getMethodStatusDescription(); $status_view = null; if ($status != ConduitAPIMethod::METHOD_STATUS_STABLE) { $status_view = new AphrontErrorView(); switch ($status) { case ConduitAPIMethod::METHOD_STATUS_DEPRECATED: $status_view->setTitle('Deprecated Method'); $status_view->appendChild(phutil_escape_html(nonempty($reason, "This method is deprecated."))); break; case ConduitAPIMethod::METHOD_STATUS_UNSTABLE: $status_view->setSeverity(AphrontErrorView::SEVERITY_WARNING); $status_view->setTitle('Unstable Method'); $status_view->appendChild(phutil_escape_html(nonempty($reason, "This method is new and unstable. Its interface is subject " . "to change."))); break; } } $error_description = array(); $error_types = $method_object->defineErrorTypes(); if ($error_types) { $error_description[] = '<ul>'; foreach ($error_types as $error => $meaning) { $error_description[] = '<li>' . '<strong>' . phutil_escape_html($error) . ':</strong> ' . phutil_escape_html($meaning) . '</li>'; } $error_description[] = '</ul>'; $error_description = implode("\n", $error_description); } else { $error_description = "This method does not raise any specific errors."; } $form = new AphrontFormView(); $form->setUser($request->getUser())->setAction('/api/' . $this->method)->appendChild(id(new AphrontFormStaticControl())->setLabel('Description')->setValue($method_object->getMethodDescription()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Returns')->setValue($method_object->defineReturnType()))->appendChild(id(new AphrontFormMarkupControl())->setLabel('Errors')->setValue($error_description))->appendChild('<p class="aphront-form-instructions">Enter parameters using ' . '<strong>JSON</strong>. For instance, to enter a list, type: ' . '<tt>["apple", "banana", "cherry"]</tt>'); $params = $method_object->defineParamTypes(); foreach ($params as $param => $desc) { $form->appendChild(id(new AphrontFormTextControl())->setLabel($param)->setName("params[{$param}]")->setCaption(phutil_escape_html($desc))); } $form->appendChild(id(new AphrontFormSelectControl())->setLabel('Output Format')->setName('output')->setOptions(array('human' => 'Human Readable', 'json' => 'JSON')))->appendChild(id(new AphrontFormSubmitControl())->setValue('Call Method')); $panel = new AphrontPanelView(); $panel->setHeader('Conduit API: ' . phutil_escape_html($this->method)); $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FULL); return $this->buildStandardPageResponse(array($status_view, $panel), array('title' => 'Conduit Console - ' . $this->method)); }
public function render() { require_celerity_resource('ponder-core-view-css'); $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); $question = $this->question; $panel = id(new AphrontPanelView())->addClass("ponder-panel")->setHeader("Your Answer:"); $form = new AphrontFormView(); $form->setUser($this->user)->setAction($this->actionURI)->addHiddenInput('question_id', $question->getID())->appendChild(id(new AphrontFormTextAreaControl())->setName('answer')->setID('answer-content')->setEnableDragAndDropFileUploads(true)->setCaption(phutil_render_tag('a', array('href' => PhabricatorEnv::getDoclink('article/Remarkup_Reference.html'), 'tabindex' => '-1', 'target' => '_blank'), 'Formatting Reference')))->appendChild(id(new AphrontFormSubmitControl())->setValue($is_serious ? 'Submit' : 'Make it so.')); $panel->appendChild($form); $panel->appendChild('<div class="aphront-panel-flush">' . '<div id="answer-preview">' . '<span class="aphront-panel-preview-loading-text">' . 'Loading answer preview...' . '</span>' . '</div>' . '</div>'); Javelin::initBehavior('ponder-feedback-preview', array('uri' => '/ponder/answer/preview/', 'content' => 'answer-content', 'preview' => 'answer-preview', 'question_id' => $question->getID())); return $panel->render(); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $editable = $this->getAccountEditable(); $e_realname = $editable ? true : null; $errors = array(); if ($request->isFormPost()) { if ($editable) { $user->setRealName($request->getStr('realname')); if (!strlen($user->getRealName())) { $errors[] = 'Real name must be nonempty.'; $e_realname = 'Required'; } } $new_timezone = $request->getStr('timezone'); if (in_array($new_timezone, DateTimeZone::listIdentifiers(), true)) { $user->setTimezoneIdentifier($new_timezone); } else { $errors[] = 'The selected timezone is not a valid timezone.'; } if (!$errors) { $user->save(); return id(new AphrontRedirectResponse())->setURI('/settings/page/account/?saved=true'); } } $notice = null; if (!$errors) { if ($request->getStr('saved')) { $notice = new AphrontErrorView(); $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE); $notice->setTitle('Changes Saved'); $notice->appendChild('<p>Your changes have been saved.</p>'); $notice = $notice->render(); } } else { $notice = new AphrontErrorView(); $notice->setTitle('Form Errors'); $notice->setErrors($errors); $notice = $notice->render(); } $timezone_ids = DateTimeZone::listIdentifiers(); $timezone_id_map = array_combine($timezone_ids, $timezone_ids); $form = new AphrontFormView(); $form->setUser($user)->setEncType('multipart/form-data')->appendChild(id(new AphrontFormStaticControl())->setLabel('Username')->setValue($user->getUsername()))->appendChild(id(new AphrontFormTextControl())->setLabel('Real Name')->setName('realname')->setError($e_realname)->setValue($user->getRealName())->setDisabled(!$editable))->appendChild(id(new AphrontFormSelectControl())->setLabel('Timezone')->setName('timezone')->setOptions($timezone_id_map)->setValue($user->getTimezoneIdentifier()))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save')); $panel = new AphrontPanelView(); $panel->setHeader('Account Settings'); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $panel->appendChild($form); return id(new AphrontNullView())->appendChild(array($notice, $panel)); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $this->requireApplicationCapability(ProjectCreateProjectsCapability::CAPABILITY); $project = PhabricatorProject::initializeNewProject($user); $e_name = true; $type_name = PhabricatorProjectTransaction::TYPE_NAME; $v_name = $project->getName(); $validation_exception = null; if ($request->isFormPost()) { $xactions = array(); $v_name = $request->getStr('name'); $xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType($type_name)->setNewValue($v_name); $xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', PhabricatorEdgeConfig::TYPE_PROJ_MEMBER)->setNewValue(array('+' => array($user->getPHID() => $user->getPHID()))); $editor = id(new PhabricatorProjectTransactionEditor())->setActor($user)->setContinueOnNoEffect(true)->setContentSourceFromRequest($request); try { $editor->applyTransactions($project, $xactions); if ($request->isAjax()) { return id(new AphrontAjaxResponse())->setContent(array('phid' => $project->getPHID(), 'name' => $project->getName())); } else { return id(new AphrontRedirectResponse())->setURI('/project/view/' . $project->getID() . '/'); } } catch (PhabricatorApplicationTransactionValidationException $ex) { $validation_exception = $ex; $e_name = $ex->getShortMessage($type_name); } } if ($request->isAjax()) { $form = new PHUIFormLayoutView(); } else { $form = new AphrontFormView(); $form->setUser($user); } $form->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Name'))->setName('name')->setValue($v_name)->setError($e_name)); if ($request->isAjax()) { $errors = array(); if ($validation_exception) { $errors = mpull($ex->getErrors(), 'getMessage'); } $dialog = id(new AphrontDialogView())->setUser($user)->setWidth(AphrontDialogView::WIDTH_FORM)->setTitle(pht('Create a New Project'))->setErrors($errors)->appendChild($form)->addSubmitButton(pht('Create Project'))->addCancelButton('/project/'); return id(new AphrontDialogResponse())->setDialog($dialog); } else { $form->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Create'))->addCancelButton('/project/')); $crumbs = $this->buildApplicationCrumbs($this->buildSideNavView()); $crumbs->addTextCrumb(pht('Create Project'), $this->getApplicationURI() . 'create/'); $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Create New Project'))->setValidationException($validation_exception)->setForm($form); return $this->buildApplicationPage(array($crumbs, $form_box), array('title' => pht('Create New Project'))); } }
public function processRequest(AphrontRequest $request) { $user = $request->getUser(); $username = $user->getUsername(); $pref_time = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT; $preferences = $user->loadPreferences(); $errors = array(); if ($request->isFormPost()) { $new_timezone = $request->getStr('timezone'); if (in_array($new_timezone, DateTimeZone::listIdentifiers(), true)) { $user->setTimezoneIdentifier($new_timezone); } else { $errors[] = pht('The selected timezone is not a valid timezone.'); } $sex = $request->getStr('sex'); $sexes = array(PhutilPerson::SEX_MALE, PhutilPerson::SEX_FEMALE); if (in_array($sex, $sexes)) { $user->setSex($sex); } else { $user->setSex(null); } // Checked in runtime. $user->setTranslation($request->getStr('translation')); $preferences->setPreference($pref_time, $request->getStr($pref_time)); if (!$errors) { $preferences->save(); $user->save(); return id(new AphrontRedirectResponse())->setURI($this->getPanelURI('?saved=true')); } } $timezone_ids = DateTimeZone::listIdentifiers(); $timezone_id_map = array_fuse($timezone_ids); $label_unknown = pht('%s updated their profile', $username); $label_her = pht('%s updated her profile', $username); $label_his = pht('%s updated his profile', $username); $sexes = array(PhutilPerson::SEX_UNKNOWN => $label_unknown, PhutilPerson::SEX_MALE => $label_his, PhutilPerson::SEX_FEMALE => $label_her); $translations = array(); $symbols = id(new PhutilSymbolLoader())->setType('class')->setAncestorClass('PhabricatorTranslation')->setConcreteOnly(true)->selectAndLoadSymbols(); foreach ($symbols as $symbol) { $class = $symbol['name']; $translations[$class] = newv($class, array())->getName(); } asort($translations); $default = PhabricatorEnv::newObjectFromConfig('translation.provider'); $translations = array('' => pht('Server Default (%s)', $default->getName())) + $translations; $form = new AphrontFormView(); $form->setUser($user)->appendChild(id(new AphrontFormSelectControl())->setLabel(pht('Timezone'))->setName('timezone')->setOptions($timezone_id_map)->setValue($user->getTimezoneIdentifier()))->appendRemarkupInstructions(pht('**Choose the pronoun you prefer:**'))->appendChild(id(new AphrontFormSelectControl())->setOptions($sexes)->setLabel(pht('Pronoun'))->setName('sex')->setValue($user->getSex()))->appendChild(id(new AphrontFormSelectControl())->setOptions($translations)->setLabel(pht('Translation'))->setName('translation')->setValue($user->getTranslation()))->appendRemarkupInstructions(pht("**Custom Date and Time Formats**\n\n" . "You can specify custom formats which will be used when " . "rendering dates and times of day. Examples:\n\n" . "| Format | Example | Notes |\n" . "| ------ | -------- | ----- |\n" . "| `g:i A` | 2:34 PM | Default 12-hour time. |\n" . "| `G.i a` | 02.34 pm | Alternate 12-hour time. |\n" . "| `H:i` | 14:34 | 24-hour time. |\n" . "\n\n" . "You can find a [[%s | full reference in the PHP manual]].", 'http://www.php.net/manual/en/function.date.php'))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Time-of-Day Format'))->setName($pref_time)->setCaption(pht('Format used when rendering a time of day.'))->setValue($preferences->getPreference($pref_time)))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Save Account Settings'))); $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Account Settings'))->setFormSaved($request->getStr('saved'))->setFormErrors($errors)->setForm($form); return array($form_box); }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $project = id(new PhabricatorProjectQuery())->setViewer($viewer)->withIDs(array($id))->needMembers(true)->needImages(true)->executeOne(); if (!$project) { return new Aphront404Response(); } $this->setProject($project); $member_phids = $project->getMemberPHIDs(); if ($request->isFormPost()) { $member_spec = array(); $remove = $request->getStr('remove'); if ($remove) { $member_spec['-'] = array_fuse(array($remove)); } $add_members = $request->getArr('phids'); if ($add_members) { $member_spec['+'] = array_fuse($add_members); } $type_member = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST; $xactions = array(); $xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', $type_member)->setNewValue($member_spec); $editor = id(new PhabricatorProjectTransactionEditor($project))->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setContinueOnMissingFields(true)->applyTransactions($project, $xactions); return id(new AphrontRedirectResponse())->setURI($request->getRequestURI()); } $member_phids = array_reverse($member_phids); $handles = $this->loadViewerHandles($member_phids); $state = array(); foreach ($handles as $handle) { $state[] = array('phid' => $handle->getPHID(), 'name' => $handle->getFullName()); } $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $project, PhabricatorPolicyCapability::CAN_EDIT); $supports_edit = $project->supportsEditMembers(); $form_box = null; $title = pht('Add Members'); if ($can_edit && $supports_edit) { $header_name = pht('Edit Members'); $view_uri = $this->getApplicationURI('profile/' . $project->getID() . '/'); $form = new AphrontFormView(); $form->setUser($viewer)->appendControl(id(new AphrontFormTokenizerControl())->setName('phids')->setLabel(pht('Add Members'))->setDatasource(new PhabricatorPeopleDatasource()))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($view_uri)->setValue(pht('Add Members'))); $form_box = id(new PHUIObjectBoxView())->setHeaderText($title)->setForm($form); } $member_list = $this->renderMemberList($project, $handles); $nav = $this->getProfileMenu(); $nav->selectFilter(PhabricatorProject::PANEL_MEMBERS); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Members')); return $this->newPage()->setNavigation($nav)->setCrumbs($crumbs)->setTitle(array($project->getName(), $title))->appendChild($form_box)->appendChild($member_list); }
public function processRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); $method = id(new PhabricatorConduitMethodQuery())->setViewer($viewer)->withMethods(array($this->method))->executeOne(); if (!$method) { return new Aphront404Response(); } $can_call_method = false; $status = $method->getMethodStatus(); $reason = $method->getMethodStatusDescription(); $errors = array(); switch ($status) { case ConduitAPIMethod::METHOD_STATUS_DEPRECATED: $reason = nonempty($reason, pht('This method is deprecated.')); $errors[] = pht('Deprecated Method: %s', $reason); break; case ConduitAPIMethod::METHOD_STATUS_UNSTABLE: $reason = nonempty($reason, pht('This method is new and unstable. Its interface is subject ' . 'to change.')); $errors[] = pht('Unstable Method: %s', $reason); break; } $error_types = $method->defineErrorTypes(); if ($error_types) { $error_description = array(); foreach ($error_types as $error => $meaning) { $error_description[] = hsprintf('<li><strong>%s:</strong> %s</li>', $error, $meaning); } $error_description = phutil_tag('ul', array(), $error_description); } else { $error_description = pht('This method does not raise any specific errors.'); } $form = new AphrontFormView(); $form->setUser($request->getUser())->setAction('/api/' . $this->method)->addHiddenInput('allowEmptyParams', 1)->appendChild(id(new AphrontFormStaticControl())->setLabel('Description')->setValue($method->getMethodDescription()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Returns')->setValue($method->defineReturnType()))->appendChild(id(new AphrontFormMarkupControl())->setLabel('Errors')->setValue($error_description))->appendChild(hsprintf('<p class="aphront-form-instructions">Enter parameters using ' . '<strong>JSON</strong>. For instance, to enter a list, type: ' . '<tt>["apple", "banana", "cherry"]</tt>')); $params = $method->defineParamTypes(); foreach ($params as $param => $desc) { $form->appendChild(id(new AphrontFormTextControl())->setLabel($param)->setName("params[{$param}]")->setCaption($desc)); } $must_login = !$viewer->isLoggedIn() && $method->shouldRequireAuthentication(); if ($must_login) { $errors[] = pht('Login Required: This method requires authentication. You must ' . 'log in before you can make calls to it.'); } else { $form->appendChild(id(new AphrontFormSelectControl())->setLabel('Output Format')->setName('output')->setOptions(array('human' => 'Human Readable', 'json' => 'JSON')))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($this->getApplicationURI())->setValue(pht('Call Method'))); } $header = id(new PHUIHeaderView())->setUser($viewer)->setHeader($method->getAPIMethodName()); $form_box = id(new PHUIObjectBoxView())->setHeader($header)->setFormErrors($errors)->setForm($form); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($method->getAPIMethodName()); return $this->buildApplicationPage(array($crumbs, $form_box), array('title' => $method->getAPIMethodName())); }
public function processRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $user = $this->getUser(); $username = $user->getUsername(); $errors = array(); if ($request->isFormPost()) { $sex = $request->getStr('sex'); $sexes = array(PhutilPerson::SEX_MALE, PhutilPerson::SEX_FEMALE); if (in_array($sex, $sexes)) { $user->setSex($sex); } else { $user->setSex(null); } // Checked in runtime. $user->setTranslation($request->getStr('translation')); if (!$errors) { $user->save(); return id(new AphrontRedirectResponse())->setURI($this->getPanelURI('?saved=true')); } } $label_unknown = pht('%s updated their profile', $username); $label_her = pht('%s updated her profile', $username); $label_his = pht('%s updated his profile', $username); $sexes = array(PhutilPerson::SEX_UNKNOWN => $label_unknown, PhutilPerson::SEX_MALE => $label_his, PhutilPerson::SEX_FEMALE => $label_her); $locales = PhutilLocale::loadAllLocales(); $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); $is_dev = PhabricatorEnv::getEnvConfig('phabricator.developer-mode'); $translations = array(); foreach ($locales as $locale) { if ($is_serious && $locale->isSillyLocale()) { // Omit silly locales on serious business installs. continue; } if (!$is_dev && $locale->isTestLocale()) { // Omit test locales on installs which aren't in development mode. continue; } $translations[$locale->getLocaleCode()] = $locale->getLocaleName(); } asort($translations); // TODO: Implement "locale.default" and use it here. $default = 'en_US'; $translations = array('' => pht('Server Default: %s', $locales[$default]->getLocaleName())) + $translations; $form = new AphrontFormView(); $form->setUser($viewer)->appendChild(id(new AphrontFormSelectControl())->setOptions($translations)->setLabel(pht('Translation'))->setName('translation')->setValue($user->getTranslation()))->appendRemarkupInstructions(pht('**Choose the pronoun you prefer:**'))->appendChild(id(new AphrontFormSelectControl())->setOptions($sexes)->setLabel(pht('Pronoun'))->setName('sex')->setValue($user->getSex()))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Save Account Settings'))); $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Account Settings'))->setFormSaved($request->getStr('saved'))->setFormErrors($errors)->setForm($form); return array($form_box); }
public function processRequest() { if ($this->id) { $category = id(new PhabricatorDirectoryCategory())->load($this->id); if (!$category) { return new Aphront404Response(); } } else { $category = new PhabricatorDirectoryCategory(); } $e_name = true; $errors = array(); $request = $this->getRequest(); if ($request->isFormPost()) { $category->setName($request->getStr('name')); $category->setSequence($request->getStr('sequence')); if (!strlen($category->getName())) { $errors[] = 'Category name is required.'; $e_name = 'Required'; } if (!$errors) { $category->save(); return id(new AphrontRedirectResponse())->setURI('/directory/category/'); } } $error_view = null; if ($errors) { $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors); } $form = new AphrontFormView(); $form->setUser($request->getUser()); if ($category->getID()) { $form->setAction('/directory/category/edit/' . $category->getID() . '/'); } else { $form->setAction('/directory/category/edit/'); } $categories = id(new PhabricatorDirectoryCategory())->loadAll(); $category_map = mpull($categories, 'getName', 'getID'); $form->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($category->getName())->setError($e_name))->appendChild(id(new AphrontFormTextControl())->setLabel('Order')->setName('sequence')->setValue((int) $category->getSequence()))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save')->addCancelButton('/directory/category/')); $panel = new AphrontPanelView(); if ($category->getID()) { $panel->setHeader('Edit Directory Category'); } else { $panel->setHeader('Create New Directory Category'); } $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Directory Category')); }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $badge = id(new PhabricatorBadgesQuery())->setViewer($viewer)->withIDs(array($id))->needRecipients(true)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT, PhabricatorPolicyCapability::CAN_VIEW))->executeOne(); if (!$badge) { return new Aphront404Response(); } $recipient_phids = $badge->getRecipientPHIDs(); if ($request->isFormPost()) { $recipient_spec = array(); $remove = $request->getStr('remove'); if ($remove) { $recipient_spec['-'] = array_fuse(array($remove)); } $add_recipients = $request->getArr('phids'); if ($add_recipients) { $recipient_spec['+'] = array_fuse($add_recipients); } $type_recipient = PhabricatorBadgeHasRecipientEdgeType::EDGECONST; $xactions = array(); $xactions[] = id(new PhabricatorBadgesTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', $type_recipient)->setNewValue($recipient_spec); $editor = id(new PhabricatorBadgesEditor($badge))->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setContinueOnMissingFields(true)->applyTransactions($badge, $xactions); return id(new AphrontRedirectResponse())->setURI($request->getRequestURI()); } $recipient_phids = array_reverse($recipient_phids); $handles = $this->loadViewerHandles($recipient_phids); $state = array(); foreach ($handles as $handle) { $state[] = array('phid' => $handle->getPHID(), 'name' => $handle->getFullName()); } $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $badge, PhabricatorPolicyCapability::CAN_EDIT); $form_box = null; $title = pht('Add Recipient'); if ($can_edit) { $header_name = pht('Edit Recipients'); $view_uri = $this->getApplicationURI('view/' . $badge->getID() . '/'); $form = new AphrontFormView(); $form->setUser($viewer)->appendControl(id(new AphrontFormTokenizerControl())->setName('phids')->setLabel(pht('Add Recipients'))->setDatasource(new PhabricatorPeopleDatasource()))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($view_uri)->setValue(pht('Add Recipients'))); $form_box = id(new PHUIObjectBoxView())->setHeaderText($title)->setForm($form); } $recipient_list = id(new PhabricatorBadgesRecipientsListView())->setBadge($badge)->setHandles($handles)->setUser($viewer); $badge_url = $this->getApplicationURI('view/' . $id . '/'); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($badge->getName(), $badge_url); $crumbs->addTextCrumb(pht('Recipients')); return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild(array($form_box, $recipient_list)); }