1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

Remove ReleephProjectController

Summary:
Ref T3657. General changes here:

  - Removes `ReleephProjectController`, which is the source of T3657.
  - Mostly moves requests from "RQ" as a monogram to "Y" (looks like a merge, mnemonic for "yank"?, we don't have too many characters left). This should be essentially only cosmetic. This reduces ambiguity with "rQ" and "R123", which are current and future repository monograms. This will continue in the next few diffs.
  - Makes requests implement policies correctly.

Test Plan: Created, edited, browsed requests.

Reviewers: chad, btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T3657

Differential Revision: https://secure.phabricator.com/D8766
This commit is contained in:
epriestley 2014-04-14 12:06:56 -07:00
parent 6899fbcf29
commit 6deab24475
20 changed files with 274 additions and 387 deletions

View file

@ -98,12 +98,12 @@ return array(
'rsrc/css/application/releeph/releeph-branch.css' => 'b8821d2d',
'rsrc/css/application/releeph/releeph-colors.css' => '2d2d6aa8',
'rsrc/css/application/releeph/releeph-core.css' => '140b959d',
'rsrc/css/application/releeph/releeph-intents.css' => '7364ac97',
'rsrc/css/application/releeph/releeph-preview-branch.css' => '0e383ca3',
'rsrc/css/application/releeph/releeph-intents.css' => '39065521',
'rsrc/css/application/releeph/releeph-preview-branch.css' => 'b7a6f4a5',
'rsrc/css/application/releeph/releeph-project.css' => 'ee1f9f57',
'rsrc/css/application/releeph/releeph-request-differential-create-dialog.css' => '8d8b92cd',
'rsrc/css/application/releeph/releeph-request-typeahead.css' => '667a48ae',
'rsrc/css/application/releeph/releeph-status.css' => 'a20631d9',
'rsrc/css/application/releeph/releeph-status.css' => 'd119a005',
'rsrc/css/application/search/search-results.css' => 'f240504c',
'rsrc/css/application/settings/settings.css' => 'ea8f5915',
'rsrc/css/application/slowvote/slowvote.css' => '266df6a1',
@ -777,12 +777,12 @@ return array(
'releeph-branch' => 'b8821d2d',
'releeph-colors' => '2d2d6aa8',
'releeph-core' => '140b959d',
'releeph-intents' => '7364ac97',
'releeph-preview-branch' => '0e383ca3',
'releeph-intents' => '39065521',
'releeph-preview-branch' => 'b7a6f4a5',
'releeph-project' => 'ee1f9f57',
'releeph-request-differential-create-dialog' => '8d8b92cd',
'releeph-request-typeahead-css' => '667a48ae',
'releeph-status' => 'a20631d9',
'releeph-status' => 'd119a005',
'setup-issue-css' => '69e640e7',
'sprite-actions-css' => '969ad0e5',
'sprite-apps-css' => '6973a52b',

View file

@ -2542,12 +2542,12 @@ phutil_register_library_map(array(
'ReleephProductTransactionQuery' => 'applications/releeph/query/ReleephProductTransactionQuery.php',
'ReleephProductViewController' => 'applications/releeph/controller/project/ReleephProductViewController.php',
'ReleephProject' => 'applications/releeph/storage/ReleephProject.php',
'ReleephProjectController' => 'applications/releeph/controller/ReleephProjectController.php',
'ReleephProjectQuery' => 'applications/releeph/query/ReleephProjectQuery.php',
'ReleephReasonFieldSpecification' => 'applications/releeph/field/specification/ReleephReasonFieldSpecification.php',
'ReleephRequest' => 'applications/releeph/storage/ReleephRequest.php',
'ReleephRequestActionController' => 'applications/releeph/controller/request/ReleephRequestActionController.php',
'ReleephRequestCommentController' => 'applications/releeph/controller/request/ReleephRequestCommentController.php',
'ReleephRequestController' => 'applications/releeph/controller/request/ReleephRequestController.php',
'ReleephRequestDifferentialCreateController' => 'applications/releeph/controller/request/ReleephRequestDifferentialCreateController.php',
'ReleephRequestEditController' => 'applications/releeph/controller/request/ReleephRequestEditController.php',
'ReleephRequestHeaderListView' => 'applications/releeph/view/request/header/ReleephRequestHeaderListView.php',
@ -5527,7 +5527,7 @@ phutil_register_library_map(array(
'ReleephPHIDTypeRequest' => 'PhabricatorPHIDType',
'ReleephProductActionController' => 'ReleephProductController',
'ReleephProductController' => 'ReleephController',
'ReleephProductCreateController' => 'ReleephProjectController',
'ReleephProductCreateController' => 'ReleephProductController',
'ReleephProductEditController' => 'ReleephProductController',
'ReleephProductEditor' => 'PhabricatorApplicationTransactionEditor',
'ReleephProductHistoryController' => 'ReleephProductController',
@ -5549,7 +5549,6 @@ phutil_register_library_map(array(
0 => 'ReleephDAO',
1 => 'PhabricatorPolicyInterface',
),
'ReleephProjectController' => 'ReleephController',
'ReleephProjectQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'ReleephReasonFieldSpecification' => 'ReleephFieldSpecification',
'ReleephRequest' =>
@ -5558,10 +5557,11 @@ phutil_register_library_map(array(
1 => 'PhabricatorPolicyInterface',
2 => 'PhabricatorCustomFieldInterface',
),
'ReleephRequestActionController' => 'ReleephProjectController',
'ReleephRequestCommentController' => 'ReleephProjectController',
'ReleephRequestDifferentialCreateController' => 'ReleephProjectController',
'ReleephRequestEditController' => 'ReleephProjectController',
'ReleephRequestActionController' => 'ReleephRequestController',
'ReleephRequestCommentController' => 'ReleephRequestController',
'ReleephRequestController' => 'ReleephController',
'ReleephRequestDifferentialCreateController' => 'ReleephController',
'ReleephRequestEditController' => 'ReleephBranchController',
'ReleephRequestHeaderListView' => 'AphrontView',
'ReleephRequestHeaderView' => 'AphrontView',
'ReleephRequestIntentsView' => 'AphrontView',
@ -5576,7 +5576,7 @@ phutil_register_library_map(array(
'ReleephRequestTransactionalEditor' => 'PhabricatorApplicationTransactionEditor',
'ReleephRequestTypeaheadControl' => 'AphrontFormControl',
'ReleephRequestTypeaheadController' => 'PhabricatorTypeaheadDatasourceController',
'ReleephRequestViewController' => 'ReleephProjectController',
'ReleephRequestViewController' => 'ReleephBranchController',
'ReleephRequestorFieldSpecification' => 'ReleephFieldSpecification',
'ReleephRevisionFieldSpecification' => 'ReleephFieldSpecification',
'ReleephSeverityFieldSpecification' => 'ReleephLevelFieldSpecification',

View file

@ -31,7 +31,13 @@ final class PhabricatorApplicationReleeph extends PhabricatorApplication {
public function getRoutes() {
return array(
'/Y(?P<requestID>[1-9]\d*)' => 'ReleephRequestViewController',
// TODO: Remove these older routes eventually.
'/RQ(?P<requestID>[1-9]\d*)' => 'ReleephRequestViewController',
'/releeph/request/(?P<requestID>[1-9]\d*)/'
=> 'ReleephRequestViewController',
'/releeph/' => array(
'' => 'ReleephProductListController',
'project/' => array(
@ -45,6 +51,7 @@ final class PhabricatorApplicationReleeph extends PhabricatorApplication {
'history/' => 'ReleephProductHistoryController',
),
),
'branch/' => array(
'edit/(?P<branchID>[1-9]\d*)/' =>
'ReleephBranchEditController',
@ -55,9 +62,11 @@ final class PhabricatorApplicationReleeph extends PhabricatorApplication {
'history/' => 'ReleephBranchHistoryController',
'(?:query/(?P<queryKey>[^/]+)/)?' => 'ReleephBranchViewController',
),
'pull/(?P<branchID>[1-9]\d*)/' =>
'ReleephRequestEditController',
),
'request/' => array(
'(?P<requestID>[1-9]\d*)/' => 'ReleephRequestViewController',
'create/' => 'ReleephRequestEditController',
'differentialcreate/' => array(
'D(?P<diffRevID>[1-9]\d*)' =>
@ -72,14 +81,6 @@ final class PhabricatorApplicationReleeph extends PhabricatorApplication {
'comment/(?P<requestID>[1-9]\d*)/' =>
'ReleephRequestCommentController',
),
// Branch navigation made pretty, as it's the most common:
'(?P<projectName>[^/]+)/(?P<branchName>[^/]+)/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?' => 'ReleephBranchViewController',
'edit/' => 'ReleephBranchEditController',
'request/' => 'ReleephRequestEditController',
'(?P<action>close|re-open)/' => 'ReleephBranchAccessController',
),
)
);
}

View file

@ -1,155 +0,0 @@
<?php
abstract class ReleephProjectController extends ReleephController {
private $releephProject;
private $releephBranch;
private $releephRequest;
/**
* ReleephController will take care of loading any Releeph* objects
* referenced in the URL.
*/
public function willProcessRequest(array $data) {
$viewer = $this->getRequest()->getUser();
// Project
$project = null;
$project_id = idx($data, 'projectID');
$project_name = idx($data, 'projectName');
if ($project_id) {
$project = id(new ReleephProjectQuery())
->setViewer($viewer)
->withIDs(array($project_id))
->executeOne();
if (!$project) {
throw new Exception(
"ReleephProject with id '{$project_id}' not found!");
}
} elseif ($project_name) {
$project = id(new ReleephProject())
->loadOneWhere('name = %s', $project_name);
if (!$project) {
throw new Exception(
"ReleephProject with name '{$project_name}' not found!");
}
}
// Branch
$branch = null;
$branch_id = idx($data, 'branchID');
$branch_name = idx($data, 'branchName');
if ($branch_id) {
$branch = id(new ReleephBranchQuery())
->setViewer($viewer)
->withIDs(array($branch_id))
->executeOne();
if (!$branch) {
throw new Exception("Branch with id '{$branch_id}' not found!");
}
} elseif ($branch_name) {
if (!$project) {
throw new Exception(
"You cannot refer to a branch by name without also referring ".
"to a ReleephProject (branch names are only unique in projects).");
}
$branch = id(new ReleephBranch())->loadOneWhere(
'basename = %s AND releephProjectID = %d',
$branch_name,
$project->getID());
if (!$branch) {
throw new Exception(
"ReleephBranch with basename '{$branch_name}' not found ".
"in project '{$project->getName()}'!");
}
// Do the branch query again, properly, to hit policies and load attached
// data.
// TODO: Clean this up with T3657.
$branch = id(new ReleephBranchQuery())
->setViewer($viewer)
->withIDs(array($branch->getID()))
->executeOne();
if (!$branch) {
throw new Exception('404!');
}
}
// Request
$request = null;
$request_id = idx($data, 'requestID');
if ($request_id) {
$request = id(new ReleephRequest())->load($request_id);
if (!$request) {
throw new Exception(
"ReleephRequest with id '{$request_id}' not found!");
}
}
// Fill in the gaps
if ($request && !$branch) {
$branch = $request->loadReleephBranch();
}
if ($branch && !$project) {
$project = $branch->loadReleephProject();
}
// Set!
$this->releephProject = $project;
$this->releephBranch = $branch;
$this->releephRequest = $request;
}
protected function getReleephProject() {
if (!$this->releephProject) {
throw new Exception(
'This controller did not load a ReleephProject from the URL $data.');
}
return $this->releephProject;
}
protected function getReleephBranch() {
if (!$this->releephBranch) {
throw new Exception(
'This controller did not load a ReleephBranch from the URL $data.');
}
return $this->releephBranch;
}
protected function getReleephRequest() {
if (!$this->releephRequest) {
throw new Exception(
'This controller did not load a ReleephRequest from the URL $data.');
}
return $this->releephRequest;
}
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
// TODO: The massive amount of derps here should be fixed once URIs get
// sorted out; see T3657.
try {
$project = $this->getReleephProject();
$project_id = $project->getID();
$project_uri = $this->getApplicationURI("project/{$project_id}/");
$crumbs->addTextCrumb($project->getName(), $project_uri);
} catch (Exception $ex) {
// TODO: This is derps.
}
try {
$branch = $this->getReleephBranch();
$branch_uri = $branch->getURI();
$crumbs->addTextCrumb($branch->getDisplayNameWithDetail(), $branch_uri);
} catch (Exception $ex) {
// TODO: This is also derps.
}
return $crumbs;
}
}

View file

@ -52,7 +52,6 @@ final class ReleephBranchViewController extends ReleephBranchController
$requests);
$list = id(new ReleephRequestHeaderListView())
->setOriginType('branch')
->setUser($viewer)
->setAphrontRequest($this->getRequest())
->setReleephProject($branch->getProduct())
@ -87,10 +86,10 @@ final class ReleephBranchViewController extends ReleephBranchController
$crumbs = parent::buildApplicationCrumbs();
$branch = $this->getBranch();
$create_uri = $branch->getURI('request/');
$crumbs->addAction(
id(new PHUIListItemView())
->setHref($create_uri)
->setHref($this->getApplicationURI('branch/pull/'.$branch->getID().'/'))
->setName(pht('New Pull Request'))
->setIcon('create')
->setDisabled(!$branch->isActive()));

View file

@ -1,6 +1,6 @@
<?php
final class ReleephProductCreateController extends ReleephProjectController {
final class ReleephProductCreateController extends ReleephProductController {
public function processRequest() {
$request = $this->getRequest();

View file

@ -1,32 +1,39 @@
<?php
final class ReleephRequestActionController extends ReleephProjectController {
final class ReleephRequestActionController
extends ReleephRequestController {
private $action;
private $requestID;
public function willProcessRequest(array $data) {
parent::willProcessRequest($data);
$this->action = $data['action'];
$this->requestID = $data['requestID'];
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$releeph_project = $this->getReleephProject();
$releeph_branch = $this->getReleephBranch();
$releeph_request = $this->getReleephRequest();
$pull = id(new ReleephRequestQuery())
->setViewer($viewer)
->withIDs(array($this->requestID))
->executeOne();
if (!$pull) {
return new Aphront404Response();
}
$releeph_branch->populateReleephRequestHandles(
$request->getUser(), array($releeph_request));
$branch = $pull->getBranch();
$product = $branch->getProduct();
$branch->populateReleephRequestHandles($viewer, array($pull));
$action = $this->action;
$user = $request->getUser();
$origin_uri = $releeph_request->loadReleephBranch()->getURI();
$origin_uri = '/'.$pull->getMonogram();
$editor = id(new ReleephRequestTransactionalEditor())
->setActor($user)
->setActor($viewer)
->setContinueOnNoEffect(true)
->setContentSourceFromRequest($request);
@ -43,15 +50,15 @@ final class ReleephRequestActionController extends ReleephProjectController {
->setTransactionType(ReleephRequestTransaction::TYPE_USER_INTENT)
->setMetadataValue(
'isAuthoritative',
$releeph_project->isAuthoritative($user))
$product->isAuthoritative($viewer))
->setNewValue($intent);
break;
case 'mark-manually-picked':
case 'mark-manually-reverted':
if (
$releeph_request->getRequestUserPHID() === $user->getPHID() ||
$releeph_project->isAuthoritative($user)) {
$pull->getRequestUserPHID() === $viewer->getPHID() ||
$product->isAuthoritative($viewer)) {
// We're all good!
} else {
@ -84,25 +91,24 @@ final class ReleephRequestActionController extends ReleephProjectController {
throw new Exception("unknown or unimplemented action {$action}");
}
$editor->applyTransactions($releeph_request, $xactions);
$editor->applyTransactions($pull, $xactions);
// If we're adding a new user to userIntents, we'll have to re-populate
// request handles to load that user's data.
//
// This is cheap enough to do every time.
$this->getReleephBranch()->populateReleephRequestHandles(
$user, array($releeph_request));
$branch->populateReleephRequestHandles($viewer, array($pull));
$list = id(new ReleephRequestHeaderListView())
->setReleephProject($this->getReleephProject())
->setReleephBranch($this->getReleephBranch())
->setReleephRequests(array($releeph_request))
->setUser($request->getUser())
->setAphrontRequest($this->getRequest())
->setOriginType('request');
->setReleephProject($product)
->setReleephBranch($branch)
->setReleephRequests(array($pull))
->setUser($viewer)
->setAphrontRequest($request);
return id(new AphrontAjaxResponse())->setContent(array(
'markup' => head($list->renderInner())
));
return id(new AphrontAjaxResponse())->setContent(
array(
'markup' => hsprintf('%s', $list->renderInner()),
));
}
}

View file

@ -1,22 +1,34 @@
<?php
final class ReleephRequestCommentController
extends ReleephProjectController {
extends ReleephRequestController {
private $requestID;
public function willProcessRequest(array $data) {
$this->requestID = $data['requestID'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$rq = $this->getReleephRequest();
$viewer = $request->getUser();
if (!$request->isFormPost()) {
return new Aphront400Response();
}
$pull = id(new ReleephRequestQuery())
->setViewer($viewer)
->withIDs(array($this->requestID))
->executeOne();
if (!$pull) {
return new Aphront404Response();
}
$is_preview = $request->isPreviewRequest();
$draft = PhabricatorDraft::buildFromRequest($request);
$view_uri = $this->getApplicationURI('/RQ'.$rq->getID());
$view_uri = $this->getApplicationURI('/'.$pull->getMonogram());
$xactions = array();
$xactions[] = id(new ReleephRequestTransaction())
@ -26,13 +38,13 @@ final class ReleephRequestCommentController
->setContent($request->getStr('comment')));
$editor = id(new ReleephRequestTransactionalEditor())
->setActor($user)
->setActor($viewer)
->setContinueOnNoEffect($request->isContinueRequest())
->setContentSourceFromRequest($request)
->setIsPreview($is_preview);
try {
$xactions = $editor->applyTransactions($rq, $xactions);
$xactions = $editor->applyTransactions($pull, $xactions);
} catch (PhabricatorApplicationTransactionNoEffectException $ex) {
return id(new PhabricatorApplicationTransactionNoEffectResponse())
->setCancelURI($view_uri)
@ -45,7 +57,7 @@ final class ReleephRequestCommentController
if ($request->isAjax()) {
return id(new PhabricatorApplicationTransactionResponse())
->setViewer($user)
->setViewer($viewer)
->setTransactions($xactions)
->setIsPreview($is_preview)
->setAnchorOffset($request->getStr('anchor'));

View file

@ -0,0 +1,5 @@
<?php
abstract class ReleephRequestController extends ReleephController {
}

View file

@ -1,7 +1,9 @@
<?php
// TODO: After T2222, this is likely unreachable?
final class ReleephRequestDifferentialCreateController
extends ReleephProjectController {
extends ReleephController {
private $revisionID;
private $revision;

View file

@ -1,79 +1,85 @@
<?php
final class ReleephRequestEditController extends ReleephProjectController {
final class ReleephRequestEditController extends ReleephBranchController {
private $id;
private $requestID;
private $branchID;
public function willProcessRequest(array $data) {
$this->id = idx($data, 'requestID');
parent::willProcessRequest($data);
$this->requestID = idx($data, 'requestID');
$this->branchID = idx($data, 'branchID');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$viewer = $request->getUser();
$releeph_project = $this->getReleephProject();
$releeph_branch = $this->getReleephBranch();
$request_identifier = $request->getStr('requestIdentifierRaw');
$e_request_identifier = true;
// Load the RQ we're editing, or create a new one
if ($this->id) {
$rq = id(new ReleephRequestQuery())
->setViewer($user)
->withIDs(array($this->id))
if ($this->requestID) {
$pull = id(new ReleephRequestQuery())
->setViewer($viewer)
->withIDs(array($this->requestID))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$pull) {
return new Aphront404Response();
}
$branch = $pull->getBranch();
$is_edit = true;
} else {
$is_edit = false;
$rq = id(new ReleephRequest())
->setRequestUserPHID($user->getPHID())
->setBranchID($releeph_branch->getID())
$branch = id(new ReleephBranchQuery())
->setViewer($viewer)
->withIDs(array($this->branchID))
->executeOne();
if (!$branch) {
return new Aphront404Response();
}
$pull = id(new ReleephRequest())
->setRequestUserPHID($viewer->getPHID())
->setBranchID($branch->getID())
->setInBranch(0);
$is_edit = false;
}
$this->setBranch($branch);
$product = $branch->getProduct();
$request_identifier = $request->getStr('requestIdentifierRaw');
$e_request_identifier = true;
// Load all the ReleephFieldSpecifications
$selector = $this->getReleephProject()->getReleephFieldSelector();
$selector = $branch->getProduct()->getReleephFieldSelector();
$fields = $selector->getFieldSpecifications();
foreach ($fields as $field) {
$field
->setReleephProject($releeph_project)
->setReleephBranch($releeph_branch)
->setReleephRequest($rq);
->setReleephProject($product)
->setReleephBranch($branch)
->setReleephRequest($pull);
}
$field_list = PhabricatorCustomField::getObjectFields(
$rq,
$pull,
PhabricatorCustomField::ROLE_EDIT);
foreach ($field_list->getFields() as $field) {
$field
->setReleephProject($releeph_project)
->setReleephBranch($releeph_branch)
->setReleephRequest($rq);
->setReleephProject($product)
->setReleephBranch($branch)
->setReleephRequest($pull);
}
$field_list->readFieldsFromStorage($rq);
$field_list->readFieldsFromStorage($pull);
// <aidehua> epriestley: Is it common to pass around a referer URL to
// return from whence one came? [...]
// <epriestley> If you only have two places, maybe consider some parameter
// rather than the full URL.
switch ($request->getStr('origin')) {
case 'request':
$origin_uri = '/RQ'.$rq->getID();
break;
case 'branch':
default:
$origin_uri = $releeph_branch->getURI();
break;
if ($this->branchID) {
$cancel_uri = $this->getApplicationURI('branch/'.$this->branchID.'/');
} else {
$cancel_uri = '/'.$pull->getMonogram();
}
// Make edits
@ -91,8 +97,8 @@ final class ReleephRequestEditController extends ReleephProjectController {
} else {
$pr_commit = null;
$finder = id(new ReleephCommitFinder())
->setUser($user)
->setReleephProject($releeph_project);
->setUser($viewer)
->setReleephProject($product);
try {
$pr_commit = $finder->fromPartial($request_identifier);
} catch (Exception $e) {
@ -115,7 +121,7 @@ final class ReleephRequestEditController extends ReleephProjectController {
if (!$errors) {
$existing = id(new ReleephRequest())
->loadOneWhere('requestCommitPHID = %s AND branchID = %d',
$pr_commit->getPHID(), $releeph_branch->getID());
$pr_commit->getPHID(), $branch->getID());
if ($existing) {
return id(new AphrontRedirectResponse())
->setURI('/releeph/request/edit/'.$existing->getID().
@ -130,10 +136,10 @@ final class ReleephRequestEditController extends ReleephProjectController {
->setTransactionType(ReleephRequestTransaction::TYPE_USER_INTENT)
// To help hide these implicit intents...
->setMetadataValue('isRQCreate', true)
->setMetadataValue('userPHID', $user->getPHID())
->setMetadataValue('userPHID', $viewer->getPHID())
->setMetadataValue(
'isAuthoritative',
$releeph_project->isAuthoritative($user))
$product->isAuthoritative($viewer))
->setNewValue(ReleephRequest::INTENT_WANT);
}
}
@ -164,21 +170,21 @@ final class ReleephRequestEditController extends ReleephProjectController {
if (!$errors) {
$editor = id(new ReleephRequestTransactionalEditor())
->setActor($user)
->setActor($viewer)
->setContinueOnNoEffect(true)
->setContentSourceFromRequest($request);
$editor->applyTransactions($rq, $xactions);
return id(new AphrontRedirectResponse())->setURI($origin_uri);
$editor->applyTransactions($pull, $xactions);
return id(new AphrontRedirectResponse())->setURI($cancel_uri);
}
}
$releeph_branch->populateReleephRequestHandles($user, array($rq));
$handles = $rq->getHandles();
$branch->populateReleephRequestHandles($viewer, array($pull));
$handles = $pull->getHandles();
$age_string = '';
if ($is_edit) {
$age_string = phabricator_format_relative_time(
time() - $rq->getDateCreated()) . ' ago';
time() - $pull->getDateCreated()) . ' ago';
}
// Warn the user if we've been redirected here because we tried to
@ -190,24 +196,15 @@ final class ReleephRequestEditController extends ReleephProjectController {
hsprintf(
"Requested %s by %s",
$age_string,
$handles[$rq->getRequestUserPHID()]->renderLink())
$handles[$pull->getRequestUserPHID()]->renderLink())
);
$notice_view = id(new AphrontErrorView())
->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
->setErrors($notice_messages);
}
/**
* Build the rest of the page
*/
$error_view = null;
if ($errors) {
$error_view = new AphrontErrorView();
$error_view->setErrors($errors);
}
$form = id(new AphrontFormView())
->setUser($user);
->setUser($viewer);
if ($is_edit) {
$form
@ -215,20 +212,20 @@ final class ReleephRequestEditController extends ReleephProjectController {
id(new AphrontFormMarkupControl())
->setLabel('Original Commit')
->setValue(
$handles[$rq->getRequestCommitPHID()]->renderLink()))
$handles[$pull->getRequestCommitPHID()]->renderLink()))
->appendChild(
id(new AphrontFormMarkupControl())
->setLabel('Requestor')
->setValue(hsprintf(
'%s %s',
$handles[$rq->getRequestUserPHID()]->renderLink(),
$handles[$pull->getRequestUserPHID()]->renderLink(),
$age_string)));
} else {
$origin = null;
$diff_rev_id = $request->getStr('D');
if ($diff_rev_id) {
$diff_rev = id(new DifferentialRevisionQuery())
->setViewer($user)
->setViewer($viewer)
->withIDs(array($diff_rev_id))
->executeOne();
$origin = '/D'.$diff_rev->getID();
@ -243,12 +240,12 @@ final class ReleephRequestEditController extends ReleephProjectController {
->setLabel('Diff')
->setValue($title));
} else {
$origin = $releeph_branch->getURI();
$repo = $releeph_project->loadPhabricatorRepository();
$origin = $branch->getURI();
$repo = $product->loadPhabricatorRepository();
$branch_cut_point = id(new PhabricatorRepositoryCommit())
->loadOneWhere(
'phid = %s',
$releeph_branch->getCutPointCommitPHID());
$branch->getCutPointCommitPHID());
$form->appendChild(
id(new ReleephRequestTypeaheadControl())
->setName('requestIdentifierRaw')
@ -268,32 +265,37 @@ final class ReleephRequestEditController extends ReleephProjectController {
$crumbs = $this->buildApplicationCrumbs();
if ($is_edit) {
$title = pht('Edit Releeph Request');
$title = pht('Edit Pull Request');
$submit_name = pht('Save');
$crumbs->addTextCrumb('RQ'.$rq->getID(), '/RQ'.$rq->getID());
$crumbs->addTextCrumb($pull->getMonogram(), '/'.$pull->getMonogram());
$crumbs->addTextCrumb(pht('Edit'));
} else {
$title = pht('Create Releeph Request');
$submit_name = pht('Create');
$crumbs->addTextCrumb(pht('New Request'));
$title = pht('Create Pull Request');
$submit_name = pht('Create Pull Request');
$crumbs->addTextCrumb(pht('New Pull Request'));
}
$form->appendChild(
id(new AphrontFormSubmitControl())
->addCancelButton($origin_uri, 'Cancel')
->addCancelButton($cancel_uri, 'Cancel')
->setValue($submit_name));
$box = id(new PHUIObjectBoxView())
->setHeaderText($title)
->setFormErrors($errors)
->appendChild($form);
return $this->buildApplicationPage(
array(
$crumbs,
$notice_view,
$error_view,
$form,
$box,
),
array(
'title' => $title,
'device' => true,
));
}
}

View file

@ -1,95 +1,93 @@
<?php
final class ReleephRequestViewController extends ReleephProjectController {
final class ReleephRequestViewController
extends ReleephBranchController {
private $requestID;
public function willProcessRequest(array $data) {
$this->requestID = $data['requestID'];
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$uri_path = $request->getRequestURI()->getPath();
$legacy_prefix = '/releeph/request/';
if (strncmp($uri_path, $legacy_prefix, strlen($legacy_prefix)) === 0) {
return id(new AphrontRedirectResponse())
->setURI('/RQ'.$this->getReleephRequest()->getID());
$pull = id(new ReleephRequestQuery())
->setViewer($viewer)
->withIDs(array($this->requestID))
->executeOne();
if (!$pull) {
return new Aphront404Response();
}
$this->setBranch($pull->getBranch());
// Redirect older URIs to new "Y" URIs.
// TODO: Get rid of this eventually.
$actual_path = $request->getRequestURI()->getPath();
$expect_path = '/'.$pull->getMonogram();
if ($actual_path != $expect_path) {
return id(new AphrontRedirectResponse())->setURI($expect_path);
}
$releeph_request = $this->getReleephRequest();
$releeph_branch = $this->getReleephBranch();
$releeph_project = $this->getReleephProject();
// TODO: Break this 1:1 stuff?
$branch = $pull->getBranch();
$releeph_branch->populateReleephRequestHandles(
$request->getUser(), array($releeph_request));
// TODO: Very gross.
$branch->populateReleephRequestHandles(
$viewer,
array($pull));
$rq_view =
id(new ReleephRequestHeaderListView())
->setReleephProject($releeph_project)
->setReleephBranch($releeph_branch)
->setReleephRequests(array($releeph_request))
->setUser($request->getUser())
->setAphrontRequest($this->getRequest())
->setReloadOnStateChange(true)
->setOriginType('request');
$user = $request->getUser();
$rq_view = id(new ReleephRequestHeaderListView())
->setReleephProject($branch->getProduct())
->setReleephBranch($branch)
->setReleephRequests(array($pull))
->setUser($viewer)
->setAphrontRequest($request)
->setReloadOnStateChange(true);
$engine = id(new PhabricatorMarkupEngine())
->setViewer($user);
->setViewer($viewer);
$xactions = id(new ReleephRequestTransactionQuery())
->setViewer($user)
->withObjectPHIDs(array($releeph_request->getPHID()))
->setViewer($viewer)
->withObjectPHIDs(array($pull->getPHID()))
->execute();
foreach ($xactions as $xaction) {
if ($xaction->getComment()) {
$engine->addObject(
$xaction->getComment(),
PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT);
}
}
$engine->process();
$timeline = id(new PhabricatorApplicationTransactionView())
->setUser($request->getUser())
->setObjectPHID($releeph_request->getPHID())
->setTransactions($xactions)
->setMarkupEngine($engine);
->setObjectPHID($pull->getPHID())
->setTransactions($xactions);
$add_comment_header = pht('Plea or yield');
$add_comment_header = pht('Plea or Yield');
$draft = PhabricatorDraft::newFromUserAndKey(
$user,
$releeph_request->getPHID());
$viewer,
$pull->getPHID());
$title = hsprintf("RQ%d: %s",
$releeph_request->getID(),
$releeph_request->getSummaryForDisplay());
$title = hsprintf(
"%s %s",
$pull->getMonogram(),
$pull->getSummaryForDisplay());
$add_comment_form = id(new PhabricatorApplicationTransactionCommentView())
->setUser($user)
->setObjectPHID($releeph_request->getPHID())
->setUser($viewer)
->setObjectPHID($pull->getPHID())
->setDraft($draft)
->setHeaderText($add_comment_header)
->setAction($this->getApplicationURI(
'/request/comment/'.$releeph_request->getID().'/'))
->setSubmitButtonName('Comment');
'/request/comment/'.$pull->getID().'/'))
->setSubmitButtonName(pht('Comment'));
$crumbs = $this->buildApplicationCrumbs()
->addTextCrumb($releeph_project->getName(), $releeph_project->getURI())
->addTextCrumb(
$releeph_branch->getDisplayNameWithDetail(),
$releeph_branch->getURI())
->addTextCrumb(
'RQ'.$releeph_request->getID(),
'/RQ'.$releeph_request->getID());
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($pull->getMonogram(), '/'.$pull->getMonogram());
return $this->buildStandardPageResponse(
array(
$crumbs,
array(
$rq_view,
$timeline,
$add_comment_form,
)
$rq_view,
$timeline,
$add_comment_form,
),
array(
'title' => $title

View file

@ -118,6 +118,21 @@ final class ReleephRequestQuery
}
}
$branch_ids = array_unique(mpull($requests, 'getBranchID'));
$branches = id(new ReleephBranchQuery())
->withIDs($branch_ids)
->setViewer($this->getViewer())
->execute();
$branches = mpull($branches, null, 'getID');
foreach ($requests as $key => $request) {
$branch = idx($branches, $request->getBranchID());
if (!$branch) {
unset($requests[$key]);
continue;
}
$request->attachBranch($branch);
}
return $requests;
}

View file

@ -181,19 +181,21 @@ final class ReleephBranch extends ReleephDAO
public function getCapabilities() {
return $this->getProject()->getCapabilities();
return $this->getProduct()->getCapabilities();
}
public function getPolicy($capability) {
return $this->getProject()->getPolicy($capability);
return $this->getProduct()->getPolicy($capability);
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return $this->getProject()->hasAutomaticCapability($capability, $viewer);
return $this->getProduct()->hasAutomaticCapability($capability, $viewer);
}
public function describeAutomaticCapability($capability) {
return null;
return pht(
'Release branches have the same policies as the product they are a '.
'part of.');
}

View file

@ -22,7 +22,9 @@ final class ReleephRequest extends ReleephDAO
// Pre-populated handles that we'll bulk load in ReleephBranch
private $handles = self::ATTACHABLE;
private $customFields = self::ATTACHABLE;
private $branch = self::ATTACHABLE;
@ -89,6 +91,19 @@ final class ReleephRequest extends ReleephDAO
return $this->calculateStatus();
}
public function getMonogram() {
return 'Y'.$this->getID();
}
public function getBranch() {
return $this->assertAttached($this->branch);
}
public function attachBranch(ReleephBranch $branch) {
$this->branch = $branch;
return $this;
}
private function calculateStatus() {
if ($this->shouldBeInBranch()) {
if ($this->getInBranch()) {
@ -305,15 +320,17 @@ final class ReleephRequest extends ReleephDAO
}
public function getPolicy($capability) {
return PhabricatorPolicies::POLICY_USER;
return $this->getBranch()->getPolicy($capability);
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return false;
return $this->getBranch()->hasAutomaticCapability($capability, $viewer);
}
public function describeAutomaticCapability($capability) {
return null;
return pht(
'Pull requests have the same policies as the branches they are '.
'requested against.');
}

View file

@ -3,7 +3,6 @@
final class ReleephRequestHeaderListView
extends AphrontView {
private $originType;
private $releephProject;
private $releephBranch;
private $releephRequests;
@ -12,11 +11,6 @@ final class ReleephRequestHeaderListView
private $errors = array();
public function setOriginType($origin) {
$this->originType = $origin;
return $this;
}
public function setReleephProject(ReleephProject $rp) {
$this->releephProject = $rp;
return $this;
@ -113,7 +107,6 @@ final class ReleephRequestHeaderListView
$views[] = id(new ReleephRequestHeaderView())
->setUser($this->user)
->setAphrontRequest($this->aphrontRequest)
->setOriginType($this->originType)
->setReleephProject($this->releephProject)
->setReleephBranch($this->releephBranch)
->setReleephRequest($releeph_request)

View file

@ -8,7 +8,6 @@ final class ReleephRequestHeaderView extends AphrontView {
private $releephRequest;
private $releephBranch;
private $releephProject;
private $originType;
private $fieldGroups;
public function setAphrontRequest(AphrontRequest $request) {
@ -31,21 +30,11 @@ final class ReleephRequestHeaderView extends AphrontView {
return $this;
}
public function setOriginType($origin) {
// For the Edit controller
$this->originType = $origin;
return $this;
}
public function setReleephFieldGroups(array $field_groups) {
$this->fieldGroups = $field_groups;
return $this;
}
protected function getOrigin() {
return $this->originType;
}
public function render() {
require_celerity_resource('releeph-core');
$all_properties_table = $this->renderFields();
@ -262,8 +251,7 @@ final class ReleephRequestHeaderView extends AphrontView {
$right_buttons[] = phutil_tag(
'a',
array(
'href' => '/releeph/request/edit/'.$this->releephRequest->getID().
'?origin='.$this->originType,
'href' => '/releeph/request/edit/'.$this->releephRequest->getID().'/',
'class' => 'small blue button',
),
'Edit');

View file

@ -17,11 +17,11 @@
}
.releeph-intents .arrow.want {
background-image: url('/rsrc/custom/image/icon/tango/go-next.png');
/* TODO: Icon. */
}
.releeph-intents .arrow.pass {
background-image: url('/rsrc/custom/image/icon/tango/go-previous-gray.png');
/* TODO: Icon. */
}
.releeph-intents a {

View file

@ -11,10 +11,11 @@
padding-left: 22px;
background-repeat: no-repeat;
background-size: 16px auto;
background-image: url(/rsrc/custom/image/releeph/releeph_warning.png);
float: left;
position: absolute;
top: 2.5em;
/* TODO: This had a background that's still at Facebook? */
}
.releeph-preview-branch .name {

View file

@ -22,5 +22,6 @@
padding-left: 22px;
background-repeat: no-repeat;
background-size: 16px auto;
background-image: url(/rsrc/custom/image/releeph/releeph_warning.png);
/* TODO: This had a background that's still at Facebook? */
}