diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index c661570dca..f30a40224d 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -118,6 +118,9 @@ phutil_register_library_map(array( 'PhabricatorMetaMTADAO' => 'applications/metamta/storage/base', 'PhabricatorMetaMTAListController' => 'applications/metamta/controller/list', 'PhabricatorMetaMTAMail' => 'applications/metamta/storage/mail', + 'PhabricatorMetaMTAMailingList' => 'applications/metamta/storage/mailinglist', + 'PhabricatorMetaMTAMailingListEditController' => 'applications/metamta/controller/mailinglistedit', + 'PhabricatorMetaMTAMailingListsController' => 'applications/metamta/controller/mailinglists', 'PhabricatorMetaMTASendController' => 'applications/metamta/controller/send', 'PhabricatorMetaMTAViewController' => 'applications/metamta/controller/view', 'PhabricatorObjectHandle' => 'applications/phid/handle', @@ -244,6 +247,9 @@ phutil_register_library_map(array( 'PhabricatorMetaMTADAO' => 'PhabricatorLiskDAO', 'PhabricatorMetaMTAListController' => 'PhabricatorMetaMTAController', 'PhabricatorMetaMTAMail' => 'PhabricatorMetaMTADAO', + 'PhabricatorMetaMTAMailingList' => 'PhabricatorMetaMTADAO', + 'PhabricatorMetaMTAMailingListEditController' => 'PhabricatorMetaMTAController', + 'PhabricatorMetaMTAMailingListsController' => 'PhabricatorMetaMTAController', 'PhabricatorMetaMTASendController' => 'PhabricatorMetaMTAController', 'PhabricatorMetaMTAViewController' => 'PhabricatorMetaMTAController', 'PhabricatorPHID' => 'PhabricatorPHIDDAO', diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php index c61eec3dc2..977aa14cea 100644 --- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php @@ -99,7 +99,10 @@ class AphrontDefaultApplicationConfiguration '$' => 'PhabricatorMetaMTAListController', 'send/$' => 'PhabricatorMetaMTASendController', 'view/(?\d+)/$' => 'PhabricatorMetaMTAViewController', - ) + 'lists/$' => 'PhabricatorMetaMTAMailingListsController', + 'lists/edit/(?:(?\d+)/)?$' + => 'PhabricatorMetaMTAMailingListEditController', + ), ); } diff --git a/src/applications/metamta/controller/base/PhabricatorMetaMTAController.php b/src/applications/metamta/controller/base/PhabricatorMetaMTAController.php index aee09ab14d..2f68d22a9c 100644 --- a/src/applications/metamta/controller/base/PhabricatorMetaMTAController.php +++ b/src/applications/metamta/controller/base/PhabricatorMetaMTAController.php @@ -24,6 +24,18 @@ abstract class PhabricatorMetaMTAController extends PhabricatorController { $page->setApplicationName('MetaMTA'); $page->setBaseURI('/mail/'); $page->setTitle(idx($data, 'title')); + $page->setTabs( + array( + 'queue' => array( + 'name' => 'Mail Queue', + 'href' => '/mail/', + ), + 'lists' => array( + 'name' => 'Mailing Lists', + 'href' => '/mail/lists/', + ), + ), + idx($data, 'tab')); $page->setGlyph("@"); $page->appendChild($view); diff --git a/src/applications/metamta/controller/list/PhabricatorMetaMTAListController.php b/src/applications/metamta/controller/list/PhabricatorMetaMTAListController.php index 1d3021e268..fd0b6bd60c 100644 --- a/src/applications/metamta/controller/list/PhabricatorMetaMTAListController.php +++ b/src/applications/metamta/controller/list/PhabricatorMetaMTAListController.php @@ -72,6 +72,7 @@ class PhabricatorMetaMTAListController extends PhabricatorMetaMTAController { $panel, array( 'title' => 'MetaMTA', + 'tab' => 'queue', )); } } diff --git a/src/applications/metamta/controller/list/__init__.php b/src/applications/metamta/controller/list/__init__.php index 520ca62a9d..79f3117912 100644 --- a/src/applications/metamta/controller/list/__init__.php +++ b/src/applications/metamta/controller/list/__init__.php @@ -11,6 +11,7 @@ phutil_require_module('phabricator', 'applications/metamta/storage/mail'); phutil_require_module('phabricator', 'view/control/table'); phutil_require_module('phabricator', 'view/layout/panel'); +phutil_require_module('phutil', 'markup'); phutil_require_module('phutil', 'utils'); diff --git a/src/applications/metamta/controller/mailinglistedit/PhabricatorMetaMTAMailingListEditController.php b/src/applications/metamta/controller/mailinglistedit/PhabricatorMetaMTAMailingListEditController.php new file mode 100644 index 0000000000..cffa047b8b --- /dev/null +++ b/src/applications/metamta/controller/mailinglistedit/PhabricatorMetaMTAMailingListEditController.php @@ -0,0 +1,121 @@ +id = idx($data, 'id'); + } + + public function processRequest() { + + if ($this->id) { + $list = id(new PhabricatorMetaMTAMailingList())->load($this->id); + if (!$list) { + return new Aphront404Response(); + } + } else { + $list = new PhabricatorMetaMTAMailingList(); + } + + $e_email = true; + $errors = array(); + + $request = $this->getRequest(); + if ($request->isFormPost()) { + $list->setName($request->getStr('name')); + $list->setEmail($request->getStr('email')); + $list->setURI($request->getStr('uri')); + + if (!strlen($list->getEmail())) { + $e_email = 'Required'; + $errors[] = 'Email is required.'; + } + + if (!$errors) { + $list->save(); + return id(new AphrontRedirectResponse()) + ->setURI('/mail/lists/'); + } + } + + $error_view = null; + if ($errors) { + $error_view = id(new AphrontErrorView()) + ->setTitle('Form Errors') + ->setErrors($errors); + } + + $form = new AphrontFormView(); + if ($list->getID()) { + $form->setAction('/mail/lists/edit/'.$list->getID().'/'); + } else { + $form->setAction('/mail/lists/edit/'); + } + + $form + ->appendChild( + id(new AphrontFormTextControl()) + ->setLabel('Email') + ->setName('email') + ->setValue($list->getEmail()) + ->setError($e_email)) + ->appendChild( + id(new AphrontFormTextControl()) + ->setLabel('Name') + ->setName('name') + ->setValue($list->getName())) + ->appendChild( + id(new AphrontFormTextControl()) + ->setLabel('URI') + ->setName('uri') + ->setValue($list->getURI())) + ->appendChild( + id(new AphrontFormStaticControl()) + ->setLabel('ID') + ->setValue(nonempty($list->getID(), '-'))) + ->appendChild( + id(new AphrontFormStaticControl()) + ->setLabel('PHID') + ->setValue(nonempty($list->getPHID(), '-'))) + ->appendChild( + id(new AphrontFormSubmitControl()) + ->setValue('Save') + ->addCancelButton('/mail/lists/')); + + $panel = new AphrontPanelView(); + if ($list->getID()) { + $panel->setHeader('Edit Mailing List'); + } else { + $panel->setHeader('Create New Mailing List'); + } + + $panel->appendChild($form); + $panel->setWidth(AphrontPanelView::WIDTH_FORM); + + return $this->buildStandardPageResponse( + array($error_view, $panel), + array( + 'title' => 'Edit Mailing List', + )); + } + +} diff --git a/src/applications/metamta/controller/mailinglistedit/__init__.php b/src/applications/metamta/controller/mailinglistedit/__init__.php new file mode 100644 index 0000000000..1469d2bd61 --- /dev/null +++ b/src/applications/metamta/controller/mailinglistedit/__init__.php @@ -0,0 +1,21 @@ +loadAllWhere( + '1 = 1 ORDER BY id DESC LIMIT 100'); + + $rows = array(); + foreach ($lists as $list) { + $rows[] = array( + phutil_escape_html($list->getPHID()), + phutil_escape_html($list->getEmail()), + phutil_escape_html($list->getName()), + phutil_render_tag( + 'a', + array( + 'class' => 'button grey small', + 'href' => '/mail/lists/edit/'.$list->getID().'/', + ), + 'Edit'), + ); + } + + $table = new AphrontTableView($rows); + $table->setHeaders( + array( + 'PHID', + 'Email', + 'Name', + '', + )); + $table->setColumnClasses( + array( + null, + null, + 'wide', + 'action', + )); + + $panel = new AphrontPanelView(); + $panel->appendChild($table); + $panel->setHeader('Mailing Lists'); + $panel->setCreateButton('Add New List', '/mail/lists/edit/'); + + return $this->buildStandardPageResponse( + $panel, + array( + 'title' => 'Mailing Lists', + 'tab' => 'lists', + )); + } +} diff --git a/src/applications/metamta/controller/mailinglists/__init__.php b/src/applications/metamta/controller/mailinglists/__init__.php new file mode 100644 index 0000000000..119d4a1842 --- /dev/null +++ b/src/applications/metamta/controller/mailinglists/__init__.php @@ -0,0 +1,18 @@ +setLabel('To') ->setName('to') - ->setDatasource('/typeahead/common/user/')) + ->setDatasource('/typeahead/common/mailable/')) ->appendChild( id(new AphrontFormTokenizerControl()) ->setLabel('CC') ->setName('cc') - ->setDatasource('/typeahead/common/user/')) + ->setDatasource('/typeahead/common/mailable/')) ->appendChild( id(new AphrontFormTextControl()) ->setLabel('Subject') diff --git a/src/applications/metamta/controller/send/__init__.php b/src/applications/metamta/controller/send/__init__.php index d606f64d0f..24025389ef 100644 --- a/src/applications/metamta/controller/send/__init__.php +++ b/src/applications/metamta/controller/send/__init__.php @@ -7,6 +7,7 @@ phutil_require_module('phabricator', 'aphront/response/redirect'); +phutil_require_module('phabricator', 'applications/metamta/adapter/phpmailerlite'); phutil_require_module('phabricator', 'applications/metamta/controller/base'); phutil_require_module('phabricator', 'applications/metamta/storage/mail'); phutil_require_module('phabricator', 'view/form/base'); diff --git a/src/applications/metamta/storage/mailinglist/PhabricatorMetaMTAMailingList.php b/src/applications/metamta/storage/mailinglist/PhabricatorMetaMTAMailingList.php new file mode 100644 index 0000000000..c8df2e35ab --- /dev/null +++ b/src/applications/metamta/storage/mailinglist/PhabricatorMetaMTAMailingList.php @@ -0,0 +1,38 @@ + true, + ) + parent::getConfiguration(); + } + +} diff --git a/src/applications/metamta/storage/mailinglist/__init__.php b/src/applications/metamta/storage/mailinglist/__init__.php new file mode 100644 index 0000000000..6ca6793cb3 --- /dev/null +++ b/src/applications/metamta/storage/mailinglist/__init__.php @@ -0,0 +1,13 @@ +loadAllWhere('phid IN (%Ls)', $phids); + $lists = mpull($lists, null, 'getPHID'); + + foreach ($phids as $phid) { + $handle = new PhabricatorObjectHandle(); + $handle->setPHID($phid); + if (empty($lists[$phid])) { + $handle->setType(self::TYPE_UNKNOWN); + $handle->setName('Unknown Mailing List'); + } else { + $list = $lists[$phid]; + $handle->setType($type); + $handle->setEmail($list->getEmail()); + $handle->setName($list->getName()); + $handle->setURI($list->getURI()); + } + $handles[$phid] = $handle; + } + break; case 'FILE': $class = 'PhabricatorFile'; PhutilSymbolLoader::loadClass($class); diff --git a/src/applications/typeahead/controller/common/PhabricatorTypeaheadCommonDatasourceController.php b/src/applications/typeahead/controller/common/PhabricatorTypeaheadCommonDatasourceController.php index 1758a1a948..acef3d6fdb 100644 --- a/src/applications/typeahead/controller/common/PhabricatorTypeaheadCommonDatasourceController.php +++ b/src/applications/typeahead/controller/common/PhabricatorTypeaheadCommonDatasourceController.php @@ -25,17 +25,41 @@ class PhabricatorTypeaheadCommonDatasourceController public function processRequest() { - $data = array(); - - $users = id(new PhabricatorUser())->loadAll(); + $need_users = false; + $need_lists = false; + switch ($this->type) { + case 'users': + $need_users = true; + break; + case 'mailable': + $need_users = true; + $need_lists = true; + break; + } $data = array(); - foreach ($users as $user) { - $data[] = array( - $user->getUsername().' ('.$user->getRealName().')', - '/p/'.$user->getUsername(), - $user->getPHID(), - ); + + + if ($need_users) { + $users = id(new PhabricatorUser())->loadAll(); + foreach ($users as $user) { + $data[] = array( + $user->getUsername().' ('.$user->getRealName().')', + '/p/'.$user->getUsername(), + $user->getPHID(), + ); + } + } + + if ($need_lists) { + $lists = id(new PhabricatorMetaMTAMailingList())->loadAll(); + foreach ($lists as $list) { + $data[] = array( + $list->getEmail(), + $list->getURI(), + $list->getPHID(), + ); + } } return id(new AphrontAjaxResponse()) diff --git a/src/applications/typeahead/controller/common/__init__.php b/src/applications/typeahead/controller/common/__init__.php index 34f6ae27c4..5a38ece7c8 100644 --- a/src/applications/typeahead/controller/common/__init__.php +++ b/src/applications/typeahead/controller/common/__init__.php @@ -7,6 +7,7 @@ phutil_require_module('phabricator', 'aphront/response/ajax'); +phutil_require_module('phabricator', 'applications/metamta/storage/mailinglist'); phutil_require_module('phabricator', 'applications/people/storage/user'); phutil_require_module('phabricator', 'applications/typeahead/controller/base');