@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Ref T8989, Phurl "Visit URL" link should route through a separate controller.

Summary: Ref T8989, Phurl "Visit URL" should now route to an access controller that decides if the URL is valid whether to open it, or redirect back to Phurl object. New route is `local.install.com/u/1` to open link.

Test Plan:
- open Phurl object with invalid URL, "Visit URL" link should redirect back to object
- open Phurl object with valid URL, "Visit URL" link should open the link
- open `local.install.com/u/1` for `U1` with valid URL should open the link
- open `local.install.com/u/1` for `U1` with invalid URL should redirect to `local.install.com/U1`

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: joshuaspence, Korvin

Maniphest Tasks: T8989

Differential Revision: https://secure.phabricator.com/D14381

+40 -15
+2
src/__phutil_library_map__.php
··· 2625 2625 'PhabricatorPhurlDAO' => 'applications/phurl/storage/PhabricatorPhurlDAO.php', 2626 2626 'PhabricatorPhurlSchemaSpec' => 'applications/phurl/storage/PhabricatorPhurlSchemaSpec.php', 2627 2627 'PhabricatorPhurlURL' => 'applications/phurl/storage/PhabricatorPhurlURL.php', 2628 + 'PhabricatorPhurlURLAccessController' => 'applications/phurl/controller/PhabricatorPhurlURLAccessController.php', 2628 2629 'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php', 2629 2630 'PhabricatorPhurlURLEditor' => 'applications/phurl/editor/PhabricatorPhurlURLEditor.php', 2630 2631 'PhabricatorPhurlURLListController' => 'applications/phurl/controller/PhabricatorPhurlURLListController.php', ··· 6727 6728 'PhabricatorFlaggableInterface', 6728 6729 'PhabricatorSpacesInterface', 6729 6730 ), 6731 + 'PhabricatorPhurlURLAccessController' => 'PhabricatorPhurlController', 6730 6732 'PhabricatorPhurlURLEditController' => 'PhabricatorPhurlController', 6731 6733 'PhabricatorPhurlURLEditor' => 'PhabricatorApplicationTransactionEditor', 6732 6734 'PhabricatorPhurlURLListController' => 'PhabricatorPhurlController',
+1
src/applications/phurl/application/PhabricatorPhurlApplication.php
··· 29 29 public function getRoutes() { 30 30 return array( 31 31 '/U(?P<id>[1-9]\d*)' => 'PhabricatorPhurlURLViewController', 32 + '/u/(?P<id>[1-9]\d*)' => 'PhabricatorPhurlURLAccessController', 32 33 '/phurl/' => array( 33 34 '(?:query/(?P<queryKey>[^/]+)/)?' 34 35 => 'PhabricatorPhurlURLListController',
+28
src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php
··· 1 + <?php 2 + 3 + final class PhabricatorPhurlURLAccessController 4 + extends PhabricatorPhurlController { 5 + 6 + public function handleRequest(AphrontRequest $request) { 7 + $viewer = $this->getViewer(); 8 + $id = $request->getURIData('id'); 9 + 10 + $url = id(new PhabricatorPhurlURLQuery()) 11 + ->setViewer($viewer) 12 + ->withIDs(array($id)) 13 + ->executeOne(); 14 + 15 + if (!$url) { 16 + return new Aphront404Response(); 17 + } 18 + 19 + if ($url->isValid()) { 20 + return id(new AphrontRedirectResponse()) 21 + ->setURI($url->getLongURL()) 22 + ->setIsExternal(true); 23 + } else { 24 + return id(new AphrontRedirectResponse())->setURI('/'.$url->getMonogram()); 25 + } 26 + } 27 + 28 + }
+2 -15
src/applications/phurl/controller/PhabricatorPhurlURLViewController.php
··· 96 96 $url, 97 97 PhabricatorPolicyCapability::CAN_EDIT); 98 98 99 - $allowed_protocols = PhabricatorEnv::getEnvConfig('uri.allowed-protocols'); 100 - $uri = new PhutilURI($url->getLongURL()); 101 - $url_protocol = $uri->getProtocol(); 102 - 103 - $can_access = false; 104 - $redirect_uri = $url->getMonogram(); 105 - 106 - if (strlen($url_protocol)) { 107 - $can_access = in_array($url_protocol, $allowed_protocols); 108 - $redirect_uri = $uri; 109 - } 110 - 111 99 $actions 112 100 ->addAction( 113 101 id(new PhabricatorActionView()) ··· 120 108 id(new PhabricatorActionView()) 121 109 ->setName(pht('Visit URL')) 122 110 ->setIcon('fa-external-link') 123 - ->setHref($redirect_uri) 124 - ->setDisabled(!$can_edit || !$can_access) 125 - ->setWorkflow(!$can_edit)); 111 + ->setHref("u/{$id}") 112 + ->setDisabled(!$url->isValid())); 126 113 127 114 return $actions; 128 115 }
+7
src/applications/phurl/storage/PhabricatorPhurlURL.php
··· 72 72 return $uri; 73 73 } 74 74 75 + public function isValid() { 76 + $allowed_protocols = PhabricatorEnv::getEnvConfig('uri.allowed-protocols'); 77 + $uri = new PhutilURI($this->getLongURL()); 78 + 79 + return isset($allowed_protocols[$uri->getProtocol()]); 80 + } 81 + 75 82 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 76 83 77 84