diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index a1361b26d7..c21038f3ee 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2625,6 +2625,7 @@ phutil_register_library_map(array( '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 @@ phutil_register_library_map(array( '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 index c0cf1bf86d..56912b0db5 100644 --- a/src/applications/phurl/application/PhabricatorPhurlApplication.php +++ b/src/applications/phurl/application/PhabricatorPhurlApplication.php @@ -29,6 +29,7 @@ final class PhabricatorPhurlApplication extends PhabricatorApplication { public function getRoutes() { return array( '/U(?P[1-9]\d*)' => 'PhabricatorPhurlURLViewController', + '/u/(?P[1-9]\d*)' => 'PhabricatorPhurlURLAccessController', '/phurl/' => array( '(?:query/(?P[^/]+)/)?' => 'PhabricatorPhurlURLListController', diff --git a/src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php b/src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php new file mode 100644 index 0000000000..8c005a90b9 --- /dev/null +++ b/src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php @@ -0,0 +1,28 @@ +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 index 1ddc2a8344..00ab160c1a 100644 --- a/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php +++ b/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php @@ -96,18 +96,6 @@ final class PhabricatorPhurlURLViewController $url, PhabricatorPolicyCapability::CAN_EDIT); - $allowed_protocols = PhabricatorEnv::getEnvConfig('uri.allowed-protocols'); - $uri = new PhutilURI($url->getLongURL()); - $url_protocol = $uri->getProtocol(); - - $can_access = false; - $redirect_uri = $url->getMonogram(); - - if (strlen($url_protocol)) { - $can_access = in_array($url_protocol, $allowed_protocols); - $redirect_uri = $uri; - } - $actions ->addAction( id(new PhabricatorActionView()) @@ -120,9 +108,8 @@ final class PhabricatorPhurlURLViewController id(new PhabricatorActionView()) ->setName(pht('Visit URL')) ->setIcon('fa-external-link') - ->setHref($redirect_uri) - ->setDisabled(!$can_edit || !$can_access) - ->setWorkflow(!$can_edit)); + ->setHref("u/{$id}") + ->setDisabled(!$url->isValid())); return $actions; } diff --git a/src/applications/phurl/storage/PhabricatorPhurlURL.php b/src/applications/phurl/storage/PhabricatorPhurlURL.php index e59aea63fa..35c5382d52 100644 --- a/src/applications/phurl/storage/PhabricatorPhurlURL.php +++ b/src/applications/phurl/storage/PhabricatorPhurlURL.php @@ -72,6 +72,13 @@ final class PhabricatorPhurlURL extends PhabricatorPhurlDAO return $uri; } + public function isValid() { + $allowed_protocols = PhabricatorEnv::getEnvConfig('uri.allowed-protocols'); + $uri = new PhutilURI($this->getLongURL()); + + return isset($allowed_protocols[$uri->getProtocol()]); + } + /* -( PhabricatorPolicyInterface )----------------------------------------- */