1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-20 05:42:40 +01:00

Update Phriction for handleRequest

Summary: Updates Phriction calls to handleRequest

Test Plan: Create, Delete, Move a Phriction Document. Check history, diff.

Reviewers: btrahan, epriestley

Reviewed By: epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T8628

Differential Revision: https://secure.phabricator.com/D13682
This commit is contained in:
Chad Little 2015-07-22 13:25:36 -07:00
parent 1aed0e67a9
commit 96cecebf65
7 changed files with 60 additions and 93 deletions

View file

@ -2,19 +2,13 @@
final class PhrictionDeleteController extends PhrictionController { final class PhrictionDeleteController extends PhrictionController {
private $id; public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
public function willProcessRequest(array $data) { $id = $request->getURIData('id');
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$document = id(new PhrictionDocumentQuery()) $document = id(new PhrictionDocumentQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($this->id)) ->withIDs(array($id))
->needContent(true) ->needContent(true)
->requireCapabilities( ->requireCapabilities(
array( array(
@ -36,7 +30,7 @@ final class PhrictionDeleteController extends PhrictionController {
->setNewValue(true); ->setNewValue(true);
$editor = id(new PhrictionTransactionEditor()) $editor = id(new PhrictionTransactionEditor())
->setActor($user) ->setActor($viewer)
->setContentSourceFromRequest($request) ->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true); ->setContinueOnNoEffect(true);
try { try {
@ -49,13 +43,13 @@ final class PhrictionDeleteController extends PhrictionController {
if ($e_text) { if ($e_text) {
$dialog = id(new AphrontDialogView()) $dialog = id(new AphrontDialogView())
->setUser($user) ->setUser($viewer)
->setTitle(pht('Can Not Delete Document!')) ->setTitle(pht('Can Not Delete Document!'))
->appendChild($e_text) ->appendChild($e_text)
->addCancelButton($document_uri); ->addCancelButton($document_uri);
} else { } else {
$dialog = id(new AphrontDialogView()) $dialog = id(new AphrontDialogView())
->setUser($user) ->setUser($viewer)
->setTitle(pht('Delete Document?')) ->setTitle(pht('Delete Document?'))
->appendChild( ->appendChild(
pht('Really delete this document? You can recover it later by '. pht('Really delete this document? You can recover it later by '.

View file

@ -2,23 +2,17 @@
final class PhrictionDiffController extends PhrictionController { final class PhrictionDiffController extends PhrictionController {
private $id;
public function shouldAllowPublic() { public function shouldAllowPublic() {
return true; return true;
} }
public function willProcessRequest(array $data) { public function handleRequest(AphrontRequest $request) {
$this->id = $data['id']; $viewer = $request->getViewer();
} $id = $request->getURIData('id');
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$document = id(new PhrictionDocumentQuery()) $document = id(new PhrictionDocumentQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($this->id)) ->withIDs(array($id))
->needContent(true) ->needContent(true)
->executeOne(); ->executeOne();
if (!$document) { if (!$document) {
@ -73,7 +67,7 @@ final class PhrictionDiffController extends PhrictionController {
$whitespace_mode = DifferentialChangesetParser::WHITESPACE_SHOW_ALL; $whitespace_mode = DifferentialChangesetParser::WHITESPACE_SHOW_ALL;
$parser = id(new DifferentialChangesetParser()) $parser = id(new DifferentialChangesetParser())
->setUser($user) ->setUser($viewer)
->setChangeset($changeset) ->setChangeset($changeset)
->setRenderingReference("{$l},{$r}"); ->setRenderingReference("{$l},{$r}");
@ -81,7 +75,7 @@ final class PhrictionDiffController extends PhrictionController {
$parser->setWhitespaceMode($whitespace_mode); $parser->setWhitespaceMode($whitespace_mode);
$engine = new PhabricatorMarkupEngine(); $engine = new PhabricatorMarkupEngine();
$engine->setViewer($user); $engine->setViewer($viewer);
$engine->process(); $engine->process();
$parser->setMarkupEngine($engine); $parser->setMarkupEngine($engine);
@ -262,7 +256,7 @@ final class PhrictionDiffController extends PhrictionController {
private function renderComparisonTable(array $content) { private function renderComparisonTable(array $content) {
assert_instances_of($content, 'PhrictionContent'); assert_instances_of($content, 'PhrictionContent');
$user = $this->getRequest()->getUser(); $viewer = $this->getViewer();
$phids = mpull($content, 'getAuthorPHID'); $phids = mpull($content, 'getAuthorPHID');
$handles = $this->loadViewerHandles($phids); $handles = $this->loadViewerHandles($phids);
@ -278,8 +272,8 @@ final class PhrictionDiffController extends PhrictionController {
$author, $author,
pht('Version %s', $c->getVersion()))) pht('Version %s', $c->getVersion())))
->addAttribute(pht('%s %s', ->addAttribute(pht('%s %s',
phabricator_date($c->getDateCreated(), $user), phabricator_date($c->getDateCreated(), $viewer),
phabricator_time($c->getDateCreated(), $user))); phabricator_time($c->getDateCreated(), $viewer)));
if ($c->getDescription()) { if ($c->getDescription()) {
$item->addAttribute($c->getDescription()); $item->addAttribute($c->getDescription());

View file

@ -9,13 +9,9 @@ final class PhrictionDocumentController
return true; return true;
} }
public function willProcessRequest(array $data) { public function handleRequest(AphrontRequest $request) {
$this->slug = $data['slug']; $viewer = $request->getViewer();
} $this->slug = $request->getURIData('slug');
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$slug = PhabricatorSlug::normalize($this->slug); $slug = PhabricatorSlug::normalize($this->slug);
if ($slug != $this->slug) { if ($slug != $this->slug) {
@ -27,7 +23,7 @@ final class PhrictionDocumentController
require_celerity_resource('phriction-document-css'); require_celerity_resource('phriction-document-css');
$document = id(new PhrictionDocumentQuery()) $document = id(new PhrictionDocumentQuery())
->setViewer($user) ->setViewer($viewer)
->withSlugs(array($slug)) ->withSlugs(array($slug))
->executeOne(); ->executeOne();
@ -39,7 +35,7 @@ final class PhrictionDocumentController
if (!$document) { if (!$document) {
$document = PhrictionDocument::initializeNewDocument($user, $slug); $document = PhrictionDocument::initializeNewDocument($viewer, $slug);
$create_uri = '/phriction/edit/?slug='.$slug; $create_uri = '/phriction/edit/?slug='.$slug;
@ -67,7 +63,7 @@ final class PhrictionDocumentController
} }
if ($content->getID() != $document->getContentID()) { if ($content->getID() != $document->getContentID()) {
$vdate = phabricator_datetime($content->getDateCreated(), $user); $vdate = phabricator_datetime($content->getDateCreated(), $viewer);
$version_note = new PHUIInfoView(); $version_note = new PHUIInfoView();
$version_note->setSeverity(PHUIInfoView::SEVERITY_NOTICE); $version_note->setSeverity(PHUIInfoView::SEVERITY_NOTICE);
$version_note->appendChild( $version_note->appendChild(
@ -87,7 +83,7 @@ final class PhrictionDocumentController
if ($current_status == PhrictionChangeType::CHANGE_EDIT || if ($current_status == PhrictionChangeType::CHANGE_EDIT ||
$current_status == PhrictionChangeType::CHANGE_MOVE_HERE) { $current_status == PhrictionChangeType::CHANGE_MOVE_HERE) {
$core_content = $content->renderContent($user); $core_content = $content->renderContent($viewer);
} else if ($current_status == PhrictionChangeType::CHANGE_DELETE) { } else if ($current_status == PhrictionChangeType::CHANGE_DELETE) {
$notice = new PHUIInfoView(); $notice = new PHUIInfoView();
$notice->setSeverity(PHUIInfoView::SEVERITY_NOTICE); $notice->setSeverity(PHUIInfoView::SEVERITY_NOTICE);
@ -112,7 +108,7 @@ final class PhrictionDocumentController
// If the new document exists and the viewer can see it, provide a link // If the new document exists and the viewer can see it, provide a link
// to it. Otherwise, render a generic message. // to it. Otherwise, render a generic message.
$new_docs = id(new PhrictionDocumentQuery()) $new_docs = id(new PhrictionDocumentQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($new_doc_id)) ->withIDs(array($new_doc_id))
->execute(); ->execute();
if ($new_docs) { if ($new_docs) {
@ -157,7 +153,7 @@ final class PhrictionDocumentController
// If the old document exists and is visible, provide a link to it. // If the old document exists and is visible, provide a link to it.
$from_docs = id(new PhrictionDocumentQuery()) $from_docs = id(new PhrictionDocumentQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($from_doc_id)) ->withIDs(array($from_doc_id))
->execute(); ->execute();
if ($from_docs) { if ($from_docs) {
@ -183,7 +179,7 @@ final class PhrictionDocumentController
$children = $this->renderDocumentChildren($slug); $children = $this->renderDocumentChildren($slug);
$actions = $this->buildActionView($user, $document); $actions = $this->buildActionView($viewer, $document);
$crumbs = $this->buildApplicationCrumbs(); $crumbs = $this->buildApplicationCrumbs();
$crumbs->setBorder(true); $crumbs->setBorder(true);
@ -201,7 +197,7 @@ final class PhrictionDocumentController
->setDropdownMenu($actions); ->setDropdownMenu($actions);
$header = id(new PHUIHeaderView()) $header = id(new PHUIHeaderView())
->setUser($user) ->setUser($viewer)
->setPolicyObject($document) ->setPolicyObject($document)
->setHeader($page_title) ->setHeader($page_title)
->addActionLink($action_button); ->addActionLink($action_button);
@ -257,17 +253,17 @@ final class PhrictionDocumentController
} }
private function buildActionView( private function buildActionView(
PhabricatorUser $user, PhabricatorUser $viewer,
PhrictionDocument $document) { PhrictionDocument $document) {
$can_edit = PhabricatorPolicyFilter::hasCapability( $can_edit = PhabricatorPolicyFilter::hasCapability(
$user, $viewer,
$document, $document,
PhabricatorPolicyCapability::CAN_EDIT); PhabricatorPolicyCapability::CAN_EDIT);
$slug = PhabricatorSlug::normalize($this->slug); $slug = PhabricatorSlug::normalize($this->slug);
$action_view = id(new PhabricatorActionListView()) $action_view = id(new PhabricatorActionListView())
->setUser($user) ->setUser($viewer)
->setObjectURI($this->getRequest()->getRequestURI()) ->setObjectURI($this->getRequest()->getRequestURI())
->setObject($document); ->setObject($document);

View file

@ -3,22 +3,15 @@
final class PhrictionEditController final class PhrictionEditController
extends PhrictionController { extends PhrictionController {
private $id; public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
public function willProcessRequest(array $data) { $id = $request->getURIData('id');
$this->id = idx($data, 'id');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$current_version = null; $current_version = null;
if ($this->id) { if ($id) {
$document = id(new PhrictionDocumentQuery()) $document = id(new PhrictionDocumentQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($this->id)) ->withIDs(array($id))
->needContent(true) ->needContent(true)
->requireCapabilities( ->requireCapabilities(
array( array(
@ -53,7 +46,7 @@ final class PhrictionEditController
} }
$document = id(new PhrictionDocumentQuery()) $document = id(new PhrictionDocumentQuery())
->setViewer($user) ->setViewer($viewer)
->withSlugs(array($slug)) ->withSlugs(array($slug))
->needContent(true) ->needContent(true)
->executeOne(); ->executeOne();
@ -62,7 +55,7 @@ final class PhrictionEditController
$content = $document->getContent(); $content = $document->getContent();
$current_version = $content->getVersion(); $current_version = $content->getVersion();
} else { } else {
$document = PhrictionDocument::initializeNewDocument($user, $slug); $document = PhrictionDocument::initializeNewDocument($viewer, $slug);
$content = $document->getContent(); $content = $document->getContent();
} }
} }
@ -78,7 +71,7 @@ final class PhrictionEditController
} }
$draft = id(new PhabricatorDraft())->loadOneWhere( $draft = id(new PhabricatorDraft())->loadOneWhere(
'authorPHID = %s AND draftKey = %s', 'authorPHID = %s AND draftKey = %s',
$user->getPHID(), $viewer->getPHID(),
$draft_key); $draft_key);
} }
@ -141,7 +134,7 @@ final class PhrictionEditController
->setNewValue($v_edit); ->setNewValue($v_edit);
$editor = id(new PhrictionTransactionEditor()) $editor = id(new PhrictionTransactionEditor())
->setActor($user) ->setActor($viewer)
->setContentSourceFromRequest($request) ->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true) ->setContinueOnNoEffect(true)
->setDescription($notes) ->setDescription($notes)
@ -198,14 +191,14 @@ final class PhrictionEditController
$cancel_uri = PhrictionDocument::getSlugURI($document->getSlug()); $cancel_uri = PhrictionDocument::getSlugURI($document->getSlug());
$policies = id(new PhabricatorPolicyQuery()) $policies = id(new PhabricatorPolicyQuery())
->setViewer($user) ->setViewer($viewer)
->setObject($document) ->setObject($document)
->execute(); ->execute();
$view_capability = PhabricatorPolicyCapability::CAN_VIEW; $view_capability = PhabricatorPolicyCapability::CAN_VIEW;
$edit_capability = PhabricatorPolicyCapability::CAN_EDIT; $edit_capability = PhabricatorPolicyCapability::CAN_EDIT;
$form = id(new AphrontFormView()) $form = id(new AphrontFormView())
->setUser($user) ->setUser($viewer)
->addHiddenInput('slug', $document->getSlug()) ->addHiddenInput('slug', $document->getSlug())
->addHiddenInput('nodraft', $request->getBool('nodraft')) ->addHiddenInput('nodraft', $request->getBool('nodraft'))
->addHiddenInput('contentVersion', $current_version) ->addHiddenInput('contentVersion', $current_version)
@ -228,7 +221,7 @@ final class PhrictionEditController
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL) ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
->setName('content') ->setName('content')
->setID('document-textarea') ->setID('document-textarea')
->setUser($user)) ->setUser($viewer))
->appendChild( ->appendChild(
id(new AphrontFormPolicyControl()) id(new AphrontFormPolicyControl())
->setName('viewPolicy') ->setName('viewPolicy')

View file

@ -9,17 +9,12 @@ final class PhrictionHistoryController
return true; return true;
} }
public function willProcessRequest(array $data) { public function handleRequest(AphrontRequest $request) {
$this->slug = $data['slug']; $viewer = $request->getViewer();
} $this->slug = $request->getURIData('slug');
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$document = id(new PhrictionDocumentQuery()) $document = id(new PhrictionDocumentQuery())
->setViewer($user) ->setViewer($viewer)
->withSlugs(array(PhabricatorSlug::normalize($this->slug))) ->withSlugs(array(PhabricatorSlug::normalize($this->slug)))
->needContent(true) ->needContent(true)
->executeOne(); ->executeOne();
@ -102,8 +97,8 @@ final class PhrictionHistoryController
), ),
pht('Version %s', $version))) pht('Version %s', $version)))
->addAttribute(pht('%s %s', ->addAttribute(pht('%s %s',
phabricator_date($content->getDateCreated(), $user), phabricator_date($content->getDateCreated(), $viewer),
phabricator_time($content->getDateCreated(), $user))); phabricator_time($content->getDateCreated(), $viewer)));
if ($content->getDescription()) { if ($content->getDescription()) {
$item->addAttribute($content->getDescription()); $item->addAttribute($content->getDescription());

View file

@ -3,19 +3,15 @@
final class PhrictionListController final class PhrictionListController
extends PhrictionController { extends PhrictionController {
private $queryKey;
public function shouldAllowPublic() { public function shouldAllowPublic() {
return true; return true;
} }
public function willProcessRequest(array $data) { public function handleRequest(AphrontRequest $request) {
$this->queryKey = idx($data, 'queryKey'); $querykey = $request->getURIData('queryKey');
}
public function processRequest() {
$controller = id(new PhabricatorApplicationSearchController()) $controller = id(new PhabricatorApplicationSearchController())
->setQueryKey($this->queryKey) ->setQueryKey($querykey)
->setSearchEngine(new PhrictionSearchEngine()) ->setSearchEngine(new PhrictionSearchEngine())
->setNavigation($this->buildSideNavView()); ->setNavigation($this->buildSideNavView());

View file

@ -2,14 +2,13 @@
final class PhrictionNewController extends PhrictionController { final class PhrictionNewController extends PhrictionController {
public function processRequest() { public function handleRequest(AphrontRequest $request) {
$request = $this->getRequest(); $viewer = $request->getViewer();
$user = $request->getUser(); $slug = PhabricatorSlug::normalize($request->getStr('slug'));
$slug = PhabricatorSlug::normalize($request->getStr('slug'));
if ($request->isFormPost()) { if ($request->isFormPost()) {
$document = id(new PhrictionDocumentQuery()) $document = id(new PhrictionDocumentQuery())
->setViewer($user) ->setViewer($viewer)
->withSlugs(array($slug)) ->withSlugs(array($slug))
->executeOne(); ->executeOne();
$prompt = $request->getStr('prompt', 'no'); $prompt = $request->getStr('prompt', 'no');
@ -20,7 +19,7 @@ final class PhrictionNewController extends PhrictionController {
$dialog = new AphrontDialogView(); $dialog = new AphrontDialogView();
$dialog->setSubmitURI('/phriction/new/') $dialog->setSubmitURI('/phriction/new/')
->setTitle(pht('Edit Existing Document?')) ->setTitle(pht('Edit Existing Document?'))
->setUser($user) ->setUser($viewer)
->appendChild(pht( ->appendChild(pht(
'The document %s already exists. Do you want to edit it instead?', 'The document %s already exists. Do you want to edit it instead?',
phutil_tag('tt', array(), $slug))) phutil_tag('tt', array(), $slug)))
@ -48,7 +47,7 @@ final class PhrictionNewController extends PhrictionController {
->setName('slug')); ->setName('slug'));
$dialog = id(new AphrontDialogView()) $dialog = id(new AphrontDialogView())
->setUser($user) ->setUser($viewer)
->setTitle(pht('New Document')) ->setTitle(pht('New Document'))
->setSubmitURI('/phriction/new/') ->setSubmitURI('/phriction/new/')
->appendChild(phutil_tag('p', ->appendChild(phutil_tag('p',