1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 21:32:43 +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 {
private $id;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$document = id(new PhrictionDocumentQuery())
->setViewer($user)
->withIDs(array($this->id))
->setViewer($viewer)
->withIDs(array($id))
->needContent(true)
->requireCapabilities(
array(
@ -36,7 +30,7 @@ final class PhrictionDeleteController extends PhrictionController {
->setNewValue(true);
$editor = id(new PhrictionTransactionEditor())
->setActor($user)
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true);
try {
@ -49,13 +43,13 @@ final class PhrictionDeleteController extends PhrictionController {
if ($e_text) {
$dialog = id(new AphrontDialogView())
->setUser($user)
->setUser($viewer)
->setTitle(pht('Can Not Delete Document!'))
->appendChild($e_text)
->addCancelButton($document_uri);
} else {
$dialog = id(new AphrontDialogView())
->setUser($user)
->setUser($viewer)
->setTitle(pht('Delete Document?'))
->appendChild(
pht('Really delete this document? You can recover it later by '.

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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