1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-04-03 16:08:19 +02:00
phorge-phorge/src/applications/auth/controller/contact/PhabricatorAuthContactNumberViewController.php
epriestley 12203762b7 Allow contact numbers to be enabled and disabled
Summary: Depends on D20008. Ref T920. Continue fleshing out contact number behaviors.

Test Plan:
  - Enabled and disabled a contact number.
  - Saw list, detail views reflect change.
  - Added number X, disabled it, added it again (allowed), enabled the disabled one ("already in use" exception).

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T920

Differential Revision: https://secure.phabricator.com/D20010
2019-01-23 13:59:55 -08:00

120 lines
3.2 KiB
PHP

<?php
final class PhabricatorAuthContactNumberViewController
extends PhabricatorAuthContactNumberController {
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$number = id(new PhabricatorAuthContactNumberQuery())
->setViewer($viewer)
->withIDs(array($request->getURIData('id')))
->executeOne();
if (!$number) {
return new Aphront404Response();
}
$crumbs = $this->buildApplicationCrumbs()
->addTextCrumb($number->getObjectName())
->setBorder(true);
$header = $this->buildHeaderView($number);
$properties = $this->buildPropertiesView($number);
$curtain = $this->buildCurtain($number);
$timeline = $this->buildTransactionTimeline(
$number,
new PhabricatorAuthContactNumberTransactionQuery());
$timeline->setShouldTerminate(true);
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setCurtain($curtain)
->setMainColumn(
array(
$timeline,
))
->addPropertySection(pht('Details'), $properties);
return $this->newPage()
->setTitle($number->getDisplayName())
->setCrumbs($crumbs)
->setPageObjectPHIDs(
array(
$number->getPHID(),
))
->appendChild($view);
}
private function buildHeaderView(PhabricatorAuthContactNumber $number) {
$viewer = $this->getViewer();
$view = id(new PHUIHeaderView())
->setViewer($viewer)
->setHeader($number->getObjectName())
->setPolicyObject($number);
if ($number->isDisabled()) {
$view->setStatus('fa-ban', 'red', pht('Disabled'));
}
return $view;
}
private function buildPropertiesView(
PhabricatorAuthContactNumber $number) {
$viewer = $this->getViewer();
$view = id(new PHUIPropertyListView())
->setViewer($viewer);
$view->addProperty(
pht('Owner'),
$viewer->renderHandle($number->getObjectPHID()));
$view->addProperty(pht('Contact Number'), $number->getDisplayName());
return $view;
}
private function buildCurtain(PhabricatorAuthContactNumber $number) {
$viewer = $this->getViewer();
$id = $number->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$number,
PhabricatorPolicyCapability::CAN_EDIT);
$curtain = $this->newCurtainView($number);
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Contact Number'))
->setIcon('fa-pencil')
->setHref($this->getApplicationURI("contact/edit/{$id}/"))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
if ($number->isDisabled()) {
$disable_uri = $this->getApplicationURI("contact/enable/{$id}/");
$disable_name = pht('Enable Contact Number');
$disable_icon = 'fa-check';
} else {
$disable_uri = $this->getApplicationURI("contact/disable/{$id}/");
$disable_name = pht('Disable Contact Number');
$disable_icon = 'fa-ban';
}
$curtain->addAction(
id(new PhabricatorActionView())
->setName($disable_name)
->setIcon($disable_icon)
->setHref($disable_uri)
->setWorkflow(true));
return $curtain;
}
}