Differential D16677 Diff 42812 src/applications/conpherence/controller/ConpherenceUpdateController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/conpherence/controller/ConpherenceUpdateController.php
<?php | <?php | ||||
final class ConpherenceUpdateController | final class ConpherenceUpdateController | ||||
extends ConpherenceController { | extends ConpherenceController { | ||||
public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
$user = $request->getUser(); | $user = $request->getUser(); | ||||
$conpherence_id = $request->getURIData('id'); | $conpherence_id = $request->getURIData('id'); | ||||
if (!$conpherence_id) { | if (!$conpherence_id) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$need_participants = false; | $need_participants = false; | ||||
$needed_capabilities = array(PhabricatorPolicyCapability::CAN_VIEW); | $needed_capabilities = array(PhabricatorPolicyCapability::CAN_VIEW); | ||||
$action = $request->getStr('action', ConpherenceUpdateActions::METADATA); | $action = $request->getStr('action'); | ||||
switch ($action) { | switch ($action) { | ||||
case ConpherenceUpdateActions::REMOVE_PERSON: | case ConpherenceUpdateActions::REMOVE_PERSON: | ||||
$person_phid = $request->getStr('remove_person'); | $person_phid = $request->getStr('remove_person'); | ||||
if ($person_phid != $user->getPHID()) { | if ($person_phid != $user->getPHID()) { | ||||
$needed_capabilities[] = PhabricatorPolicyCapability::CAN_EDIT; | $needed_capabilities[] = PhabricatorPolicyCapability::CAN_EDIT; | ||||
} | } | ||||
break; | break; | ||||
case ConpherenceUpdateActions::ADD_PERSON: | case ConpherenceUpdateActions::ADD_PERSON: | ||||
case ConpherenceUpdateActions::METADATA: | |||||
$needed_capabilities[] = PhabricatorPolicyCapability::CAN_EDIT; | $needed_capabilities[] = PhabricatorPolicyCapability::CAN_EDIT; | ||||
break; | break; | ||||
case ConpherenceUpdateActions::LOAD: | case ConpherenceUpdateActions::LOAD: | ||||
break; | break; | ||||
} | } | ||||
epriestley: I think we're going to kill this controller soon, but we could use a `default` + `throw` if we… | |||||
$conpherence = id(new ConpherenceThreadQuery()) | $conpherence = id(new ConpherenceThreadQuery()) | ||||
->setViewer($user) | ->setViewer($user) | ||||
->withIDs(array($conpherence_id)) | ->withIDs(array($conpherence_id)) | ||||
->needParticipants($need_participants) | ->needParticipants($need_participants) | ||||
->requireCapabilities($needed_capabilities) | ->requireCapabilities($needed_capabilities) | ||||
->executeOne(); | ->executeOne(); | ||||
$latest_transaction_id = null; | $latest_transaction_id = null; | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | if ($request->isFormPost() || ($action == ConpherenceUpdateActions::LOAD)) { | ||||
if ($person_phid) { | if ($person_phid) { | ||||
$xactions[] = id(new ConpherenceTransaction()) | $xactions[] = id(new ConpherenceTransaction()) | ||||
->setTransactionType( | ->setTransactionType( | ||||
ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE) | ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE) | ||||
->setNewValue(array('-' => array($person_phid))); | ->setNewValue(array('-' => array($person_phid))); | ||||
$response_mode = 'go-home'; | $response_mode = 'go-home'; | ||||
} | } | ||||
break; | break; | ||||
case ConpherenceUpdateActions::METADATA: | |||||
$title = $request->getStr('title'); | |||||
$topic = $request->getStr('topic'); | |||||
// all other metadata updates are continue requests | |||||
if (!$request->isContinueRequest()) { | |||||
break; | |||||
} | |||||
$title = $request->getStr('title'); | |||||
$topic = $request->getStr('topic'); | |||||
$xactions[] = id(new ConpherenceTransaction()) | |||||
->setTransactionType( | |||||
ConpherenceThreadTitleTransaction::TRANSACTIONTYPE) | |||||
->setNewValue($title); | |||||
$xactions[] = id(new ConpherenceTransaction()) | |||||
->setTransactionType( | |||||
ConpherenceThreadTopicTransaction::TRANSACTIONTYPE) | |||||
->setNewValue($topic); | |||||
$xactions[] = id(new ConpherenceTransaction()) | |||||
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) | |||||
->setNewValue($request->getStr('viewPolicy')); | |||||
$xactions[] = id(new ConpherenceTransaction()) | |||||
->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY) | |||||
->setNewValue($request->getStr('editPolicy')); | |||||
if (!$request->getExists('force_ajax')) { | |||||
$response_mode = 'redirect'; | |||||
} | |||||
break; | |||||
case ConpherenceUpdateActions::LOAD: | case ConpherenceUpdateActions::LOAD: | ||||
$updated = false; | $updated = false; | ||||
$response_mode = 'ajax'; | $response_mode = 'ajax'; | ||||
break; | break; | ||||
default: | default: | ||||
throw new Exception(pht('Unknown action: %s', $action)); | throw new Exception(pht('Unknown action: %s', $action)); | ||||
break; | break; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | public function handleRequest(AphrontRequest $request) { | ||||
switch ($action) { | switch ($action) { | ||||
case ConpherenceUpdateActions::ADD_PERSON: | case ConpherenceUpdateActions::ADD_PERSON: | ||||
$dialog = $this->renderAddPersonDialog($conpherence); | $dialog = $this->renderAddPersonDialog($conpherence); | ||||
break; | break; | ||||
case ConpherenceUpdateActions::REMOVE_PERSON: | case ConpherenceUpdateActions::REMOVE_PERSON: | ||||
$dialog = $this->renderRemovePersonDialog($conpherence); | $dialog = $this->renderRemovePersonDialog($conpherence); | ||||
break; | break; | ||||
case ConpherenceUpdateActions::METADATA: | |||||
default: | |||||
$dialog = $this->renderMetadataDialog($conpherence, $error_view); | |||||
break; | |||||
} | } | ||||
return | return | ||||
$dialog | $dialog | ||||
->setUser($user) | ->setUser($user) | ||||
->setWidth(AphrontDialogView::WIDTH_FORM) | ->setWidth(AphrontDialogView::WIDTH_FORM) | ||||
->setSubmitURI($this->getApplicationURI('update/'.$conpherence_id.'/')) | ->setSubmitURI($this->getApplicationURI('update/'.$conpherence_id.'/')) | ||||
->addSubmitButton() | ->addSubmitButton() | ||||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | private function renderRemovePersonDialog( | ||||
foreach ($body as $paragraph) { | foreach ($body as $paragraph) { | ||||
$dialog->appendParagraph($paragraph); | $dialog->appendParagraph($paragraph); | ||||
} | } | ||||
return $dialog; | return $dialog; | ||||
} | } | ||||
private function renderMetadataDialog( | |||||
ConpherenceThread $conpherence, | |||||
$error_view) { | |||||
$request = $this->getRequest(); | |||||
$user = $request->getUser(); | |||||
$title = pht('Update Room'); | |||||
$form = id(new PHUIFormLayoutView()) | |||||
->appendChild($error_view) | |||||
->appendChild( | |||||
id(new AphrontFormTextControl()) | |||||
->setLabel(pht('Title')) | |||||
->setName('title') | |||||
->setValue($conpherence->getTitle())) | |||||
->appendChild( | |||||
id(new AphrontFormTextControl()) | |||||
->setLabel(pht('Topic')) | |||||
->setName('topic') | |||||
->setValue($conpherence->getTopic())); | |||||
$policies = id(new PhabricatorPolicyQuery()) | |||||
->setViewer($user) | |||||
->setObject($conpherence) | |||||
->execute(); | |||||
$form | |||||
->appendChild( | |||||
id(new AphrontFormPolicyControl()) | |||||
->setName('viewPolicy') | |||||
->setPolicyObject($conpherence) | |||||
->setCapability(PhabricatorPolicyCapability::CAN_VIEW) | |||||
->setPolicies($policies)) | |||||
->appendChild( | |||||
id(new AphrontFormPolicyControl()) | |||||
->setName('editPolicy') | |||||
->setPolicyObject($conpherence) | |||||
->setCapability(PhabricatorPolicyCapability::CAN_EDIT) | |||||
->setPolicies($policies)); | |||||
$view = id(new AphrontDialogView()) | |||||
->setTitle($title) | |||||
->addHiddenInput('action', 'metadata') | |||||
->addHiddenInput( | |||||
'latest_transaction_id', | |||||
$request->getInt('latest_transaction_id')) | |||||
->addHiddenInput('__continue__', true) | |||||
->appendChild($form); | |||||
if ($request->getExists('force_ajax')) { | |||||
$view->addHiddenInput('force_ajax', true); | |||||
} | |||||
return $view; | |||||
} | |||||
private function loadAndRenderUpdates( | private function loadAndRenderUpdates( | ||||
$action, | $action, | ||||
$conpherence_id, | $conpherence_id, | ||||
$latest_transaction_id) { | $latest_transaction_id) { | ||||
$need_transactions = false; | $need_transactions = false; | ||||
switch ($action) { | switch ($action) { | ||||
case ConpherenceUpdateActions::METADATA: | |||||
case ConpherenceUpdateActions::LOAD: | case ConpherenceUpdateActions::LOAD: | ||||
$need_transactions = true; | $need_transactions = true; | ||||
break; | break; | ||||
case ConpherenceUpdateActions::MESSAGE: | case ConpherenceUpdateActions::MESSAGE: | ||||
case ConpherenceUpdateActions::ADD_PERSON: | case ConpherenceUpdateActions::ADD_PERSON: | ||||
$need_transactions = true; | $need_transactions = true; | ||||
break; | break; | ||||
case ConpherenceUpdateActions::REMOVE_PERSON: | case ConpherenceUpdateActions::REMOVE_PERSON: | ||||
Show All 32 Lines | private function loadAndRenderUpdates( | ||||
$rendered_transactions = idx($data, 'transactions'); | $rendered_transactions = idx($data, 'transactions'); | ||||
$new_latest_transaction_id = idx($data, 'latest_transaction_id'); | $new_latest_transaction_id = idx($data, 'latest_transaction_id'); | ||||
$update_uri = $this->getApplicationURI('update/'.$conpherence->getID().'/'); | $update_uri = $this->getApplicationURI('update/'.$conpherence->getID().'/'); | ||||
$nav_item = null; | $nav_item = null; | ||||
$header = null; | $header = null; | ||||
$people_widget = null; | $people_widget = null; | ||||
switch ($action) { | switch ($action) { | ||||
case ConpherenceUpdateActions::METADATA: | |||||
$header = $this->buildHeaderPaneContent($conpherence); | |||||
$header = hsprintf('%s', $header); | |||||
$nav_item = id(new ConpherenceThreadListView()) | |||||
->setUser($user) | |||||
->setBaseURI($this->getApplicationURI()) | |||||
->renderThreadItem($conpherence); | |||||
$nav_item = hsprintf('%s', $nav_item); | |||||
break; | |||||
case ConpherenceUpdateActions::ADD_PERSON: | case ConpherenceUpdateActions::ADD_PERSON: | ||||
$people_widget = id(new ConpherenceParticipantView()) | $people_widget = id(new ConpherenceParticipantView()) | ||||
->setUser($user) | ->setUser($user) | ||||
->setConpherence($conpherence) | ->setConpherence($conpherence) | ||||
->setUpdateURI($update_uri); | ->setUpdateURI($update_uri); | ||||
$people_widget = hsprintf('%s', $people_widget->render()); | $people_widget = hsprintf('%s', $people_widget->render()); | ||||
break; | break; | ||||
case ConpherenceUpdateActions::REMOVE_PERSON: | case ConpherenceUpdateActions::REMOVE_PERSON: | ||||
▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines |
I think we're going to kill this controller soon, but we could use a default + throw if we don't.