mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-14 02:42:40 +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',
|
'PhabricatorPasteListController' => 'applications/paste/controller/PhabricatorPasteListController.php',
|
||||||
'PhabricatorPastePastePHIDType' => 'applications/paste/phid/PhabricatorPastePastePHIDType.php',
|
'PhabricatorPastePastePHIDType' => 'applications/paste/phid/PhabricatorPastePastePHIDType.php',
|
||||||
'PhabricatorPasteQuery' => 'applications/paste/query/PhabricatorPasteQuery.php',
|
'PhabricatorPasteQuery' => 'applications/paste/query/PhabricatorPasteQuery.php',
|
||||||
|
'PhabricatorPasteRawController' => 'applications/paste/controller/PhabricatorPasteRawController.php',
|
||||||
'PhabricatorPasteRemarkupRule' => 'applications/paste/remarkup/PhabricatorPasteRemarkupRule.php',
|
'PhabricatorPasteRemarkupRule' => 'applications/paste/remarkup/PhabricatorPasteRemarkupRule.php',
|
||||||
'PhabricatorPasteSchemaSpec' => 'applications/paste/storage/PhabricatorPasteSchemaSpec.php',
|
'PhabricatorPasteSchemaSpec' => 'applications/paste/storage/PhabricatorPasteSchemaSpec.php',
|
||||||
'PhabricatorPasteSearchEngine' => 'applications/paste/query/PhabricatorPasteSearchEngine.php',
|
'PhabricatorPasteSearchEngine' => 'applications/paste/query/PhabricatorPasteSearchEngine.php',
|
||||||
|
@ -6545,6 +6546,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorPasteListController' => 'PhabricatorPasteController',
|
'PhabricatorPasteListController' => 'PhabricatorPasteController',
|
||||||
'PhabricatorPastePastePHIDType' => 'PhabricatorPHIDType',
|
'PhabricatorPastePastePHIDType' => 'PhabricatorPHIDType',
|
||||||
'PhabricatorPasteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PhabricatorPasteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
|
'PhabricatorPasteRawController' => 'PhabricatorPasteController',
|
||||||
'PhabricatorPasteRemarkupRule' => 'PhabricatorObjectRemarkupRule',
|
'PhabricatorPasteRemarkupRule' => 'PhabricatorObjectRemarkupRule',
|
||||||
'PhabricatorPasteSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
'PhabricatorPasteSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
||||||
'PhabricatorPasteSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
'PhabricatorPasteSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
|
|
|
@ -40,6 +40,7 @@ final class PhabricatorPasteApplication extends PhabricatorApplication {
|
||||||
'(query/(?P<queryKey>[^/]+)/)?' => 'PhabricatorPasteListController',
|
'(query/(?P<queryKey>[^/]+)/)?' => 'PhabricatorPasteListController',
|
||||||
'create/' => 'PhabricatorPasteEditController',
|
'create/' => 'PhabricatorPasteEditController',
|
||||||
'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteEditController',
|
'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteEditController',
|
||||||
|
'raw/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteRawController',
|
||||||
'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteCommentController',
|
'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();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = id(new PhabricatorFileQuery())
|
|
||||||
->setViewer($viewer)
|
|
||||||
->withPHIDs(array($paste->getFilePHID()))
|
|
||||||
->executeOne();
|
|
||||||
if (!$file) {
|
|
||||||
return new Aphront400Response();
|
|
||||||
}
|
|
||||||
|
|
||||||
$forks = id(new PhabricatorPasteQuery())
|
$forks = id(new PhabricatorPasteQuery())
|
||||||
->setViewer($viewer)
|
->setViewer($viewer)
|
||||||
->withParentPHIDs(array($paste->getPHID()))
|
->withParentPHIDs(array($paste->getPHID()))
|
||||||
|
@ -57,7 +49,7 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
||||||
$fork_phids = mpull($forks, 'getPHID');
|
$fork_phids = mpull($forks, 'getPHID');
|
||||||
|
|
||||||
$header = $this->buildHeaderView($paste);
|
$header = $this->buildHeaderView($paste);
|
||||||
$actions = $this->buildActionView($viewer, $paste, $file);
|
$actions = $this->buildActionView($viewer, $paste);
|
||||||
$properties = $this->buildPropertyView($paste, $fork_phids, $actions);
|
$properties = $this->buildPropertyView($paste, $fork_phids, $actions);
|
||||||
|
|
||||||
$object_box = id(new PHUIObjectBoxView())
|
$object_box = id(new PHUIObjectBoxView())
|
||||||
|
@ -139,8 +131,7 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
||||||
|
|
||||||
private function buildActionView(
|
private function buildActionView(
|
||||||
PhabricatorUser $viewer,
|
PhabricatorUser $viewer,
|
||||||
PhabricatorPaste $paste,
|
PhabricatorPaste $paste) {
|
||||||
PhabricatorFile $file) {
|
|
||||||
|
|
||||||
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
||||||
$viewer,
|
$viewer,
|
||||||
|
@ -148,7 +139,8 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
||||||
PhabricatorPolicyCapability::CAN_EDIT);
|
PhabricatorPolicyCapability::CAN_EDIT);
|
||||||
|
|
||||||
$can_fork = $viewer->isLoggedIn();
|
$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())
|
return id(new PhabricatorActionListView())
|
||||||
->setUser($viewer)
|
->setUser($viewer)
|
||||||
|
@ -160,7 +152,7 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
||||||
->setIcon('fa-pencil')
|
->setIcon('fa-pencil')
|
||||||
->setDisabled(!$can_edit)
|
->setDisabled(!$can_edit)
|
||||||
->setWorkflow(!$can_edit)
|
->setWorkflow(!$can_edit)
|
||||||
->setHref($this->getApplicationURI('/edit/'.$paste->getID().'/')))
|
->setHref($this->getApplicationURI("edit/{$id}/")))
|
||||||
->addAction(
|
->addAction(
|
||||||
id(new PhabricatorActionView())
|
id(new PhabricatorActionView())
|
||||||
->setName(pht('Fork This Paste'))
|
->setName(pht('Fork This Paste'))
|
||||||
|
@ -172,7 +164,7 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
||||||
id(new PhabricatorActionView())
|
id(new PhabricatorActionView())
|
||||||
->setName(pht('View Raw File'))
|
->setName(pht('View Raw File'))
|
||||||
->setIcon('fa-file-text-o')
|
->setIcon('fa-file-text-o')
|
||||||
->setHref($file->getBestURI()));
|
->setHref($this->getApplicationURI("raw/{$id}/")));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildPropertyView(
|
private function buildPropertyView(
|
||||||
|
|
Loading…
Reference in a new issue