1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 05:20:56 +01:00

Provide an application-wide controller for Releeph

Summary: Fixes T3548. Concrete Releeph controllers currently extend either from ReleephController or PhabricatorController directly. Instead, make them all extend ReleephController. Introduce ReleephProjectController for controllers which depend on project context. Project context code which lived in ReleephController moves to ReleephProjectController.

Test Plan: Viewed list, project, releases, requests.

Reviewers: btrahan, edward

Reviewed By: edward

CC: aran

Maniphest Tasks: T3548

Differential Revision: https://secure.phabricator.com/D6472
This commit is contained in:
epriestley 2013-07-21 08:42:10 -07:00
parent 6cdb02fc7e
commit 904a24c1df
18 changed files with 139 additions and 132 deletions

View file

@ -1905,6 +1905,7 @@ phutil_register_library_map(array(
'ReleephPHIDConstants' => 'applications/releeph/ReleephPHIDConstants.php', 'ReleephPHIDConstants' => 'applications/releeph/ReleephPHIDConstants.php',
'ReleephProject' => 'applications/releeph/storage/ReleephProject.php', 'ReleephProject' => 'applications/releeph/storage/ReleephProject.php',
'ReleephProjectActionController' => 'applications/releeph/controller/project/ReleephProjectActionController.php', 'ReleephProjectActionController' => 'applications/releeph/controller/project/ReleephProjectActionController.php',
'ReleephProjectController' => 'applications/releeph/controller/ReleephProjectController.php',
'ReleephProjectCreateController' => 'applications/releeph/controller/project/ReleephProjectCreateController.php', 'ReleephProjectCreateController' => 'applications/releeph/controller/project/ReleephProjectCreateController.php',
'ReleephProjectEditController' => 'applications/releeph/controller/project/ReleephProjectEditController.php', 'ReleephProjectEditController' => 'applications/releeph/controller/project/ReleephProjectEditController.php',
'ReleephProjectListController' => 'applications/releeph/controller/project/ReleephProjectListController.php', 'ReleephProjectListController' => 'applications/releeph/controller/project/ReleephProjectListController.php',
@ -3913,15 +3914,15 @@ phutil_register_library_map(array(
'ReleephActiveProjectListView' => 'AphrontView', 'ReleephActiveProjectListView' => 'AphrontView',
'ReleephAuthorFieldSpecification' => 'ReleephFieldSpecification', 'ReleephAuthorFieldSpecification' => 'ReleephFieldSpecification',
'ReleephBranch' => 'ReleephDAO', 'ReleephBranch' => 'ReleephDAO',
'ReleephBranchAccessController' => 'ReleephController', 'ReleephBranchAccessController' => 'ReleephProjectController',
'ReleephBranchBoxView' => 'AphrontView', 'ReleephBranchBoxView' => 'AphrontView',
'ReleephBranchCommitFieldSpecification' => 'ReleephFieldSpecification', 'ReleephBranchCommitFieldSpecification' => 'ReleephFieldSpecification',
'ReleephBranchCreateController' => 'ReleephController', 'ReleephBranchCreateController' => 'ReleephProjectController',
'ReleephBranchEditController' => 'ReleephController', 'ReleephBranchEditController' => 'ReleephProjectController',
'ReleephBranchEditor' => 'PhabricatorEditor', 'ReleephBranchEditor' => 'PhabricatorEditor',
'ReleephBranchNamePreviewController' => 'PhabricatorController', 'ReleephBranchNamePreviewController' => 'PhabricatorController',
'ReleephBranchPreviewView' => 'AphrontFormControl', 'ReleephBranchPreviewView' => 'AphrontFormControl',
'ReleephBranchViewController' => 'ReleephController', 'ReleephBranchViewController' => 'ReleephProjectController',
'ReleephCommitFinderException' => 'Exception', 'ReleephCommitFinderException' => 'Exception',
'ReleephCommitMessageFieldSpecification' => 'ReleephFieldSpecification', 'ReleephCommitMessageFieldSpecification' => 'ReleephFieldSpecification',
'ReleephController' => 'PhabricatorController', 'ReleephController' => 'PhabricatorController',
@ -3945,23 +3946,24 @@ phutil_register_library_map(array(
0 => 'ReleephDAO', 0 => 'ReleephDAO',
1 => 'PhabricatorPolicyInterface', 1 => 'PhabricatorPolicyInterface',
), ),
'ReleephProjectActionController' => 'ReleephController', 'ReleephProjectActionController' => 'ReleephProjectController',
'ReleephProjectCreateController' => 'ReleephController', 'ReleephProjectController' => 'ReleephController',
'ReleephProjectEditController' => 'ReleephController', 'ReleephProjectCreateController' => 'ReleephProjectController',
'ReleephProjectEditController' => 'ReleephProjectController',
'ReleephProjectListController' => 'PhabricatorController', 'ReleephProjectListController' => 'PhabricatorController',
'ReleephProjectQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'ReleephProjectQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'ReleephProjectView' => 'AphrontView', 'ReleephProjectView' => 'AphrontView',
'ReleephProjectViewController' => 'ReleephController', 'ReleephProjectViewController' => 'ReleephProjectController',
'ReleephReasonFieldSpecification' => 'ReleephFieldSpecification', 'ReleephReasonFieldSpecification' => 'ReleephFieldSpecification',
'ReleephRequest' => 'ReleephRequest' =>
array( array(
0 => 'ReleephDAO', 0 => 'ReleephDAO',
1 => 'PhabricatorPolicyInterface', 1 => 'PhabricatorPolicyInterface',
), ),
'ReleephRequestActionController' => 'ReleephController', 'ReleephRequestActionController' => 'ReleephProjectController',
'ReleephRequestCommentController' => 'ReleephController', 'ReleephRequestCommentController' => 'ReleephProjectController',
'ReleephRequestDifferentialCreateController' => 'ReleephController', 'ReleephRequestDifferentialCreateController' => 'ReleephProjectController',
'ReleephRequestEditController' => 'ReleephController', 'ReleephRequestEditController' => 'ReleephProjectController',
'ReleephRequestEvent' => 'ReleephDAO', 'ReleephRequestEvent' => 'ReleephDAO',
'ReleephRequestException' => 'Exception', 'ReleephRequestException' => 'Exception',
'ReleephRequestHeaderListView' => 'AphrontView', 'ReleephRequestHeaderListView' => 'AphrontView',
@ -3977,7 +3979,7 @@ phutil_register_library_map(array(
'ReleephRequestTransactionalEditor' => 'PhabricatorApplicationTransactionEditor', 'ReleephRequestTransactionalEditor' => 'PhabricatorApplicationTransactionEditor',
'ReleephRequestTypeaheadControl' => 'AphrontFormControl', 'ReleephRequestTypeaheadControl' => 'AphrontFormControl',
'ReleephRequestTypeaheadController' => 'PhabricatorTypeaheadDatasourceController', 'ReleephRequestTypeaheadController' => 'PhabricatorTypeaheadDatasourceController',
'ReleephRequestViewController' => 'ReleephController', 'ReleephRequestViewController' => 'ReleephProjectController',
'ReleephRequestorFieldSpecification' => 'ReleephFieldSpecification', 'ReleephRequestorFieldSpecification' => 'ReleephFieldSpecification',
'ReleephRevisionFieldSpecification' => 'ReleephFieldSpecification', 'ReleephRevisionFieldSpecification' => 'ReleephFieldSpecification',
'ReleephRiskFieldSpecification' => 'ReleephFieldSpecification', 'ReleephRiskFieldSpecification' => 'ReleephFieldSpecification',

View file

@ -2,110 +2,6 @@
abstract class ReleephController extends PhabricatorController { abstract class ReleephController extends PhabricatorController {
private $releephProject;
private $releephBranch;
private $releephRequest;
/**
* ReleephController will take care of loading any Releeph* objects
* referenced in the URL.
*/
public function willProcessRequest(array $data) {
// Project
$project = null;
$project_id = idx($data, 'projectID');
$project_name = idx($data, 'projectName');
if ($project_id) {
$project = id(new ReleephProject())->load($project_id);
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 ReleephBranch())->load($branch_id);
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()}'!");
}
}
// 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;
}
public function buildStandardPageResponse($view, array $data) { public function buildStandardPageResponse($view, array $data) {
$page = $this->buildStandardPageView(); $page = $this->buildStandardPageView();

View file

@ -0,0 +1,109 @@
<?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) {
// Project
$project = null;
$project_id = idx($data, 'projectID');
$project_name = idx($data, 'projectName');
if ($project_id) {
$project = id(new ReleephProject())->load($project_id);
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 ReleephBranch())->load($branch_id);
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()}'!");
}
}
// 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;
}
}

View file

@ -1,6 +1,6 @@
<?php <?php
final class ReleephBranchAccessController extends ReleephController { final class ReleephBranchAccessController extends ReleephProjectController {
private $action; private $action;

View file

@ -1,6 +1,6 @@
<?php <?php
final class ReleephBranchCreateController extends ReleephController { final class ReleephBranchCreateController extends ReleephProjectController {
public function processRequest() { public function processRequest() {
$releeph_project = $this->getReleephProject(); $releeph_project = $this->getReleephProject();

View file

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

View file

@ -1,7 +1,7 @@
<?php <?php
final class ReleephBranchNamePreviewController final class ReleephBranchNamePreviewController
extends PhabricatorController { extends ReleephController {
public function processRequest() { public function processRequest() {
$request = $this->getRequest(); $request = $this->getRequest();

View file

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

View file

@ -1,6 +1,6 @@
<?php <?php
final class ReleephProjectActionController extends ReleephController { final class ReleephProjectActionController extends ReleephProjectController {
private $action; private $action;

View file

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

View file

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

View file

@ -1,6 +1,6 @@
<?php <?php
final class ReleephProjectListController extends PhabricatorController { final class ReleephProjectListController extends ReleephController {
private $filter; private $filter;

View file

@ -1,6 +1,6 @@
<?php <?php
final class ReleephProjectViewController extends ReleephController { final class ReleephProjectViewController extends ReleephProjectController {
public function processRequest() { public function processRequest() {
// Load all branches // Load all branches

View file

@ -1,6 +1,6 @@
<?php <?php
final class ReleephRequestActionController extends ReleephController { final class ReleephRequestActionController extends ReleephProjectController {
private $action; private $action;

View file

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

View file

@ -1,7 +1,7 @@
<?php <?php
final class ReleephRequestDifferentialCreateController final class ReleephRequestDifferentialCreateController
extends ReleephController { extends ReleephProjectController {
private $revision; private $revision;

View file

@ -1,6 +1,6 @@
<?php <?php
final class ReleephRequestEditController extends ReleephController { final class ReleephRequestEditController extends ReleephProjectController {
private $id; private $id;

View file

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