Differential D20664 Diff 49291 src/applications/auth/controller/message/PhabricatorAuthMessageViewController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/controller/message/PhabricatorAuthMessageViewController.php
| <?php | <?php | ||||
| final class PhabricatorAuthMessageViewController | final class PhabricatorAuthMessageViewController | ||||
| extends PhabricatorAuthMessageController { | extends PhabricatorAuthMessageController { | ||||
| public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $this->requireApplicationCapability( | $this->requireApplicationCapability( | ||||
| AuthManageProvidersCapability::CAPABILITY); | AuthManageProvidersCapability::CAPABILITY); | ||||
| // The "id" in the URI may either be an actual storage record ID (if a | |||||
| // message has already been created) or a message type key (for a message | |||||
| // type which does not have a record yet). | |||||
| // This flow allows messages which have not been set yet to have a detail | |||||
| // page (so users can get detailed information about the message and see | |||||
| // any default value). | |||||
| $id = $request->getURIData('id'); | |||||
| if (ctype_digit($id)) { | |||||
| $message = id(new PhabricatorAuthMessageQuery()) | $message = id(new PhabricatorAuthMessageQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withIDs(array($request->getURIData('id'))) | ->withIDs(array($id)) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| if (!$message) { | if (!$message) { | ||||
| return new Aphront404Response(); | return new Aphront404Response(); | ||||
| } | } | ||||
| } else { | |||||
| $types = PhabricatorAuthMessageType::getAllMessageTypes(); | |||||
| if (!isset($types[$id])) { | |||||
| return new Aphront404Response(); | |||||
| } | |||||
| // If this message type already has a storage record, redirect to the | |||||
| // canonical page for the record. | |||||
| $message = id(new PhabricatorAuthMessageQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withMessageKeys(array($id)) | |||||
| ->executeOne(); | |||||
| if ($message) { | |||||
| $message_uri = $message->getURI(); | |||||
| return id(new AphrontRedirectResponse())->setURI($message_uri); | |||||
| } | |||||
| // Otherwise, create an empty placeholder message object with the | |||||
| // appropriate message type. | |||||
| $message = PhabricatorAuthMessage::initializeNewMessage($types[$id]); | |||||
| } | |||||
| $crumbs = $this->buildApplicationCrumbs() | $crumbs = $this->buildApplicationCrumbs() | ||||
| ->addTextCrumb($message->getObjectName()) | ->addTextCrumb($message->getMessageType()->getDisplayName()) | ||||
| ->setBorder(true); | ->setBorder(true); | ||||
| $header = $this->buildHeaderView($message); | $header = $this->buildHeaderView($message); | ||||
| $properties = $this->buildPropertiesView($message); | $properties = $this->buildPropertiesView($message); | ||||
| $curtain = $this->buildCurtain($message); | $curtain = $this->buildCurtain($message); | ||||
| if ($message->getID()) { | |||||
| $timeline = $this->buildTransactionTimeline( | $timeline = $this->buildTransactionTimeline( | ||||
| $message, | $message, | ||||
| new PhabricatorAuthMessageTransactionQuery()); | new PhabricatorAuthMessageTransactionQuery()); | ||||
| $timeline->setShouldTerminate(true); | $timeline->setShouldTerminate(true); | ||||
| } else { | |||||
| $timeline = null; | |||||
| } | |||||
| $view = id(new PHUITwoColumnView()) | $view = id(new PHUITwoColumnView()) | ||||
| ->setHeader($header) | ->setHeader($header) | ||||
| ->setCurtain($curtain) | ->setCurtain($curtain) | ||||
| ->setMainColumn( | ->setMainColumn( | ||||
| array( | array( | ||||
| $timeline, | $timeline, | ||||
| )) | )) | ||||
| Show All 24 Lines | private function buildPropertiesView(PhabricatorAuthMessage $message) { | ||||
| $view = id(new PHUIPropertyListView()) | $view = id(new PHUIPropertyListView()) | ||||
| ->setViewer($viewer); | ->setViewer($viewer); | ||||
| $view->addProperty( | $view->addProperty( | ||||
| pht('Description'), | pht('Description'), | ||||
| $message->getMessageType()->getShortDescription()); | $message->getMessageType()->getShortDescription()); | ||||
| if (strlen($message->getMessageText())) { | |||||
| $view->addSectionHeader( | $view->addSectionHeader( | ||||
| pht('Message Preview'), | pht('Message Preview'), | ||||
| PHUIPropertyListView::ICON_SUMMARY); | PHUIPropertyListView::ICON_SUMMARY); | ||||
| $view->addTextContent( | $view->addTextContent( | ||||
| new PHUIRemarkupView($viewer, $message->getMessageText())); | new PHUIRemarkupView($viewer, $message->getMessageText())); | ||||
| } | |||||
| return $view; | return $view; | ||||
| } | } | ||||
| private function buildCurtain(PhabricatorAuthMessage $message) { | private function buildCurtain(PhabricatorAuthMessage $message) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $id = $message->getID(); | $id = $message->getID(); | ||||
| $can_edit = PhabricatorPolicyFilter::hasCapability( | $can_edit = PhabricatorPolicyFilter::hasCapability( | ||||
| $viewer, | $viewer, | ||||
| $message, | $message, | ||||
| PhabricatorPolicyCapability::CAN_EDIT); | PhabricatorPolicyCapability::CAN_EDIT); | ||||
| if ($id) { | |||||
| $edit_uri = urisprintf('message/edit/%s/', $id); | |||||
| $edit_name = pht('Edit Message'); | |||||
| } else { | |||||
| $edit_uri = urisprintf('message/edit/'); | |||||
| $params = array( | |||||
| 'messageKey' => $message->getMessageKey(), | |||||
| ); | |||||
| $edit_uri = new PhutilURI($edit_uri, $params); | |||||
| $edit_name = pht('Customize Message'); | |||||
| } | |||||
| $edit_uri = $this->getApplicationURI($edit_uri); | |||||
| $curtain = $this->newCurtainView($message); | $curtain = $this->newCurtainView($message); | ||||
| $curtain->addAction( | $curtain->addAction( | ||||
| id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
| ->setName(pht('Edit Message')) | ->setName($edit_name) | ||||
| ->setIcon('fa-pencil') | ->setIcon('fa-pencil') | ||||
| ->setHref($this->getApplicationURI("message/edit/{$id}/")) | ->setHref($edit_uri) | ||||
| ->setDisabled(!$can_edit) | ->setDisabled(!$can_edit) | ||||
| ->setWorkflow(!$can_edit)); | ->setWorkflow(!$can_edit)); | ||||
| return $curtain; | return $curtain; | ||||
| } | } | ||||
| } | } | ||||