mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-21 13:00: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:
parent
6cdb02fc7e
commit
904a24c1df
18 changed files with 139 additions and 132 deletions
|
@ -1905,6 +1905,7 @@ phutil_register_library_map(array(
|
|||
'ReleephPHIDConstants' => 'applications/releeph/ReleephPHIDConstants.php',
|
||||
'ReleephProject' => 'applications/releeph/storage/ReleephProject.php',
|
||||
'ReleephProjectActionController' => 'applications/releeph/controller/project/ReleephProjectActionController.php',
|
||||
'ReleephProjectController' => 'applications/releeph/controller/ReleephProjectController.php',
|
||||
'ReleephProjectCreateController' => 'applications/releeph/controller/project/ReleephProjectCreateController.php',
|
||||
'ReleephProjectEditController' => 'applications/releeph/controller/project/ReleephProjectEditController.php',
|
||||
'ReleephProjectListController' => 'applications/releeph/controller/project/ReleephProjectListController.php',
|
||||
|
@ -3913,15 +3914,15 @@ phutil_register_library_map(array(
|
|||
'ReleephActiveProjectListView' => 'AphrontView',
|
||||
'ReleephAuthorFieldSpecification' => 'ReleephFieldSpecification',
|
||||
'ReleephBranch' => 'ReleephDAO',
|
||||
'ReleephBranchAccessController' => 'ReleephController',
|
||||
'ReleephBranchAccessController' => 'ReleephProjectController',
|
||||
'ReleephBranchBoxView' => 'AphrontView',
|
||||
'ReleephBranchCommitFieldSpecification' => 'ReleephFieldSpecification',
|
||||
'ReleephBranchCreateController' => 'ReleephController',
|
||||
'ReleephBranchEditController' => 'ReleephController',
|
||||
'ReleephBranchCreateController' => 'ReleephProjectController',
|
||||
'ReleephBranchEditController' => 'ReleephProjectController',
|
||||
'ReleephBranchEditor' => 'PhabricatorEditor',
|
||||
'ReleephBranchNamePreviewController' => 'PhabricatorController',
|
||||
'ReleephBranchPreviewView' => 'AphrontFormControl',
|
||||
'ReleephBranchViewController' => 'ReleephController',
|
||||
'ReleephBranchViewController' => 'ReleephProjectController',
|
||||
'ReleephCommitFinderException' => 'Exception',
|
||||
'ReleephCommitMessageFieldSpecification' => 'ReleephFieldSpecification',
|
||||
'ReleephController' => 'PhabricatorController',
|
||||
|
@ -3945,23 +3946,24 @@ phutil_register_library_map(array(
|
|||
0 => 'ReleephDAO',
|
||||
1 => 'PhabricatorPolicyInterface',
|
||||
),
|
||||
'ReleephProjectActionController' => 'ReleephController',
|
||||
'ReleephProjectCreateController' => 'ReleephController',
|
||||
'ReleephProjectEditController' => 'ReleephController',
|
||||
'ReleephProjectActionController' => 'ReleephProjectController',
|
||||
'ReleephProjectController' => 'ReleephController',
|
||||
'ReleephProjectCreateController' => 'ReleephProjectController',
|
||||
'ReleephProjectEditController' => 'ReleephProjectController',
|
||||
'ReleephProjectListController' => 'PhabricatorController',
|
||||
'ReleephProjectQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'ReleephProjectView' => 'AphrontView',
|
||||
'ReleephProjectViewController' => 'ReleephController',
|
||||
'ReleephProjectViewController' => 'ReleephProjectController',
|
||||
'ReleephReasonFieldSpecification' => 'ReleephFieldSpecification',
|
||||
'ReleephRequest' =>
|
||||
array(
|
||||
0 => 'ReleephDAO',
|
||||
1 => 'PhabricatorPolicyInterface',
|
||||
),
|
||||
'ReleephRequestActionController' => 'ReleephController',
|
||||
'ReleephRequestCommentController' => 'ReleephController',
|
||||
'ReleephRequestDifferentialCreateController' => 'ReleephController',
|
||||
'ReleephRequestEditController' => 'ReleephController',
|
||||
'ReleephRequestActionController' => 'ReleephProjectController',
|
||||
'ReleephRequestCommentController' => 'ReleephProjectController',
|
||||
'ReleephRequestDifferentialCreateController' => 'ReleephProjectController',
|
||||
'ReleephRequestEditController' => 'ReleephProjectController',
|
||||
'ReleephRequestEvent' => 'ReleephDAO',
|
||||
'ReleephRequestException' => 'Exception',
|
||||
'ReleephRequestHeaderListView' => 'AphrontView',
|
||||
|
@ -3977,7 +3979,7 @@ phutil_register_library_map(array(
|
|||
'ReleephRequestTransactionalEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'ReleephRequestTypeaheadControl' => 'AphrontFormControl',
|
||||
'ReleephRequestTypeaheadController' => 'PhabricatorTypeaheadDatasourceController',
|
||||
'ReleephRequestViewController' => 'ReleephController',
|
||||
'ReleephRequestViewController' => 'ReleephProjectController',
|
||||
'ReleephRequestorFieldSpecification' => 'ReleephFieldSpecification',
|
||||
'ReleephRevisionFieldSpecification' => 'ReleephFieldSpecification',
|
||||
'ReleephRiskFieldSpecification' => 'ReleephFieldSpecification',
|
||||
|
|
|
@ -2,110 +2,6 @@
|
|||
|
||||
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) {
|
||||
$page = $this->buildStandardPageView();
|
||||
|
||||
|
|
109
src/applications/releeph/controller/ReleephProjectController.php
Normal file
109
src/applications/releeph/controller/ReleephProjectController.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
final class ReleephBranchAccessController extends ReleephController {
|
||||
final class ReleephBranchAccessController extends ReleephProjectController {
|
||||
|
||||
private $action;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
final class ReleephBranchCreateController extends ReleephController {
|
||||
final class ReleephBranchCreateController extends ReleephProjectController {
|
||||
|
||||
public function processRequest() {
|
||||
$releeph_project = $this->getReleephProject();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
final class ReleephBranchEditController extends ReleephController {
|
||||
final class ReleephBranchEditController extends ReleephProjectController {
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class ReleephBranchNamePreviewController
|
||||
extends PhabricatorController {
|
||||
extends ReleephController {
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
final class ReleephBranchViewController extends ReleephController {
|
||||
final class ReleephBranchViewController extends ReleephProjectController {
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
final class ReleephProjectActionController extends ReleephController {
|
||||
final class ReleephProjectActionController extends ReleephProjectController {
|
||||
|
||||
private $action;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
final class ReleephProjectCreateController extends ReleephController {
|
||||
final class ReleephProjectCreateController extends ReleephProjectController {
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
final class ReleephProjectEditController extends ReleephController {
|
||||
final class ReleephProjectEditController extends ReleephProjectController {
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
final class ReleephProjectListController extends PhabricatorController {
|
||||
final class ReleephProjectListController extends ReleephController {
|
||||
|
||||
private $filter;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
final class ReleephProjectViewController extends ReleephController {
|
||||
final class ReleephProjectViewController extends ReleephProjectController {
|
||||
|
||||
public function processRequest() {
|
||||
// Load all branches
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
final class ReleephRequestActionController extends ReleephController {
|
||||
final class ReleephRequestActionController extends ReleephProjectController {
|
||||
|
||||
private $action;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class ReleephRequestCommentController
|
||||
extends ReleephController {
|
||||
extends ReleephProjectController {
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class ReleephRequestDifferentialCreateController
|
||||
extends ReleephController {
|
||||
extends ReleephProjectController {
|
||||
|
||||
private $revision;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
final class ReleephRequestEditController extends ReleephController {
|
||||
final class ReleephRequestEditController extends ReleephProjectController {
|
||||
|
||||
private $id;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
final class ReleephRequestViewController extends ReleephController {
|
||||
final class ReleephRequestViewController extends ReleephProjectController {
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
|
|
Loading…
Reference in a new issue