private function returnSaveAddressResponse(AphrontRequest $request, PhutilURI $uri, PhabricatorMetaMTAApplicationEmail $email_object, $is_new) { $viewer = $request->getUser(); $config_default = PhabricatorMetaMTAApplicationEmail::CONFIG_DEFAULT_AUTHOR; $e_email = true; $v_email = $email_object->getAddress(); $e_space = null; $v_space = $email_object->getSpacePHID(); $v_default = $email_object->getConfigValue($config_default); $validation_exception = null; if ($request->isDialogFormPost()) { $e_email = null; $v_email = trim($request->getStr('email')); $v_space = $request->getStr('spacePHID'); $v_default = $request->getArr($config_default); $v_default = nonempty(head($v_default), null); $type_address = PhabricatorMetaMTAApplicationEmailTransaction::TYPE_ADDRESS; $type_space = PhabricatorTransactions::TYPE_SPACE; $type_config = PhabricatorMetaMTAApplicationEmailTransaction::TYPE_CONFIG; $key_config = PhabricatorMetaMTAApplicationEmailTransaction::KEY_CONFIG; $xactions = array(); $xactions[] = id(new PhabricatorMetaMTAApplicationEmailTransaction())->setTransactionType($type_address)->setNewValue($v_email); $xactions[] = id(new PhabricatorMetaMTAApplicationEmailTransaction())->setTransactionType($type_space)->setNewValue($v_space); $xactions[] = id(new PhabricatorMetaMTAApplicationEmailTransaction())->setTransactionType($type_config)->setMetadataValue($key_config, $config_default)->setNewValue($v_default); $editor = id(new PhabricatorMetaMTAApplicationEmailEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true); try { $editor->applyTransactions($email_object, $xactions); return id(new AphrontRedirectResponse())->setURI($uri->alter('highlight', $email_object->getID())); } catch (PhabricatorApplicationTransactionValidationException $ex) { $validation_exception = $ex; $e_email = $ex->getShortMessage($type_address); $e_space = $ex->getShortMessage($type_space); } } if ($v_default) { $v_default = array($v_default); } else { $v_default = array(); } $form = id(new AphrontFormView())->setUser($viewer)->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Email'))->setName('email')->setValue($v_email)->setError($e_email)); if (PhabricatorSpacesNamespaceQuery::getViewerSpacesExist($viewer)) { $form->appendControl(id(new AphrontFormSelectControl())->setLabel(pht('Space'))->setName('spacePHID')->setValue($v_space)->setError($e_space)->setOptions(PhabricatorSpacesNamespaceQuery::getSpaceOptionsForViewer($viewer, $v_space))); } $form->appendControl(id(new AphrontFormTokenizerControl())->setDatasource(new PhabricatorPeopleDatasource())->setLabel(pht('Default Author'))->setName($config_default)->setLimit(1)->setValue($v_default)->setCaption(pht('Used if the "From:" address does not map to a known account.'))); if ($is_new) { $title = pht('New Address'); } else { $title = pht('Edit Address'); } $dialog = id(new AphrontDialogView())->setUser($viewer)->setWidth(AphrontDialogView::WIDTH_FORM)->setTitle($title)->setValidationException($validation_exception)->appendForm($form)->addSubmitButton(pht('Save'))->addCancelButton($uri); if ($is_new) { $dialog->addHiddenInput('new', 'true'); } return id(new AphrontDialogResponse())->setDialog($dialog); }
public function testRegistrationEmailApplicationEmailCollide() { $app_email = '*****@*****.**'; $app_email_object = PhabricatorMetaMTAApplicationEmail::initializeNewAppEmail($this->generateNewTestUser()); $app_email_object->setAddress($app_email); $app_email_object->setApplicationPHID('test'); $app_email_object->save(); $caught = null; try { $this->registerUser('PhabricatorUserEditorTestCaseDomain', $app_email); } catch (Exception $ex) { $caught = $ex; } $this->assertTrue($caught instanceof Exception); }
<?php $key = 'metamta.maniphest.public-create-email'; echo pht("Migrating `%s` to new application email infrastructure...\n", $key); $value = PhabricatorEnv::getEnvConfigIfExists($key); $maniphest = new PhabricatorManiphestApplication(); if ($value) { try { PhabricatorMetaMTAApplicationEmail::initializeNewAppEmail(PhabricatorUser::getOmnipotentUser())->setAddress($value)->setApplicationPHID($maniphest->getPHID())->save(); } catch (AphrontDuplicateKeyQueryException $ex) { // Already migrated? } } echo pht('Done.') . "\n";