diff --git a/src/applications/conduit/method/ConduitAPIMethod.php b/src/applications/conduit/method/ConduitAPIMethod.php --- a/src/applications/conduit/method/ConduitAPIMethod.php +++ b/src/applications/conduit/method/ConduitAPIMethod.php @@ -245,4 +245,35 @@ 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); + } + } diff --git a/src/applications/project/conduit/ProjectCreateConduitAPIMethod.php b/src/applications/project/conduit/ProjectCreateConduitAPIMethod.php new file mode 100644 --- /dev/null +++ b/src/applications/project/conduit/ProjectCreateConduitAPIMethod.php @@ -0,0 +1,62 @@ + 'required string', + 'members' => 'optional list', + ); + } + + 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); + } + +}