Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14031440
D14381.id34739.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D14381.id34739.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2625,6 +2625,7 @@
'PhabricatorPhurlDAO' => 'applications/phurl/storage/PhabricatorPhurlDAO.php',
'PhabricatorPhurlSchemaSpec' => 'applications/phurl/storage/PhabricatorPhurlSchemaSpec.php',
'PhabricatorPhurlURL' => 'applications/phurl/storage/PhabricatorPhurlURL.php',
+ 'PhabricatorPhurlURLAccessController' => 'applications/phurl/controller/PhabricatorPhurlURLAccessController.php',
'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php',
'PhabricatorPhurlURLEditor' => 'applications/phurl/editor/PhabricatorPhurlURLEditor.php',
'PhabricatorPhurlURLListController' => 'applications/phurl/controller/PhabricatorPhurlURLListController.php',
@@ -6727,6 +6728,7 @@
'PhabricatorFlaggableInterface',
'PhabricatorSpacesInterface',
),
+ 'PhabricatorPhurlURLAccessController' => 'PhabricatorPhurlController',
'PhabricatorPhurlURLEditController' => 'PhabricatorPhurlController',
'PhabricatorPhurlURLEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorPhurlURLListController' => 'PhabricatorPhurlController',
diff --git a/src/applications/phurl/application/PhabricatorPhurlApplication.php b/src/applications/phurl/application/PhabricatorPhurlApplication.php
--- a/src/applications/phurl/application/PhabricatorPhurlApplication.php
+++ b/src/applications/phurl/application/PhabricatorPhurlApplication.php
@@ -29,6 +29,7 @@
public function getRoutes() {
return array(
'/U(?P<id>[1-9]\d*)' => 'PhabricatorPhurlURLViewController',
+ '/u/(?P<id>[1-9]\d*)' => 'PhabricatorPhurlURLAccessController',
'/phurl/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PhabricatorPhurlURLListController',
diff --git a/src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php b/src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php
@@ -0,0 +1,28 @@
+<?php
+
+final class PhabricatorPhurlURLAccessController
+ extends PhabricatorPhurlController {
+
+ public function handleRequest(AphrontRequest $request) {
+ $viewer = $this->getViewer();
+ $id = $request->getURIData('id');
+
+ $url = id(new PhabricatorPhurlURLQuery())
+ ->setViewer($viewer)
+ ->withIDs(array($id))
+ ->executeOne();
+
+ if (!$url) {
+ return new Aphront404Response();
+ }
+
+ if ($url->isValid()) {
+ return id(new AphrontRedirectResponse())
+ ->setURI($url->getLongURL())
+ ->setIsExternal(true);
+ } else {
+ return id(new AphrontRedirectResponse())->setURI('/'.$url->getMonogram());
+ }
+ }
+
+}
diff --git a/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php b/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php
--- a/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php
+++ b/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php
@@ -96,13 +96,25 @@
$url,
PhabricatorPolicyCapability::CAN_EDIT);
- $actions->addAction(
- id(new PhabricatorActionView())
- ->setName(pht('Edit'))
- ->setIcon('fa-pencil')
- ->setHref($this->getApplicationURI("url/edit/{$id}/"))
- ->setDisabled(!$can_edit)
- ->setWorkflow(!$can_edit));
+ $can_view = PhabricatorPolicyFilter::hasCapability(
+ $viewer,
+ $url,
+ PhabricatorPolicyCapability::CAN_VIEW);
+
+ $actions
+ ->addAction(
+ id(new PhabricatorActionView())
+ ->setName(pht('Edit'))
+ ->setIcon('fa-pencil')
+ ->setHref($this->getApplicationURI("url/edit/{$id}/"))
+ ->setDisabled(!$can_edit)
+ ->setWorkflow(!$can_edit))
+ ->addAction(
+ id(new PhabricatorActionView())
+ ->setName(pht('Visit URL'))
+ ->setIcon('fa-external-link')
+ ->setHref("u/{$id}")
+ ->setDisabled(!$url->isValid()));
return $actions;
}
diff --git a/src/applications/phurl/storage/PhabricatorPhurlURL.php b/src/applications/phurl/storage/PhabricatorPhurlURL.php
--- a/src/applications/phurl/storage/PhabricatorPhurlURL.php
+++ b/src/applications/phurl/storage/PhabricatorPhurlURL.php
@@ -72,6 +72,13 @@
return $uri;
}
+ public function isValid() {
+ $allowed_protocols = PhabricatorEnv::getEnvConfig('uri.allowed-protocols');
+ $uri = new PhutilURI($this->getLongURL());
+
+ return isset($allowed_protocols[$uri->getProtocol()]);
+ }
+
/* -( PhabricatorPolicyInterface )----------------------------------------- */
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 10, 10:30 AM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6764120
Default Alt Text
D14381.id34739.diff (4 KB)
Attached To
Mode
D14381: Ref T8989, Phurl "Visit URL" link should route through a separate controller.
Attached
Detach File
Event Timeline
Log In to Comment