mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Allow anonymus access to Differential.
Summary: Add possibility for not logged in users to browse and see Differential revisions. Test Plan: Set 'differential.anonymous-access' config option to true, log out, you should be able to browse Differential without logging back in. Reviewers: epriestley, jungejason Reviewed By: epriestley CC: aran, epriestley, mareksapota Differential Revision: 1044
This commit is contained in:
parent
0778f35272
commit
789dc6cb5e
8 changed files with 197 additions and 134 deletions
|
@ -570,6 +570,11 @@ return array(
|
||||||
// not actually be receiving thorough review.
|
// not actually be receiving thorough review.
|
||||||
'differential.enable-email-accept' => false,
|
'differential.enable-email-accept' => false,
|
||||||
|
|
||||||
|
// If you set this to true, users won't need to login to view differential
|
||||||
|
// revisions. Anonymous users will have read-only access and won't be able to
|
||||||
|
// interact with the revisions.
|
||||||
|
'differential.anonymous-access' => false,
|
||||||
|
|
||||||
|
|
||||||
// -- Maniphest ------------------------------------------------------------- //
|
// -- Maniphest ------------------------------------------------------------- //
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,16 @@
|
||||||
|
|
||||||
abstract class DifferentialController extends PhabricatorController {
|
abstract class DifferentialController extends PhabricatorController {
|
||||||
|
|
||||||
|
protected function allowsAnonymousAccess() {
|
||||||
|
return PhabricatorEnv::getEnvConfig('differential.anonymous-access');
|
||||||
|
}
|
||||||
|
|
||||||
public function buildStandardPageResponse($view, array $data) {
|
public function buildStandardPageResponse($view, array $data) {
|
||||||
|
|
||||||
require_celerity_resource('differential-core-view-css');
|
require_celerity_resource('differential-core-view-css');
|
||||||
|
|
||||||
|
$viewer_is_anonymous = !$this->getRequest()->getUser()->isLoggedIn();
|
||||||
|
|
||||||
$page = $this->buildStandardPageView();
|
$page = $this->buildStandardPageView();
|
||||||
|
|
||||||
$page->setApplicationName('Differential');
|
$page->setApplicationName('Differential');
|
||||||
|
@ -29,18 +35,22 @@ abstract class DifferentialController extends PhabricatorController {
|
||||||
$page->setTitle(idx($data, 'title'));
|
$page->setTitle(idx($data, 'title'));
|
||||||
$page->setGlyph("\xE2\x9A\x99");
|
$page->setGlyph("\xE2\x9A\x99");
|
||||||
$page->appendChild($view);
|
$page->appendChild($view);
|
||||||
$page->setTabs(
|
$tabs = array(
|
||||||
array(
|
|
||||||
'revisions' => array(
|
'revisions' => array(
|
||||||
'name' => 'Revisions',
|
'name' => 'Revisions',
|
||||||
'href' => '/differential/',
|
'href' => '/differential/',
|
||||||
),
|
)
|
||||||
|
);
|
||||||
|
if (!$viewer_is_anonymous) {
|
||||||
|
$tabs = array_merge($tabs, array(
|
||||||
'create' => array(
|
'create' => array(
|
||||||
'name' => 'Create Diff',
|
'name' => 'Create Diff',
|
||||||
'href' => '/differential/diff/create/',
|
'href' => '/differential/diff/create/',
|
||||||
),
|
)
|
||||||
),
|
));
|
||||||
idx($data, 'tab'));
|
}
|
||||||
|
$page->setTabs($tabs, idx($data, 'tab'));
|
||||||
|
$page->setIsLoggedOut($viewer_is_anonymous);
|
||||||
|
|
||||||
$response = new AphrontWebpageResponse();
|
$response = new AphrontWebpageResponse();
|
||||||
return $response->setContent($page->render());
|
return $response->setContent($page->render());
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
phutil_require_module('phabricator', 'aphront/response/webpage');
|
phutil_require_module('phabricator', 'aphront/response/webpage');
|
||||||
phutil_require_module('phabricator', 'applications/base/controller/base');
|
phutil_require_module('phabricator', 'applications/base/controller/base');
|
||||||
phutil_require_module('phabricator', 'infrastructure/celerity/api');
|
phutil_require_module('phabricator', 'infrastructure/celerity/api');
|
||||||
|
phutil_require_module('phabricator', 'infrastructure/env');
|
||||||
|
|
||||||
phutil_require_module('phutil', 'utils');
|
phutil_require_module('phutil', 'utils');
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,10 @@
|
||||||
class DifferentialChangesetViewController extends DifferentialController {
|
class DifferentialChangesetViewController extends DifferentialController {
|
||||||
|
|
||||||
|
|
||||||
|
public function shouldRequireLogin() {
|
||||||
|
return !$this->allowsAnonymousAccess();
|
||||||
|
}
|
||||||
|
|
||||||
public function processRequest() {
|
public function processRequest() {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,10 @@ class DifferentialRevisionListController extends DifferentialController {
|
||||||
|
|
||||||
private $filter;
|
private $filter;
|
||||||
|
|
||||||
|
public function shouldRequireLogin() {
|
||||||
|
return !$this->allowsAnonymousAccess();
|
||||||
|
}
|
||||||
|
|
||||||
public function willProcessRequest(array $data) {
|
public function willProcessRequest(array $data) {
|
||||||
$this->filter = idx($data, 'filter');
|
$this->filter = idx($data, 'filter');
|
||||||
}
|
}
|
||||||
|
@ -27,6 +31,7 @@ class DifferentialRevisionListController extends DifferentialController {
|
||||||
public function processRequest() {
|
public function processRequest() {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$user = $request->getUser();
|
||||||
|
$viewer_is_anonymous = !$user->isLoggedIn();
|
||||||
|
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
$phid_arr = $request->getArr('view_user');
|
$phid_arr = $request->getArr('view_user');
|
||||||
|
@ -35,6 +40,8 @@ class DifferentialRevisionListController extends DifferentialController {
|
||||||
->setURI($request->getRequestURI()->alter('phid', $view_target));
|
->setURI($request->getRequestURI()->alter('phid', $view_target));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$filters = array();
|
||||||
|
if (!$viewer_is_anonymous) {
|
||||||
$filters = array(
|
$filters = array(
|
||||||
'User Revisions',
|
'User Revisions',
|
||||||
'active' => array(
|
'active' => array(
|
||||||
|
@ -100,7 +107,10 @@ class DifferentialRevisionListController extends DifferentialController {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'<hr />',
|
'<hr />'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$filters = array_merge($filters, array(
|
||||||
'All Revisions',
|
'All Revisions',
|
||||||
'allopen' => array(
|
'allopen' => array(
|
||||||
'name' => 'Open',
|
'name' => 'Open',
|
||||||
|
@ -112,10 +122,14 @@ class DifferentialRevisionListController extends DifferentialController {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
|
|
||||||
if (empty($filters[$this->filter])) {
|
if (empty($filters[$this->filter])) {
|
||||||
|
if (!$viewer_is_anonymous) {
|
||||||
$this->filter = 'active';
|
$this->filter = 'active';
|
||||||
|
} else {
|
||||||
|
$this->filter = 'allopen';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$view_phid = nonempty($request->getStr('phid'), $user->getPHID());
|
$view_phid = nonempty($request->getStr('phid'), $user->getPHID());
|
||||||
|
|
|
@ -20,6 +20,10 @@ class DifferentialRevisionViewController extends DifferentialController {
|
||||||
|
|
||||||
private $revisionID;
|
private $revisionID;
|
||||||
|
|
||||||
|
public function shouldRequireLogin() {
|
||||||
|
return !$this->allowsAnonymousAccess();
|
||||||
|
}
|
||||||
|
|
||||||
public function willProcessRequest(array $data) {
|
public function willProcessRequest(array $data) {
|
||||||
$this->revisionID = $data['id'];
|
$this->revisionID = $data['id'];
|
||||||
}
|
}
|
||||||
|
@ -28,6 +32,7 @@ class DifferentialRevisionViewController extends DifferentialController {
|
||||||
|
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$user = $request->getUser();
|
||||||
|
$viewer_is_anonymous = !$user->isLoggedIn();
|
||||||
|
|
||||||
$revision = id(new DifferentialRevision())->load($this->revisionID);
|
$revision = id(new DifferentialRevision())->load($this->revisionID);
|
||||||
if (!$revision) {
|
if (!$revision) {
|
||||||
|
@ -197,7 +202,7 @@ class DifferentialRevisionViewController extends DifferentialController {
|
||||||
|
|
||||||
$changeset_view = new DifferentialChangesetListView();
|
$changeset_view = new DifferentialChangesetListView();
|
||||||
$changeset_view->setChangesets($visible_changesets);
|
$changeset_view->setChangesets($visible_changesets);
|
||||||
$changeset_view->setEditable(true);
|
$changeset_view->setEditable(!$viewer_is_anonymous);
|
||||||
$changeset_view->setStandaloneViews(true);
|
$changeset_view->setStandaloneViews(true);
|
||||||
$changeset_view->setRevision($revision);
|
$changeset_view->setRevision($revision);
|
||||||
$changeset_view->setRenderingReferences($rendering_references);
|
$changeset_view->setRenderingReferences($rendering_references);
|
||||||
|
@ -221,6 +226,7 @@ class DifferentialRevisionViewController extends DifferentialController {
|
||||||
$toc_view->setRevisionID($revision->getID());
|
$toc_view->setRevisionID($revision->getID());
|
||||||
$toc_view->setWhitespace($whitespace);
|
$toc_view->setWhitespace($whitespace);
|
||||||
|
|
||||||
|
if (!$viewer_is_anonymous) {
|
||||||
$draft = id(new PhabricatorDraft())->loadOneWhere(
|
$draft = id(new PhabricatorDraft())->loadOneWhere(
|
||||||
'authorPHID = %s AND draftKey = %s',
|
'authorPHID = %s AND draftKey = %s',
|
||||||
$user->getPHID(),
|
$user->getPHID(),
|
||||||
|
@ -239,6 +245,7 @@ class DifferentialRevisionViewController extends DifferentialController {
|
||||||
$comment_form->setDraft($draft);
|
$comment_form->setDraft($draft);
|
||||||
|
|
||||||
$this->updateViewTime($user->getPHID(), $revision->getPHID());
|
$this->updateViewTime($user->getPHID(), $revision->getPHID());
|
||||||
|
}
|
||||||
|
|
||||||
$pane_id = celerity_generate_unique_node_id();
|
$pane_id = celerity_generate_unique_node_id();
|
||||||
Javelin::initBehavior(
|
Javelin::initBehavior(
|
||||||
|
@ -247,8 +254,7 @@ class DifferentialRevisionViewController extends DifferentialController {
|
||||||
'haunt' => $pane_id,
|
'haunt' => $pane_id,
|
||||||
));
|
));
|
||||||
|
|
||||||
return $this->buildStandardPageResponse(
|
$page_pane = id(new DifferentialPrimaryPaneView())
|
||||||
id(new DifferentialPrimaryPaneView())
|
|
||||||
->setLineWidthFromChangesets($changesets)
|
->setLineWidthFromChangesets($changesets)
|
||||||
->setID($pane_id)
|
->setID($pane_id)
|
||||||
->appendChild(
|
->appendChild(
|
||||||
|
@ -258,8 +264,12 @@ class DifferentialRevisionViewController extends DifferentialController {
|
||||||
$warning.
|
$warning.
|
||||||
$local_view->render().
|
$local_view->render().
|
||||||
$toc_view->render().
|
$toc_view->render().
|
||||||
$changeset_view->render().
|
$changeset_view->render());
|
||||||
$comment_form->render()),
|
if ($comment_form) {
|
||||||
|
$page_pane->appendChild($comment_form->render());
|
||||||
|
}
|
||||||
|
return $this->buildStandardPageResponse(
|
||||||
|
$page_pane,
|
||||||
array(
|
array(
|
||||||
'title' => 'D'.$revision->getID().' '.$revision->getTitle(),
|
'title' => 'D'.$revision->getID().' '.$revision->getTitle(),
|
||||||
));
|
));
|
||||||
|
@ -296,6 +306,7 @@ class DifferentialRevisionViewController extends DifferentialController {
|
||||||
$viewer_is_owner = ($revision->getAuthorPHID() == $viewer_phid);
|
$viewer_is_owner = ($revision->getAuthorPHID() == $viewer_phid);
|
||||||
$viewer_is_reviewer = in_array($viewer_phid, $revision->getReviewers());
|
$viewer_is_reviewer = in_array($viewer_phid, $revision->getReviewers());
|
||||||
$viewer_is_cc = in_array($viewer_phid, $revision->getCCPHIDs());
|
$viewer_is_cc = in_array($viewer_phid, $revision->getCCPHIDs());
|
||||||
|
$viewer_is_anonymous = !$this->getRequest()->getUser()->isLoggedIn();
|
||||||
$status = $revision->getStatus();
|
$status = $revision->getStatus();
|
||||||
$revision_id = $revision->getID();
|
$revision_id = $revision->getID();
|
||||||
$revision_phid = $revision->getPHID();
|
$revision_phid = $revision->getPHID();
|
||||||
|
@ -310,6 +321,7 @@ class DifferentialRevisionViewController extends DifferentialController {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$viewer_is_anonymous) {
|
||||||
if (!$viewer_is_owner && !$viewer_is_reviewer) {
|
if (!$viewer_is_owner && !$viewer_is_reviewer) {
|
||||||
$action = $viewer_is_cc ? 'rem' : 'add';
|
$action = $viewer_is_cc ? 'rem' : 'add';
|
||||||
$links[] = array(
|
$links[] = array(
|
||||||
|
@ -355,6 +367,7 @@ class DifferentialRevisionViewController extends DifferentialController {
|
||||||
'name' => 'Herald Transcripts',
|
'name' => 'Herald Transcripts',
|
||||||
'href' => "/herald/transcript/?phid={$revision_phid}",
|
'href' => "/herald/transcript/?phid={$revision_phid}",
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return $links;
|
return $links;
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,10 @@ class PhabricatorUser extends PhabricatorUserDAO {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isLoggedIn() {
|
||||||
|
return !($this->getPHID() === null);
|
||||||
|
}
|
||||||
|
|
||||||
public function save() {
|
public function save() {
|
||||||
if (!$this->getConduitCertificate()) {
|
if (!$this->getConduitCertificate()) {
|
||||||
$this->setConduitCertificate($this->generateConduitCertificate());
|
$this->setConduitCertificate($this->generateConduitCertificate());
|
||||||
|
|
|
@ -35,6 +35,18 @@ class PhabricatorStandardPageView extends AphrontPageView {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setIsLoggedOut($is_logged_out) {
|
||||||
|
if ($is_logged_out) {
|
||||||
|
$this->tabs = array_merge($this->tabs, array(
|
||||||
|
'login' => array(
|
||||||
|
'name' => 'Login',
|
||||||
|
'href' => '/login/'
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function getIsAdminInterface() {
|
public function getIsAdminInterface() {
|
||||||
return $this->isAdminInterface;
|
return $this->isAdminInterface;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue