mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 05:50:55 +01:00
Provide a stable URI for getting raw paste content
Summary: Fixes T9312. This is a bit fluff, but does simplify the view controller slightly and seems reasonable/useful in general. Test Plan: Clicked "View Raw File" on a paste, got redirected to the raw file via a stable URI. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9312 Differential Revision: https://secure.phabricator.com/D14167
This commit is contained in:
parent
d735c7adf2
commit
b7ca5a2d29
4 changed files with 48 additions and 14 deletions
|
@ -2510,6 +2510,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPasteListController' => 'applications/paste/controller/PhabricatorPasteListController.php',
|
||||
'PhabricatorPastePastePHIDType' => 'applications/paste/phid/PhabricatorPastePastePHIDType.php',
|
||||
'PhabricatorPasteQuery' => 'applications/paste/query/PhabricatorPasteQuery.php',
|
||||
'PhabricatorPasteRawController' => 'applications/paste/controller/PhabricatorPasteRawController.php',
|
||||
'PhabricatorPasteRemarkupRule' => 'applications/paste/remarkup/PhabricatorPasteRemarkupRule.php',
|
||||
'PhabricatorPasteSchemaSpec' => 'applications/paste/storage/PhabricatorPasteSchemaSpec.php',
|
||||
'PhabricatorPasteSearchEngine' => 'applications/paste/query/PhabricatorPasteSearchEngine.php',
|
||||
|
@ -6545,6 +6546,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPasteListController' => 'PhabricatorPasteController',
|
||||
'PhabricatorPastePastePHIDType' => 'PhabricatorPHIDType',
|
||||
'PhabricatorPasteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorPasteRawController' => 'PhabricatorPasteController',
|
||||
'PhabricatorPasteRemarkupRule' => 'PhabricatorObjectRemarkupRule',
|
||||
'PhabricatorPasteSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
||||
'PhabricatorPasteSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
|
|
|
@ -40,6 +40,7 @@ final class PhabricatorPasteApplication extends PhabricatorApplication {
|
|||
'(query/(?P<queryKey>[^/]+)/)?' => 'PhabricatorPasteListController',
|
||||
'create/' => 'PhabricatorPasteEditController',
|
||||
'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteEditController',
|
||||
'raw/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteRawController',
|
||||
'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteCommentController',
|
||||
),
|
||||
);
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Redirect to the current raw contents of a Paste.
|
||||
*
|
||||
* This controller provides a stable URI for getting the current contents of
|
||||
* a paste, and slightly simplifies the view controller.
|
||||
*/
|
||||
final class PhabricatorPasteRawController
|
||||
extends PhabricatorPasteController {
|
||||
|
||||
public function shouldAllowPublic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$id = $request->getURIData('id');
|
||||
|
||||
$paste = id(new PhabricatorPasteQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->executeOne();
|
||||
if (!$paste) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$file = id(new PhabricatorFileQuery())
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(array($paste->getFilePHID()))
|
||||
->executeOne();
|
||||
if (!$file) {
|
||||
return new Aphront400Response();
|
||||
}
|
||||
|
||||
return $file->getRedirectResponse();
|
||||
}
|
||||
|
||||
}
|
|
@ -42,14 +42,6 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
|||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$file = id(new PhabricatorFileQuery())
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(array($paste->getFilePHID()))
|
||||
->executeOne();
|
||||
if (!$file) {
|
||||
return new Aphront400Response();
|
||||
}
|
||||
|
||||
$forks = id(new PhabricatorPasteQuery())
|
||||
->setViewer($viewer)
|
||||
->withParentPHIDs(array($paste->getPHID()))
|
||||
|
@ -57,7 +49,7 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
|||
$fork_phids = mpull($forks, 'getPHID');
|
||||
|
||||
$header = $this->buildHeaderView($paste);
|
||||
$actions = $this->buildActionView($viewer, $paste, $file);
|
||||
$actions = $this->buildActionView($viewer, $paste);
|
||||
$properties = $this->buildPropertyView($paste, $fork_phids, $actions);
|
||||
|
||||
$object_box = id(new PHUIObjectBoxView())
|
||||
|
@ -139,8 +131,7 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
|||
|
||||
private function buildActionView(
|
||||
PhabricatorUser $viewer,
|
||||
PhabricatorPaste $paste,
|
||||
PhabricatorFile $file) {
|
||||
PhabricatorPaste $paste) {
|
||||
|
||||
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
||||
$viewer,
|
||||
|
@ -148,7 +139,8 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
|||
PhabricatorPolicyCapability::CAN_EDIT);
|
||||
|
||||
$can_fork = $viewer->isLoggedIn();
|
||||
$fork_uri = $this->getApplicationURI('/create/?parent='.$paste->getID());
|
||||
$id = $paste->getID();
|
||||
$fork_uri = $this->getApplicationURI('/create/?parent='.$id);
|
||||
|
||||
return id(new PhabricatorActionListView())
|
||||
->setUser($viewer)
|
||||
|
@ -160,7 +152,7 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
|||
->setIcon('fa-pencil')
|
||||
->setDisabled(!$can_edit)
|
||||
->setWorkflow(!$can_edit)
|
||||
->setHref($this->getApplicationURI('/edit/'.$paste->getID().'/')))
|
||||
->setHref($this->getApplicationURI("edit/{$id}/")))
|
||||
->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->setName(pht('Fork This Paste'))
|
||||
|
@ -172,7 +164,7 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
|||
id(new PhabricatorActionView())
|
||||
->setName(pht('View Raw File'))
|
||||
->setIcon('fa-file-text-o')
|
||||
->setHref($file->getBestURI()));
|
||||
->setHref($this->getApplicationURI("raw/{$id}/")));
|
||||
}
|
||||
|
||||
private function buildPropertyView(
|
||||
|
|
Loading…
Reference in a new issue