Move "Mailing Lists" to a separate application
Summary: There's currently no way to get here from the UI since nav tabs don't exist anymore. It's also always been hard to find this feature even when we had the tabs, since it's surprising that it's inside "MetaMTA". - Move mailing lists to a separate application. - Add `buildApplicationPage()`, since we don't really need `buildStandardPageResponse()` any more -- we can infer all the information from `PhabricatorApplication`. This will let us get rid of a lot of the `PhabricatorXXXController` classes which just define application information. - Add `getApplicationURI()` to reduce code duplication, and in case we want to let you move applications around some day. Test Plan: Looked/edited/saved mailing lists. Reviewers: btrahan, vrana Reviewed By: btrahan CC: aran Maniphest Tasks: T631 Differential Revision: https://secure.phabricator.com/D3248
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
final class PhabricatorMailingListsEditController
|
||||
extends PhabricatorController {
|
||||
|
||||
private $id;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->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;
|
||||
$e_uri = null;
|
||||
$e_name = true;
|
||||
$errors = array();
|
||||
|
||||
$request = $this->getRequest();
|
||||
if ($request->isFormPost()) {
|
||||
$list->setName($request->getStr('name'));
|
||||
$list->setEmail($request->getStr('email'));
|
||||
$list->setURI($request->getStr('uri'));
|
||||
|
||||
$e_email = null;
|
||||
$e_name = null;
|
||||
|
||||
if (!strlen($list->getEmail())) {
|
||||
$e_email = 'Required';
|
||||
$errors[] = 'Email is required.';
|
||||
}
|
||||
|
||||
if (!strlen($list->getName())) {
|
||||
$e_name = 'Required';
|
||||
$errors[] = 'Name is required.';
|
||||
} else if (preg_match('/[ ,]/', $list->getName())) {
|
||||
$e_name = 'Invalid';
|
||||
$errors[] = 'Name must not contain spaces or commas.';
|
||||
}
|
||||
|
||||
if ($list->getURI()) {
|
||||
if (!PhabricatorEnv::isValidWebResource($list->getURI())) {
|
||||
$e_uri = 'Invalid';
|
||||
$errors[] = 'Mailing list URI must point to a valid web page.';
|
||||
}
|
||||
}
|
||||
|
||||
if (!$errors) {
|
||||
try {
|
||||
$list->save();
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI($this->getApplicationURI());
|
||||
} catch (AphrontQueryDuplicateKeyException $ex) {
|
||||
$e_email = 'Duplicate';
|
||||
$errors[] = 'Another mailing list already uses that address.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$error_view = null;
|
||||
if ($errors) {
|
||||
$error_view = id(new AphrontErrorView())
|
||||
->setTitle('Form Errors')
|
||||
->setErrors($errors);
|
||||
}
|
||||
|
||||
$form = new AphrontFormView();
|
||||
$form->setUser($request->getUser());
|
||||
if ($list->getID()) {
|
||||
$form->setAction($this->getApplicationURI('/edit/'.$list->getID().'/'));
|
||||
} else {
|
||||
$form->setAction($this->getApplicationURI('/edit/'));
|
||||
}
|
||||
|
||||
$form
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel('Email')
|
||||
->setName('email')
|
||||
->setValue($list->getEmail())
|
||||
->setCaption('Email will be delivered to this address.')
|
||||
->setError($e_email))
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel('Name')
|
||||
->setName('name')
|
||||
->setError($e_name)
|
||||
->setCaption('Human-readable display and autocomplete name.')
|
||||
->setValue($list->getName()))
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel('URI')
|
||||
->setName('uri')
|
||||
->setError($e_uri)
|
||||
->setCaption('Optional link to mailing list archives or info.')
|
||||
->setValue($list->getURI()))
|
||||
->appendChild(
|
||||
id(new AphrontFormStaticControl())
|
||||
->setLabel('PHID')
|
||||
->setValue(nonempty($list->getPHID(), '-')))
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue('Save')
|
||||
->addCancelButton($this->getApplicationURI()));
|
||||
|
||||
$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->buildApplicationPage(
|
||||
array(
|
||||
$error_view,
|
||||
$panel,
|
||||
),
|
||||
array(
|
||||
'title' => 'Edit Mailing List',
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user