Make "public" pastes meaningfully visible to logged-out users
Summary: - Introduce `shouldAllowPublic()`, indicating that logged-out users are OK in a controller if the install is configured to permit public policies. - Make Paste views and lists allow public users. - Make UI do sensible things with respect to disabling links, etc. - Improve behavior of "you need to login" with respect to policy exceptions and Ajax requests. Test Plan: Looked at "public" paste, saw all unavailable UI disabled, clicked it, got appropraite prompts. Reviewers: vrana, btrahan Reviewed By: vrana CC: aran Maniphest Tasks: T603 Differential Revision: https://secure.phabricator.com/D3502
This commit is contained in:
@@ -50,7 +50,6 @@ abstract class AphrontController {
|
|||||||
return $controller->processRequest();
|
return $controller->processRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
final public function setCurrentApplication(
|
final public function setCurrentApplication(
|
||||||
PhabricatorApplication $current_application) {
|
PhabricatorApplication $current_application) {
|
||||||
|
|
||||||
|
|||||||
@@ -336,6 +336,18 @@ class AphrontDefaultApplicationConfiguration
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($ex instanceof PhabricatorPolicyException) {
|
if ($ex instanceof PhabricatorPolicyException) {
|
||||||
|
|
||||||
|
if (!$user->isLoggedIn()) {
|
||||||
|
// If the user isn't logged in, just give them a login form. This is
|
||||||
|
// probably a generally more useful response than a policy dialog that
|
||||||
|
// they have to click through to get a login form.
|
||||||
|
//
|
||||||
|
// Possibly we should add a header here like "you need to login to see
|
||||||
|
// the thing you are trying to look at".
|
||||||
|
$login_controller = new PhabricatorLoginController($request);
|
||||||
|
return $login_controller->processRequest();
|
||||||
|
}
|
||||||
|
|
||||||
$content =
|
$content =
|
||||||
'<div class="aphront-policy-exception">'.
|
'<div class="aphront-policy-exception">'.
|
||||||
phutil_escape_html($ex->getMessage()).
|
phutil_escape_html($ex->getMessage()).
|
||||||
|
|||||||
@@ -25,12 +25,33 @@ final class PhabricatorLoginController
|
|||||||
|
|
||||||
public function processRequest() {
|
public function processRequest() {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
$user = $request->getUser();
|
||||||
|
|
||||||
if ($request->getUser()->getPHID()) {
|
if ($user->isLoggedIn()) {
|
||||||
// Kick the user out if they're already logged in.
|
// Kick the user out if they're already logged in.
|
||||||
return id(new AphrontRedirectResponse())->setURI('/');
|
return id(new AphrontRedirectResponse())->setURI('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($request->isAjax()) {
|
||||||
|
|
||||||
|
// We end up here if the user clicks a workflow link that they need to
|
||||||
|
// login to use. We give them a dialog saying "You need to login..".
|
||||||
|
|
||||||
|
if ($request->isDialogFormPost()) {
|
||||||
|
return id(new AphrontRedirectResponse())->setURI(
|
||||||
|
$request->getRequestURI());
|
||||||
|
}
|
||||||
|
|
||||||
|
$dialog = new AphrontDialogView();
|
||||||
|
$dialog->setUser($user);
|
||||||
|
$dialog->setTitle('Login Required');
|
||||||
|
$dialog->appendChild('<p>You must login to continue.</p>');
|
||||||
|
$dialog->addSubmitButton('Login');
|
||||||
|
$dialog->addCancelButton('/', 'Cancel');
|
||||||
|
|
||||||
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
||||||
|
}
|
||||||
|
|
||||||
if ($request->isConduit()) {
|
if ($request->isConduit()) {
|
||||||
|
|
||||||
// A common source of errors in Conduit client configuration is getting
|
// A common source of errors in Conduit client configuration is getting
|
||||||
|
|||||||
@@ -21,6 +21,14 @@ abstract class PhabricatorController extends AphrontController {
|
|||||||
private $handles;
|
private $handles;
|
||||||
|
|
||||||
public function shouldRequireLogin() {
|
public function shouldRequireLogin() {
|
||||||
|
|
||||||
|
// If this install is configured to allow public resources and the
|
||||||
|
// controller works in public mode, allow the request through.
|
||||||
|
$is_public_allowed = PhabricatorEnv::getEnvConfig('policy.allow-public');
|
||||||
|
if ($is_public_allowed && $this->shouldAllowPublic()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,6 +40,10 @@ abstract class PhabricatorController extends AphrontController {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function shouldAllowPublic() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public function shouldRequireEmailVerification() {
|
public function shouldRequireEmailVerification() {
|
||||||
$need_verify = PhabricatorUserEmail::isEmailVerificationRequired();
|
$need_verify = PhabricatorUserEmail::isEmailVerificationRequired();
|
||||||
$need_login = $this->shouldRequireLogin();
|
$need_login = $this->shouldRequireLogin();
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
abstract class PhabricatorPasteController extends PhabricatorController {
|
abstract class PhabricatorPasteController extends PhabricatorController {
|
||||||
|
|
||||||
public function buildSideNavView(PhabricatorPaste $paste = null) {
|
public function buildSideNavView(PhabricatorPaste $paste = null) {
|
||||||
|
$user = $this->getRequest()->getUser();
|
||||||
|
|
||||||
$nav = new AphrontSideNavFilterView();
|
$nav = new AphrontSideNavFilterView();
|
||||||
$nav->setBaseURI(new PhutilURI($this->getApplicationURI('filter/')));
|
$nav->setBaseURI(new PhutilURI($this->getApplicationURI('filter/')));
|
||||||
|
|
||||||
@@ -28,11 +30,18 @@ abstract class PhabricatorPasteController extends PhabricatorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$nav->addLabel('Create');
|
$nav->addLabel('Create');
|
||||||
$nav->addFilter('edit', 'New Paste', $this->getApplicationURI());
|
$nav->addFilter(
|
||||||
|
'edit',
|
||||||
|
'New Paste',
|
||||||
|
$this->getApplicationURI(),
|
||||||
|
$relative = false,
|
||||||
|
$class = ($user->isLoggedIn() ? null : 'disabled'));
|
||||||
|
|
||||||
$nav->addSpacer();
|
$nav->addSpacer();
|
||||||
$nav->addLabel('Pastes');
|
$nav->addLabel('Pastes');
|
||||||
|
if ($user->isLoggedIn()) {
|
||||||
$nav->addFilter('my', 'My Pastes');
|
$nav->addFilter('my', 'My Pastes');
|
||||||
|
}
|
||||||
$nav->addFilter('all', 'All Pastes');
|
$nav->addFilter('all', 'All Pastes');
|
||||||
|
|
||||||
return $nav;
|
return $nav;
|
||||||
|
|||||||
@@ -18,6 +18,10 @@
|
|||||||
|
|
||||||
final class PhabricatorPasteListController extends PhabricatorPasteController {
|
final class PhabricatorPasteListController extends PhabricatorPasteController {
|
||||||
|
|
||||||
|
public function shouldRequireLogin() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private $filter;
|
private $filter;
|
||||||
|
|
||||||
public function willProcessRequest(array $data) {
|
public function willProcessRequest(array $data) {
|
||||||
|
|||||||
@@ -18,6 +18,10 @@
|
|||||||
|
|
||||||
final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
||||||
|
|
||||||
|
public function shouldAllowPublic() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private $id;
|
private $id;
|
||||||
private $handles;
|
private $handles;
|
||||||
|
|
||||||
@@ -98,6 +102,8 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
|||||||
$paste,
|
$paste,
|
||||||
PhabricatorPolicyCapability::CAN_EDIT);
|
PhabricatorPolicyCapability::CAN_EDIT);
|
||||||
|
|
||||||
|
$can_fork = $user->isLoggedIn();
|
||||||
|
|
||||||
return id(new PhabricatorActionListView())
|
return id(new PhabricatorActionListView())
|
||||||
->setUser($user)
|
->setUser($user)
|
||||||
->setObject($paste)
|
->setObject($paste)
|
||||||
@@ -105,6 +111,8 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
|||||||
id(new PhabricatorActionView())
|
id(new PhabricatorActionView())
|
||||||
->setName(pht('Fork This Paste'))
|
->setName(pht('Fork This Paste'))
|
||||||
->setIcon('fork')
|
->setIcon('fork')
|
||||||
|
->setDisabled(!$can_fork)
|
||||||
|
->setWorkflow(!$can_fork)
|
||||||
->setHref($this->getApplicationURI('?parent='.$paste->getID())))
|
->setHref($this->getApplicationURI('?parent='.$paste->getID())))
|
||||||
->addAction(
|
->addAction(
|
||||||
id(new PhabricatorActionView())
|
id(new PhabricatorActionView())
|
||||||
|
|||||||
Reference in New Issue
Block a user