1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 03:50:54 +01:00

Merge pull request #76 from mareksapota-fb/master

Pull request for differential revision D1044
This commit is contained in:
Evan Priestley 2011-10-25 10:43:42 -07:00
commit 9d4793b27f
8 changed files with 197 additions and 134 deletions

View file

@ -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 ------------------------------------------------------------- //

View file

@ -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());

View file

@ -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');

View file

@ -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();

View file

@ -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,72 +40,77 @@ class DifferentialRevisionListController extends DifferentialController {
->setURI($request->getRequestURI()->alter('phid', $view_target)); ->setURI($request->getRequestURI()->alter('phid', $view_target));
} }
$filters = array( $filters = array();
'User Revisions', if (!$viewer_is_anonymous) {
'active' => array( $filters = array(
'name' => 'Active Revisions', 'User Revisions',
'queries' => array( 'active' => array(
array( 'name' => 'Active Revisions',
'query' 'queries' => array(
=> DifferentialRevisionListData::QUERY_NEED_ACTION_FROM_SELF, array(
'header' => 'Action Required', 'query'
'nodata' => 'You have no revisions requiring action.', => DifferentialRevisionListData::QUERY_NEED_ACTION_FROM_SELF,
), 'header' => 'Action Required',
array( 'nodata' => 'You have no revisions requiring action.',
'query' ),
=> DifferentialRevisionListData::QUERY_NEED_ACTION_FROM_OTHERS, array(
'header' => 'Waiting on Others', 'query'
'nodata' => 'You have no revisions waiting on others', => DifferentialRevisionListData::QUERY_NEED_ACTION_FROM_OTHERS,
'header' => 'Waiting on Others',
'nodata' => 'You have no revisions waiting on others',
),
), ),
), ),
), 'open' => array(
'open' => array( 'name' => 'Open Revisions',
'name' => 'Open Revisions', 'queries' => array(
'queries' => array( array(
array( 'query' => DifferentialRevisionListData::QUERY_OPEN_OWNED,
'query' => DifferentialRevisionListData::QUERY_OPEN_OWNED, 'header' => 'Your Open Revisions',
'header' => 'Your Open Revisions', ),
), ),
), ),
), 'reviews' => array(
'reviews' => array( 'name' => 'Open Reviews',
'name' => 'Open Reviews', 'queries' => array(
'queries' => array( array(
array( 'query' => DifferentialRevisionListData::QUERY_OPEN_REVIEWER,
'query' => DifferentialRevisionListData::QUERY_OPEN_REVIEWER, 'header' => 'Your Open Reviews',
'header' => 'Your Open Reviews', ),
), ),
), ),
), 'all' => array(
'all' => array( 'name' => 'All Revisions',
'name' => 'All Revisions', 'queries' => array(
'queries' => array( array(
array( 'query' => DifferentialRevisionListData::QUERY_OWNED,
'query' => DifferentialRevisionListData::QUERY_OWNED, 'header' => 'Your Revisions',
'header' => 'Your Revisions', ),
), ),
), ),
), 'related' => array(
'related' => array( 'name' => 'All Revisions and Reviews',
'name' => 'All Revisions and Reviews', 'queries' => array(
'queries' => array( array(
array( 'query' => DifferentialRevisionListData::QUERY_OWNED_OR_REVIEWER,
'query' => DifferentialRevisionListData::QUERY_OWNED_OR_REVIEWER, 'header' => 'Your Revisions and Reviews',
'header' => 'Your Revisions and Reviews', ),
), ),
), ),
), 'updates' => array(
'updates' => array( 'name' => 'Updates',
'name' => 'Updates', 'queries' => array(
'queries' => array( array(
array( 'query' => DifferentialRevisionListData::QUERY_UPDATED_SINCE,
'query' => DifferentialRevisionListData::QUERY_UPDATED_SINCE, 'header' =>
'header' => 'Diffs that have been updated since you\'ve last viewed them',
'Diffs that have been updated since you\'ve last viewed them', ),
), ),
), ),
), '<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])) {
$this->filter = 'active'; if (!$viewer_is_anonymous) {
$this->filter = 'active';
} else {
$this->filter = 'allopen';
}
} }
$view_phid = nonempty($request->getStr('phid'), $user->getPHID()); $view_phid = nonempty($request->getStr('phid'), $user->getPHID());

View file

@ -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,25 +226,27 @@ class DifferentialRevisionViewController extends DifferentialController {
$toc_view->setRevisionID($revision->getID()); $toc_view->setRevisionID($revision->getID());
$toc_view->setWhitespace($whitespace); $toc_view->setWhitespace($whitespace);
$draft = id(new PhabricatorDraft())->loadOneWhere( if (!$viewer_is_anonymous) {
'authorPHID = %s AND draftKey = %s', $draft = id(new PhabricatorDraft())->loadOneWhere(
$user->getPHID(), 'authorPHID = %s AND draftKey = %s',
'differential-comment-'.$revision->getID()); $user->getPHID(),
if ($draft) { 'differential-comment-'.$revision->getID());
$draft = $draft->getDraft(); if ($draft) {
} else { $draft = $draft->getDraft();
$draft = null; } else {
$draft = null;
}
$comment_form = new DifferentialAddCommentView();
$comment_form->setRevision($revision);
$comment_form->setActions($this->getRevisionCommentActions($revision));
$comment_form->setActionURI('/differential/comment/save/');
$comment_form->setUser($user);
$comment_form->setDraft($draft);
$this->updateViewTime($user->getPHID(), $revision->getPHID());
} }
$comment_form = new DifferentialAddCommentView();
$comment_form->setRevision($revision);
$comment_form->setActions($this->getRevisionCommentActions($revision));
$comment_form->setActionURI('/differential/comment/save/');
$comment_form->setUser($user);
$comment_form->setDraft($draft);
$this->updateViewTime($user->getPHID(), $revision->getPHID());
$pane_id = celerity_generate_unique_node_id(); $pane_id = celerity_generate_unique_node_id();
Javelin::initBehavior( Javelin::initBehavior(
'differential-keyboard-navigation', 'differential-keyboard-navigation',
@ -247,19 +254,22 @@ class DifferentialRevisionViewController extends DifferentialController {
'haunt' => $pane_id, 'haunt' => $pane_id,
)); ));
$page_pane = id(new DifferentialPrimaryPaneView())
->setLineWidthFromChangesets($changesets)
->setID($pane_id)
->appendChild(
$revision_detail->render().
$comment_view->render().
$diff_history->render().
$warning.
$local_view->render().
$toc_view->render().
$changeset_view->render());
if ($comment_form) {
$page_pane->appendChild($comment_form->render());
}
return $this->buildStandardPageResponse( return $this->buildStandardPageResponse(
id(new DifferentialPrimaryPaneView()) $page_pane,
->setLineWidthFromChangesets($changesets)
->setID($pane_id)
->appendChild(
$revision_detail->render().
$comment_view->render().
$diff_history->render().
$warning.
$local_view->render().
$toc_view->render().
$changeset_view->render().
$comment_form->render()),
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,52 +321,54 @@ class DifferentialRevisionViewController extends DifferentialController {
); );
} }
if (!$viewer_is_owner && !$viewer_is_reviewer) { if (!$viewer_is_anonymous) {
$action = $viewer_is_cc ? 'rem' : 'add'; if (!$viewer_is_owner && !$viewer_is_reviewer) {
$links[] = array( $action = $viewer_is_cc ? 'rem' : 'add';
'class' => $viewer_is_cc ? 'subscribe-rem' : 'subscribe-add', $links[] = array(
'href' => "/differential/subscribe/{$action}/{$revision_id}/", 'class' => $viewer_is_cc ? 'subscribe-rem' : 'subscribe-add',
'name' => $viewer_is_cc ? 'Unsubscribe' : 'Subscribe', 'href' => "/differential/subscribe/{$action}/{$revision_id}/",
'instant' => true, 'name' => $viewer_is_cc ? 'Unsubscribe' : 'Subscribe',
); 'instant' => true,
} else { );
$links[] = array( } else {
'class' => 'subscribe-rem unavailable', $links[] = array(
'name' => 'Automatically Subscribed', 'class' => 'subscribe-rem unavailable',
); 'name' => 'Automatically Subscribed',
} );
}
require_celerity_resource('phabricator-object-selector-css'); require_celerity_resource('phabricator-object-selector-css');
require_celerity_resource('javelin-behavior-phabricator-object-selector'); require_celerity_resource('javelin-behavior-phabricator-object-selector');
$links[] = array(
'class' => 'action-dependencies',
'name' => 'Edit Dependencies',
'href' => "/search/attach/{$revision_phid}/DREV/dependencies/",
'sigil' => 'workflow',
);
if (PhabricatorEnv::getEnvConfig('maniphest.enabled')) {
$links[] = array( $links[] = array(
'class' => 'attach-maniphest', 'class' => 'action-dependencies',
'name' => 'Edit Maniphest Tasks', 'name' => 'Edit Dependencies',
'href' => "/search/attach/{$revision_phid}/TASK/", 'href' => "/search/attach/{$revision_phid}/DREV/dependencies/",
'sigil' => 'workflow', 'sigil' => 'workflow',
); );
if (PhabricatorEnv::getEnvConfig('maniphest.enabled')) {
$links[] = array(
'class' => 'attach-maniphest',
'name' => 'Edit Maniphest Tasks',
'href' => "/search/attach/{$revision_phid}/TASK/",
'sigil' => 'workflow',
);
}
$links[] = array(
'class' => 'transcripts-metamta',
'name' => 'MetaMTA Transcripts',
'href' => "/mail/?phid={$revision_phid}",
);
$links[] = array(
'class' => 'transcripts-herald',
'name' => 'Herald Transcripts',
'href' => "/herald/transcript/?phid={$revision_phid}",
);
} }
$links[] = array(
'class' => 'transcripts-metamta',
'name' => 'MetaMTA Transcripts',
'href' => "/mail/?phid={$revision_phid}",
);
$links[] = array(
'class' => 'transcripts-herald',
'name' => 'Herald Transcripts',
'href' => "/herald/transcript/?phid={$revision_phid}",
);
return $links; return $links;
} }

View file

@ -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());

View file

@ -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;
} }