Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / diffusion / controller / DiffusionIdentityViewController.php
blob1c78ec59923c531f892789a5ec7ddcdcf94cc3b5
1 <?php
3 final class DiffusionIdentityViewController
4 extends DiffusionController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $request->getViewer();
9 $id = $request->getURIData('id');
10 $identity = id(new PhabricatorRepositoryIdentityQuery())
11 ->setViewer($viewer)
12 ->withIDs(array($id))
13 ->executeOne();
14 if (!$identity) {
15 return new Aphront404Response();
18 $title = pht('Identity %d', $identity->getID());
20 $curtain = $this->buildCurtain($identity);
22 $header = id(new PHUIHeaderView())
23 ->setUser($viewer)
24 ->setHeader($identity->getIdentityShortName())
25 ->setHeaderIcon('fa-globe');
27 $crumbs = $this->buildApplicationCrumbs();
28 $crumbs->addTextCrumb(
29 pht('Identities'),
30 $this->getApplicationURI('identity/'));
31 $crumbs->addTextCrumb($identity->getObjectName());
32 $crumbs->setBorder(true);
34 $timeline = $this->buildTransactionTimeline(
35 $identity,
36 new PhabricatorRepositoryIdentityTransactionQuery());
37 $timeline->setShouldTerminate(true);
39 $properties = $this->buildPropertyList($identity);
41 $view = id(new PHUITwoColumnView())
42 ->setHeader($header)
43 ->setCurtain($curtain)
44 ->setMainColumn(array(
45 $properties,
46 $timeline,
47 ));
49 return $this->newPage()
50 ->setTitle($title)
51 ->setCrumbs($crumbs)
52 ->appendChild(
53 array(
54 $view,
55 ));
58 private function buildCurtain(PhabricatorRepositoryIdentity $identity) {
59 $viewer = $this->getViewer();
61 $can_edit = PhabricatorPolicyFilter::hasCapability(
62 $viewer,
63 $identity,
64 PhabricatorPolicyCapability::CAN_EDIT);
66 $id = $identity->getID();
67 $edit_uri = $this->getApplicationURI("identity/edit/{$id}/");
69 $curtain = $this->newCurtainView($identity);
71 $curtain->addAction(
72 id(new PhabricatorActionView())
73 ->setIcon('fa-pencil')
74 ->setName(pht('Edit Identity'))
75 ->setHref($edit_uri)
76 ->setWorkflow(!$can_edit)
77 ->setDisabled(!$can_edit));
79 return $curtain;
82 private function buildPropertyList(
83 PhabricatorRepositoryIdentity $identity) {
85 $viewer = $this->getViewer();
87 $properties = id(new PHUIPropertyListView())
88 ->setViewer($viewer);
90 $properties->addProperty(
91 pht('Email Address'),
92 $identity->getEmailAddress());
94 $effective_phid = $identity->getCurrentEffectiveUserPHID();
95 $automatic_phid = $identity->getAutomaticGuessedUserPHID();
96 $manual_phid = $identity->getManuallySetUserPHID();
98 if ($effective_phid) {
99 $tag = id(new PHUITagView())
100 ->setType(PHUITagView::TYPE_SHADE)
101 ->setColor('green')
102 ->setIcon('fa-check')
103 ->setName('Assigned');
104 } else {
105 $tag = id(new PHUITagView())
106 ->setType(PHUITagView::TYPE_SHADE)
107 ->setColor('indigo')
108 ->setIcon('fa-bomb')
109 ->setName('Unassigned');
111 $properties->addProperty(
112 pht('Effective User'),
113 $this->buildPropertyValue($effective_phid));
114 $properties->addProperty(
115 pht('Automatically Detected User'),
116 $this->buildPropertyValue($automatic_phid));
117 $properties->addProperty(
118 pht('Assigned To'),
119 $this->buildPropertyValue($manual_phid));
121 $header = id(new PHUIHeaderView())
122 ->setHeader(array(pht('Identity Assignments'), $tag));
124 return id(new PHUIObjectBoxView())
125 ->setHeader($header)
126 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
127 ->addPropertyList($properties);
130 private function buildPropertyValue($value) {
131 $viewer = $this->getViewer();
133 if ($value == DiffusionIdentityUnassignedDatasource::FUNCTION_TOKEN) {
134 return phutil_tag('em', array(), pht('Explicitly Unassigned'));
135 } else if (!$value) {
136 return phutil_tag('em', array(), pht('None'));
137 } else {
138 return $viewer->renderHandle($value);