~ubuntu-branches/ubuntu/wily/phabricator/wily

« back to all changes in this revision

Viewing changes to phabricator/src/applications/mailinglists/controller/PhabricatorMailingListsEditController.php

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2015-06-13 10:52:10 UTC
  • mfrom: (0.30.1) (0.29.1) (0.17.4) (2.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20150613105210-5uirr7tvnk0n6e6y
Tags: 0~git20150613-1
* New snapshot release (closes: #787805)
* fixed typo in logrotate script (closes: #787645)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 
3
 
final class PhabricatorMailingListsEditController
4
 
  extends PhabricatorMailingListsController {
5
 
 
6
 
  public function handleRequest(AphrontRequest $request) {
7
 
    $request = $this->getRequest();
8
 
    $viewer = $request->getUser();
9
 
 
10
 
    $this->requireApplicationCapability(
11
 
      PhabricatorMailingListsManageCapability::CAPABILITY);
12
 
 
13
 
    $list_id = $request->getURIData('id');
14
 
    if ($list_id) {
15
 
      $page_title = pht('Edit Mailing List');
16
 
      $list = id(new PhabricatorMailingListQuery())
17
 
        ->setViewer($viewer)
18
 
        ->withIDs(array($list_id))
19
 
        ->executeOne();
20
 
      if (!$list) {
21
 
        return new Aphront404Response();
22
 
      }
23
 
    } else {
24
 
      $page_title = pht('Create Mailing List');
25
 
      $list = new PhabricatorMetaMTAMailingList();
26
 
    }
27
 
 
28
 
    $e_email = true;
29
 
    $e_uri = null;
30
 
    $e_name = true;
31
 
    $errors = array();
32
 
 
33
 
    $crumbs = $this->buildApplicationCrumbs();
34
 
 
35
 
    if ($request->isFormPost()) {
36
 
      $list->setName($request->getStr('name'));
37
 
      $list->setEmail($request->getStr('email'));
38
 
      $list->setURI($request->getStr('uri'));
39
 
 
40
 
      $e_email = null;
41
 
      $e_name = null;
42
 
 
43
 
      if (!strlen($list->getEmail())) {
44
 
        $e_email = pht('Required');
45
 
        $errors[] = pht('Email is required.');
46
 
      }
47
 
 
48
 
      if (!strlen($list->getName())) {
49
 
        $e_name = pht('Required');
50
 
        $errors[] = pht('Name is required.');
51
 
      } else if (preg_match('/[ ,]/', $list->getName())) {
52
 
        $e_name = pht('Invalid');
53
 
        $errors[] = pht('Name must not contain spaces or commas.');
54
 
      }
55
 
 
56
 
      if ($list->getURI()) {
57
 
        if (!PhabricatorEnv::isValidRemoteURIForLink($list->getURI())) {
58
 
          $e_uri = pht('Invalid');
59
 
          $errors[] = pht('Mailing list URI must point to a valid web page.');
60
 
        }
61
 
      }
62
 
 
63
 
      if (!$errors) {
64
 
        try {
65
 
          $list->save();
66
 
          return id(new AphrontRedirectResponse())
67
 
            ->setURI($this->getApplicationURI());
68
 
        } catch (AphrontDuplicateKeyQueryException $ex) {
69
 
          $e_email = pht('Duplicate');
70
 
          $errors[] = pht('Another mailing list already uses that address.');
71
 
        }
72
 
      }
73
 
    }
74
 
 
75
 
    $form = new AphrontFormView();
76
 
    $form->setUser($request->getUser());
77
 
    if ($list->getID()) {
78
 
      $form->setAction($this->getApplicationURI('/edit/'.$list->getID().'/'));
79
 
    } else {
80
 
      $form->setAction($this->getApplicationURI('/edit/'));
81
 
    }
82
 
 
83
 
    $form
84
 
      ->appendChild(
85
 
        id(new AphrontFormTextControl())
86
 
          ->setLabel(pht('Email'))
87
 
          ->setName('email')
88
 
          ->setValue($list->getEmail())
89
 
          ->setCaption(pht('Email will be delivered to this address.'))
90
 
          ->setError($e_email))
91
 
      ->appendChild(
92
 
        id(new AphrontFormTextControl())
93
 
          ->setLabel(pht('Name'))
94
 
          ->setName('name')
95
 
          ->setError($e_name)
96
 
          ->setCaption(pht('Human-readable display and autocomplete name.'))
97
 
          ->setValue($list->getName()))
98
 
      ->appendChild(
99
 
        id(new AphrontFormTextControl())
100
 
          ->setLabel(pht('URI'))
101
 
          ->setName('uri')
102
 
          ->setError($e_uri)
103
 
          ->setCaption(pht('Optional link to mailing list archives or info.'))
104
 
          ->setValue($list->getURI()))
105
 
      ->appendChild(
106
 
        id(new AphrontFormSubmitControl())
107
 
          ->setValue(pht('Save'))
108
 
          ->addCancelButton($this->getApplicationURI()));
109
 
 
110
 
    if ($list->getID()) {
111
 
      $crumbs->addTextCrumb(pht('Edit Mailing List'));
112
 
    } else {
113
 
      $crumbs->addTextCrumb(pht('Create Mailing List'));
114
 
    }
115
 
 
116
 
    $form_box = id(new PHUIObjectBoxView())
117
 
      ->setHeaderText($page_title)
118
 
      ->setFormErrors($errors)
119
 
      ->setForm($form);
120
 
 
121
 
    return $this->buildApplicationPage(
122
 
      array(
123
 
        $crumbs,
124
 
        $form_box,
125
 
      ),
126
 
      array(
127
 
        'title' => $page_title,
128
 
      ));
129
 
  }
130
 
 
131
 
}