From 09d4ea884fe405b60f2f6fa6163cc326a6bd3663 Mon Sep 17 00:00:00 2001 From: lkassianik Date: Mon, 2 Nov 2015 16:40:56 +0000 Subject: [PATCH] Ref T8989, Add a "Visit URL" link to Phurl items. Summary: Ref T8989, Add a "Visit URL" link to Phurl items and make it actionable if the URI has a valid protocol. Test Plan: - Create a Phurl object with a URI of "google.com". - "Visit URL" action in action view should be greyed out. - Edit object to have URI "http://google.com" and save. "Visit URL" link should be available and should redirect to the intended URL. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: chad, Korvin Maniphest Tasks: T8989 Differential Revision: https://secure.phabricator.com/D14379 --- .../PhabricatorPhurlURLViewController.php | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php b/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php index 4483b9bb77..1ddc2a8344 100644 --- a/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php +++ b/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php @@ -96,13 +96,33 @@ final class PhabricatorPhurlURLViewController $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)); + $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()) + ->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($redirect_uri) + ->setDisabled(!$can_edit || !$can_access) + ->setWorkflow(!$can_edit)); return $actions; }