mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
First stab at a conduit method for creating projects.
Summary: This code is mostly lifted from the PhabricatorProjectCreateController. Test Plan: currently untested Reviewers: rush898, #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley, aklapper, Korvin Maniphest Tasks: T5691 Differential Revision: https://secure.phabricator.com/D10036
This commit is contained in:
parent
1e375c97c5
commit
5f82705e12
2 changed files with 93 additions and 0 deletions
|
@ -245,4 +245,35 @@ abstract class ConduitAPIMethod
|
|||
return null;
|
||||
}
|
||||
|
||||
protected function hasApplicationCapability(
|
||||
$capability,
|
||||
PhabricatorUser $viewer) {
|
||||
|
||||
$application = $this->getApplication();
|
||||
|
||||
if (!$application) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return PhabricatorPolicyFilter::hasCapability(
|
||||
$viewer,
|
||||
$application,
|
||||
$capability);
|
||||
}
|
||||
|
||||
protected function requireApplicationCapability(
|
||||
$capability,
|
||||
PhabricatorUser $viewer) {
|
||||
|
||||
$application = $this->getApplication();
|
||||
if (!$application) {
|
||||
return;
|
||||
}
|
||||
|
||||
PhabricatorPolicyFilter::requireCapability(
|
||||
$viewer,
|
||||
$this->getApplication(),
|
||||
$capability);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
final class ProjectCreateConduitAPIMethod extends ProjectConduitAPIMethod {
|
||||
|
||||
public function getAPIMethodName() {
|
||||
return 'project.create';
|
||||
}
|
||||
|
||||
public function getMethodDescription() {
|
||||
return pht('Create a project.');
|
||||
}
|
||||
|
||||
public function defineParamTypes() {
|
||||
return array(
|
||||
'name' => 'required string',
|
||||
'members' => 'optional list<phid>',
|
||||
);
|
||||
}
|
||||
|
||||
public function defineReturnType() {
|
||||
return 'dict';
|
||||
}
|
||||
|
||||
public function defineErrorTypes() {
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function execute(ConduitAPIRequest $request) {
|
||||
$user = $request->getUser();
|
||||
|
||||
$this->requireApplicationCapability(
|
||||
ProjectCreateProjectsCapability::CAPABILITY,
|
||||
$user);
|
||||
|
||||
$project = PhabricatorProject::initializeNewProject($user);
|
||||
$type_name = PhabricatorProjectTransaction::TYPE_NAME;
|
||||
$members = $request->getValue('members');
|
||||
$xactions = array();
|
||||
|
||||
$xactions[] = id(new PhabricatorProjectTransaction())
|
||||
->setTransactionType($type_name)
|
||||
->setNewValue($request->getValue('name'));
|
||||
|
||||
$xactions[] = id(new PhabricatorProjectTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
|
||||
->setMetadataValue('edge:type', PhabricatorEdgeConfig::TYPE_PROJ_MEMBER)
|
||||
->setNewValue(
|
||||
array(
|
||||
'+' => array_fuse($members),
|
||||
));
|
||||
|
||||
$editor = id(new PhabricatorProjectTransactionEditor())
|
||||
->setActor($user)
|
||||
->setContinueOnNoEffect(true)
|
||||
->setContentSourceFromConduitRequest($request);
|
||||
|
||||
$editor->applyTransactions($project, $xactions);
|
||||
|
||||
return $this->buildProjectInfoDictionary($project);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue