Skip to content

Commit 09d4ea8

Browse files
lkassianiklpriestley
authored andcommitted
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
1 parent 4e11253 commit 09d4ea8

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

src/applications/phurl/controller/PhabricatorPhurlURLViewController.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,33 @@ private function buildActionView(PhabricatorPhurlURL $url) {
9696
$url,
9797
PhabricatorPolicyCapability::CAN_EDIT);
9898

99-
$actions->addAction(
100-
id(new PhabricatorActionView())
101-
->setName(pht('Edit'))
102-
->setIcon('fa-pencil')
103-
->setHref($this->getApplicationURI("url/edit/{$id}/"))
104-
->setDisabled(!$can_edit)
105-
->setWorkflow(!$can_edit));
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+
$actions
112+
->addAction(
113+
id(new PhabricatorActionView())
114+
->setName(pht('Edit'))
115+
->setIcon('fa-pencil')
116+
->setHref($this->getApplicationURI("url/edit/{$id}/"))
117+
->setDisabled(!$can_edit)
118+
->setWorkflow(!$can_edit))
119+
->addAction(
120+
id(new PhabricatorActionView())
121+
->setName(pht('Visit URL'))
122+
->setIcon('fa-external-link')
123+
->setHref($redirect_uri)
124+
->setDisabled(!$can_edit || !$can_access)
125+
->setWorkflow(!$can_edit));
106126

107127
return $actions;
108128
}

0 commit comments

Comments
 (0)