Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diviner/controller/DivinerBookEditController.php
- This file was added.
| <?php | |||||
| final class DivinerBookEditController extends DivinerController { | |||||
| public function handleRequest(AphrontRequest $request) { | |||||
| $viewer = $request->getViewer(); | |||||
| $book_name = $request->getURIData('book'); | |||||
| $book = id(new DivinerBookQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->requireCapabilities( | |||||
epriestley: In modern Controllers, prefer to implement `handleRequest()` instead and access URI data with… | |||||
| array( | |||||
| PhabricatorPolicyCapability::CAN_VIEW, | |||||
Done Inline ActionsPrefer $viewer = $this->getViewer() too. epriestley: Prefer `$viewer = $this->getViewer()` too. | |||||
| PhabricatorPolicyCapability::CAN_EDIT, | |||||
| )) | |||||
| ->needProjectPHIDs(true) | |||||
| ->withNames(array($book_name)) | |||||
| ->executeOne(); | |||||
| if (!$book) { | |||||
Done Inline ActionsShould have a if !$book return 404. epriestley: Should have a `if !$book return 404`. | |||||
| return new Aphront404Response(); | |||||
Done Inline ActionsShould have a trailing slash. epriestley: Should have a trailing slash. | |||||
| } | |||||
Done Inline ActionsOh, the 404 is here -- but needs to be above $book->getName(), or we'll fatal before we get here. epriestley: Oh, the 404 is here -- but needs to be above `$book->getName()`, or we'll fatal before we get… | |||||
| $view_uri = '/book/'.$book->getName().'/'; | |||||
| if ($request->isFormPost()) { | |||||
| $v_projects = $request->getArr('projectPHIDs'); | |||||
| $v_view = $request->getStr('viewPolicy'); | |||||
| $v_edit = $request->getStr('editPolicy'); | |||||
| $xactions = array(); | |||||
| $xactions[] = id(new DivinerLiveBookTransaction()) | |||||
| ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) | |||||
| ->setMetadataValue( | |||||
| 'edge:type', | |||||
| PhabricatorProjectObjectHasProjectEdgeType::EDGECONST) | |||||
| ->setNewValue( | |||||
| array( | |||||
| '=' => array_fuse($v_projects), | |||||
| )); | |||||
| $xactions[] = id(new DivinerLiveBookTransaction()) | |||||
| ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) | |||||
| ->setNewValue($v_view); | |||||
| $xactions[] = id(new DivinerLiveBookTransaction()) | |||||
| ->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY) | |||||
| ->setNewValue($v_edit); | |||||
| id(new DivinerLiveBookEditor()) | |||||
| ->setContinueOnNoEffect(true) | |||||
| ->setContentSourceFromRequest($request) | |||||
| ->setActor($viewer) | |||||
| ->applyTransactions($book, $xactions); | |||||
| return id(new AphrontRedirectResponse())->setURI($view_uri); | |||||
| } | |||||
| $crumbs = $this->buildApplicationCrumbs(); | |||||
| $crumbs->addTextCrumb(pht('Edit Basics')); | |||||
| $title = pht('Edit %s', $book->getTitle()); | |||||
| $policies = id(new PhabricatorPolicyQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->setObject($book) | |||||
| ->execute(); | |||||
| $view_capability = PhabricatorPolicyCapability::CAN_VIEW; | |||||
| $edit_capability = PhabricatorPolicyCapability::CAN_EDIT; | |||||
| $form = id(new AphrontFormView()) | |||||
| ->setUser($viewer) | |||||
| ->appendControl( | |||||
| id(new AphrontFormTokenizerControl()) | |||||
| ->setDatasource(new PhabricatorProjectDatasource()) | |||||
| ->setName('projectPHIDs') | |||||
| ->setLabel(pht('Projects')) | |||||
| ->setValue($book->getProjectPHIDs())) | |||||
| ->appendChild( | |||||
| id(new AphrontFormPolicyControl()) | |||||
| ->setName('viewPolicy') | |||||
| ->setPolicyObject($book) | |||||
| ->setCapability($view_capability) | |||||
| ->setPolicies($policies) | |||||
| ->setCaption($book->describeAutomaticCapability($view_capability))) | |||||
| ->appendChild( | |||||
| id(new AphrontFormPolicyControl()) | |||||
| ->setName('editPolicy') | |||||
Done Inline Actions(This seems unusual?) epriestley: (This seems unusual?) | |||||
| ->setPolicyObject($book) | |||||
Done Inline ActionsHow so? joshuaspence: How so? | |||||
| ->setCapability($edit_capability) | |||||
Done Inline ActionsThe "unusual" thing was the random divider control at the bottom of the form. epriestley: The "unusual" thing was the random divider control at the bottom of the form. | |||||
Not Done Inline ActionsAh right... the inline comment doesn't line up anymore. Yeah, the divider has been removed now. joshuaspence: Ah right... the inline comment doesn't line up anymore. Yeah, the divider has been removed now. | |||||
| ->setPolicies($policies) | |||||
| ->setCaption($book->describeAutomaticCapability($edit_capability))) | |||||
| ->appendChild( | |||||
| id(new AphrontFormSubmitControl()) | |||||
| ->setValue(pht('Save')) | |||||
| ->addCancelButton($view_uri)); | |||||
| $object_box = id(new PHUIObjectBoxView()) | |||||
| ->setHeaderText($title) | |||||
| ->setForm($form); | |||||
| $timeline = $this->buildTransactionTimeline( | |||||
| $book, | |||||
| new DivinerLiveBookTransactionQuery()); | |||||
| $timeline->setShouldTerminate(true); | |||||
| return $this->buildApplicationPage( | |||||
| array( | |||||
| $crumbs, | |||||
| $object_box, | |||||
| $timeline, | |||||
| ), | |||||
| array( | |||||
| 'title' => $title, | |||||
| )); | |||||
| } | |||||
| } | |||||
In modern Controllers, prefer to implement handleRequest() instead and access URI data with $request->getURIData('book').
(This is just trying to clean up all the willProcessRequest() stubs which rarely/never do anything useful.)