1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +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:
Marek Sapota 2011-10-24 12:27:16 -07:00
parent 0778f35272
commit 789dc6cb5e
8 changed files with 197 additions and 134 deletions

View file

@ -570,6 +570,11 @@ return array(
// not actually be receiving thorough review.
'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 ------------------------------------------------------------- //

View file

@ -18,10 +18,16 @@
abstract class DifferentialController extends PhabricatorController {
protected function allowsAnonymousAccess() {
return PhabricatorEnv::getEnvConfig('differential.anonymous-access');
}
public function buildStandardPageResponse($view, array $data) {
require_celerity_resource('differential-core-view-css');
$viewer_is_anonymous = !$this->getRequest()->getUser()->isLoggedIn();
$page = $this->buildStandardPageView();
$page->setApplicationName('Differential');
@ -29,18 +35,22 @@ abstract class DifferentialController extends PhabricatorController {
$page->setTitle(idx($data, 'title'));
$page->setGlyph("\xE2\x9A\x99");
$page->appendChild($view);
$page->setTabs(
array(
$tabs = array(
'revisions' => array(
'name' => 'Revisions',
'href' => '/differential/',
),
)
);
if (!$viewer_is_anonymous) {
$tabs = array_merge($tabs, array(
'create' => array(
'name' => 'Create Diff',
'href' => '/differential/diff/create/',
),
),
idx($data, 'tab'));
)
));
}
$page->setTabs($tabs, idx($data, 'tab'));
$page->setIsLoggedOut($viewer_is_anonymous);
$response = new AphrontWebpageResponse();
return $response->setContent($page->render());

View file

@ -9,6 +9,7 @@
phutil_require_module('phabricator', 'aphront/response/webpage');
phutil_require_module('phabricator', 'applications/base/controller/base');
phutil_require_module('phabricator', 'infrastructure/celerity/api');
phutil_require_module('phabricator', 'infrastructure/env');
phutil_require_module('phutil', 'utils');

View file

@ -19,6 +19,10 @@
class DifferentialChangesetViewController extends DifferentialController {
public function shouldRequireLogin() {
return !$this->allowsAnonymousAccess();
}
public function processRequest() {
$request = $this->getRequest();

View file

@ -20,6 +20,10 @@ class DifferentialRevisionListController extends DifferentialController {
private $filter;
public function shouldRequireLogin() {
return !$this->allowsAnonymousAccess();
}
public function willProcessRequest(array $data) {
$this->filter = idx($data, 'filter');
}
@ -27,6 +31,7 @@ class DifferentialRevisionListController extends DifferentialController {
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$viewer_is_anonymous = !$user->isLoggedIn();
if ($request->isFormPost()) {
$phid_arr = $request->getArr('view_user');
@ -35,6 +40,8 @@ class DifferentialRevisionListController extends DifferentialController {
->setURI($request->getRequestURI()->alter('phid', $view_target));
}
$filters = array();
if (!$viewer_is_anonymous) {
$filters = array(
'User Revisions',
'active' => array(
@ -100,7 +107,10 @@ class DifferentialRevisionListController extends DifferentialController {
),
),
),
'<hr />',
'<hr />'
);
}
$filters = array_merge($filters, array(
'All Revisions',
'allopen' => array(
'name' => 'Open',
@ -112,10 +122,14 @@ class DifferentialRevisionListController extends DifferentialController {
),
),
),
);
));
if (empty($filters[$this->filter])) {
if (!$viewer_is_anonymous) {
$this->filter = 'active';
} else {
$this->filter = 'allopen';
}
}
$view_phid = nonempty($request->getStr('phid'), $user->getPHID());

View file

@ -20,6 +20,10 @@ class DifferentialRevisionViewController extends DifferentialController {
private $revisionID;
public function shouldRequireLogin() {
return !$this->allowsAnonymousAccess();
}
public function willProcessRequest(array $data) {
$this->revisionID = $data['id'];
}
@ -28,6 +32,7 @@ class DifferentialRevisionViewController extends DifferentialController {
$request = $this->getRequest();
$user = $request->getUser();
$viewer_is_anonymous = !$user->isLoggedIn();
$revision = id(new DifferentialRevision())->load($this->revisionID);
if (!$revision) {
@ -197,7 +202,7 @@ class DifferentialRevisionViewController extends DifferentialController {
$changeset_view = new DifferentialChangesetListView();
$changeset_view->setChangesets($visible_changesets);
$changeset_view->setEditable(true);
$changeset_view->setEditable(!$viewer_is_anonymous);
$changeset_view->setStandaloneViews(true);
$changeset_view->setRevision($revision);
$changeset_view->setRenderingReferences($rendering_references);
@ -221,6 +226,7 @@ class DifferentialRevisionViewController extends DifferentialController {
$toc_view->setRevisionID($revision->getID());
$toc_view->setWhitespace($whitespace);
if (!$viewer_is_anonymous) {
$draft = id(new PhabricatorDraft())->loadOneWhere(
'authorPHID = %s AND draftKey = %s',
$user->getPHID(),
@ -239,6 +245,7 @@ class DifferentialRevisionViewController extends DifferentialController {
$comment_form->setDraft($draft);
$this->updateViewTime($user->getPHID(), $revision->getPHID());
}
$pane_id = celerity_generate_unique_node_id();
Javelin::initBehavior(
@ -247,8 +254,7 @@ class DifferentialRevisionViewController extends DifferentialController {
'haunt' => $pane_id,
));
return $this->buildStandardPageResponse(
id(new DifferentialPrimaryPaneView())
$page_pane = id(new DifferentialPrimaryPaneView())
->setLineWidthFromChangesets($changesets)
->setID($pane_id)
->appendChild(
@ -258,8 +264,12 @@ class DifferentialRevisionViewController extends DifferentialController {
$warning.
$local_view->render().
$toc_view->render().
$changeset_view->render().
$comment_form->render()),
$changeset_view->render());
if ($comment_form) {
$page_pane->appendChild($comment_form->render());
}
return $this->buildStandardPageResponse(
$page_pane,
array(
'title' => 'D'.$revision->getID().' '.$revision->getTitle(),
));
@ -296,6 +306,7 @@ class DifferentialRevisionViewController extends DifferentialController {
$viewer_is_owner = ($revision->getAuthorPHID() == $viewer_phid);
$viewer_is_reviewer = in_array($viewer_phid, $revision->getReviewers());
$viewer_is_cc = in_array($viewer_phid, $revision->getCCPHIDs());
$viewer_is_anonymous = !$this->getRequest()->getUser()->isLoggedIn();
$status = $revision->getStatus();
$revision_id = $revision->getID();
$revision_phid = $revision->getPHID();
@ -310,6 +321,7 @@ class DifferentialRevisionViewController extends DifferentialController {
);
}
if (!$viewer_is_anonymous) {
if (!$viewer_is_owner && !$viewer_is_reviewer) {
$action = $viewer_is_cc ? 'rem' : 'add';
$links[] = array(
@ -355,6 +367,7 @@ class DifferentialRevisionViewController extends DifferentialController {
'name' => 'Herald Transcripts',
'href' => "/herald/transcript/?phid={$revision_phid}",
);
}
return $links;
}

View file

@ -86,6 +86,10 @@ class PhabricatorUser extends PhabricatorUserDAO {
return $this;
}
public function isLoggedIn() {
return !($this->getPHID() === null);
}
public function save() {
if (!$this->getConduitCertificate()) {
$this->setConduitCertificate($this->generateConduitCertificate());

View file

@ -35,6 +35,18 @@ class PhabricatorStandardPageView extends AphrontPageView {
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() {
return $this->isAdminInterface;
}