Page MenuHomePhabricator

D10036.id.diff
No OneTemporary

D10036.id.diff

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 @@
+<?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);
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Sat, Feb 1, 7:08 AM (15 h, 14 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7081093
Default Alt Text
D10036.id.diff (2 KB)

Event Timeline