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

« back to all changes in this revision

Viewing changes to phabricator/src/applications/spaces/controller/PhabricatorSpacesViewController.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 PhabricatorSpacesViewController
 
4
  extends PhabricatorSpacesController {
 
5
 
 
6
  public function shouldAllowPublic() {
 
7
    return true;
 
8
  }
 
9
 
 
10
  public function handleRequest(AphrontRequest $request) {
 
11
    $viewer = $this->getViewer();
 
12
 
 
13
    $space = id(new PhabricatorSpacesNamespaceQuery())
 
14
      ->setViewer($viewer)
 
15
      ->withIDs(array($request->getURIData('id')))
 
16
      ->executeOne();
 
17
    if (!$space) {
 
18
      return new Aphront404Response();
 
19
    }
 
20
 
 
21
    $action_list = $this->buildActionListView($space);
 
22
    $property_list = $this->buildPropertyListView($space);
 
23
    $property_list->setActionList($action_list);
 
24
 
 
25
    $xactions = id(new PhabricatorSpacesNamespaceTransactionQuery())
 
26
      ->setViewer($viewer)
 
27
      ->withObjectPHIDs(array($space->getPHID()))
 
28
      ->execute();
 
29
 
 
30
    $timeline = $this->buildTransactionTimeline(
 
31
      $space,
 
32
      new PhabricatorSpacesNamespaceTransactionQuery());
 
33
    $timeline->setShouldTerminate(true);
 
34
 
 
35
    $header = id(new PHUIHeaderView())
 
36
      ->setUser($viewer)
 
37
      ->setHeader($space->getNamespaceName())
 
38
      ->setPolicyObject($space);
 
39
 
 
40
    if ($space->getIsArchived()) {
 
41
      $header->setStatus('fa-ban', 'red', pht('Archived'));
 
42
    } else {
 
43
      $header->setStatus('fa-check', 'bluegrey', pht('Active'));
 
44
    }
 
45
 
 
46
    $box = id(new PHUIObjectBoxView())
 
47
      ->setHeader($header)
 
48
      ->addPropertyList($property_list);
 
49
 
 
50
    $crumbs = $this->buildApplicationCrumbs();
 
51
    $crumbs->addTextCrumb($space->getMonogram());
 
52
 
 
53
    return $this->buildApplicationPage(
 
54
      array(
 
55
        $crumbs,
 
56
        $box,
 
57
        $timeline,
 
58
      ),
 
59
      array(
 
60
        'title' => array($space->getMonogram(), $space->getNamespaceName()),
 
61
      ));
 
62
  }
 
63
 
 
64
  private function buildPropertyListView(PhabricatorSpacesNamespace $space) {
 
65
    $viewer = $this->getRequest()->getUser();
 
66
 
 
67
    $list = id(new PHUIPropertyListView())
 
68
      ->setUser($viewer);
 
69
 
 
70
    $list->addProperty(
 
71
      pht('Default Space'),
 
72
      $space->getIsDefaultNamespace()
 
73
        ? pht('Yes')
 
74
        : pht('No'));
 
75
 
 
76
    $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions(
 
77
      $viewer,
 
78
      $space);
 
79
 
 
80
    $list->addProperty(
 
81
      pht('Editable By'),
 
82
      $descriptions[PhabricatorPolicyCapability::CAN_EDIT]);
 
83
 
 
84
    $description = $space->getDescription();
 
85
    if (strlen($description)) {
 
86
      $description = PhabricatorMarkupEngine::renderOneObject(
 
87
        id(new PhabricatorMarkupOneOff())->setContent($description),
 
88
        'default',
 
89
        $viewer);
 
90
 
 
91
      $list->addSectionHeader(
 
92
        pht('Description'),
 
93
        PHUIPropertyListView::ICON_SUMMARY);
 
94
 
 
95
      $list->addTextContent($description);
 
96
    }
 
97
 
 
98
    return $list;
 
99
  }
 
100
 
 
101
  private function buildActionListView(PhabricatorSpacesNamespace $space) {
 
102
    $viewer = $this->getRequest()->getUser();
 
103
 
 
104
    $list = id(new PhabricatorActionListView())
 
105
      ->setUser($viewer)
 
106
      ->setObjectURI('/'.$space->getMonogram());
 
107
 
 
108
    $can_edit = PhabricatorPolicyFilter::hasCapability(
 
109
      $viewer,
 
110
      $space,
 
111
      PhabricatorPolicyCapability::CAN_EDIT);
 
112
 
 
113
    $list->addAction(
 
114
      id(new PhabricatorActionView())
 
115
        ->setName(pht('Edit Space'))
 
116
        ->setIcon('fa-pencil')
 
117
        ->setHref($this->getApplicationURI('edit/'.$space->getID().'/'))
 
118
        ->setWorkflow(!$can_edit)
 
119
        ->setDisabled(!$can_edit));
 
120
 
 
121
    $id = $space->getID();
 
122
 
 
123
    if ($space->getIsArchived()) {
 
124
      $list->addAction(
 
125
        id(new PhabricatorActionView())
 
126
          ->setName(pht('Activate Space'))
 
127
          ->setIcon('fa-check')
 
128
          ->setHref($this->getApplicationURI("activate/{$id}/"))
 
129
          ->setDisabled(!$can_edit)
 
130
          ->setWorkflow(true));
 
131
    } else {
 
132
      $list->addAction(
 
133
        id(new PhabricatorActionView())
 
134
          ->setName(pht('Archive Space'))
 
135
          ->setIcon('fa-ban')
 
136
          ->setHref($this->getApplicationURI("archive/{$id}/"))
 
137
          ->setDisabled(!$can_edit)
 
138
          ->setWorkflow(true));
 
139
    }
 
140
 
 
141
    return $list;
 
142
  }
 
143
 
 
144
}