@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Mukunda Modell and committed by
epriestley
5f82705e 1e375c97

+93
+31
src/applications/conduit/method/ConduitAPIMethod.php
··· 245 245 return null; 246 246 } 247 247 248 + protected function hasApplicationCapability( 249 + $capability, 250 + PhabricatorUser $viewer) { 251 + 252 + $application = $this->getApplication(); 253 + 254 + if (!$application) { 255 + return false; 256 + } 257 + 258 + return PhabricatorPolicyFilter::hasCapability( 259 + $viewer, 260 + $application, 261 + $capability); 262 + } 263 + 264 + protected function requireApplicationCapability( 265 + $capability, 266 + PhabricatorUser $viewer) { 267 + 268 + $application = $this->getApplication(); 269 + if (!$application) { 270 + return; 271 + } 272 + 273 + PhabricatorPolicyFilter::requireCapability( 274 + $viewer, 275 + $this->getApplication(), 276 + $capability); 277 + } 278 + 248 279 }
+62
src/applications/project/conduit/ProjectCreateConduitAPIMethod.php
··· 1 + <?php 2 + 3 + final class ProjectCreateConduitAPIMethod extends ProjectConduitAPIMethod { 4 + 5 + public function getAPIMethodName() { 6 + return 'project.create'; 7 + } 8 + 9 + public function getMethodDescription() { 10 + return pht('Create a project.'); 11 + } 12 + 13 + public function defineParamTypes() { 14 + return array( 15 + 'name' => 'required string', 16 + 'members' => 'optional list<phid>', 17 + ); 18 + } 19 + 20 + public function defineReturnType() { 21 + return 'dict'; 22 + } 23 + 24 + public function defineErrorTypes() { 25 + return array(); 26 + } 27 + 28 + protected function execute(ConduitAPIRequest $request) { 29 + $user = $request->getUser(); 30 + 31 + $this->requireApplicationCapability( 32 + ProjectCreateProjectsCapability::CAPABILITY, 33 + $user); 34 + 35 + $project = PhabricatorProject::initializeNewProject($user); 36 + $type_name = PhabricatorProjectTransaction::TYPE_NAME; 37 + $members = $request->getValue('members'); 38 + $xactions = array(); 39 + 40 + $xactions[] = id(new PhabricatorProjectTransaction()) 41 + ->setTransactionType($type_name) 42 + ->setNewValue($request->getValue('name')); 43 + 44 + $xactions[] = id(new PhabricatorProjectTransaction()) 45 + ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) 46 + ->setMetadataValue('edge:type', PhabricatorEdgeConfig::TYPE_PROJ_MEMBER) 47 + ->setNewValue( 48 + array( 49 + '+' => array_fuse($members), 50 + )); 51 + 52 + $editor = id(new PhabricatorProjectTransactionEditor()) 53 + ->setActor($user) 54 + ->setContinueOnNoEffect(true) 55 + ->setContentSourceFromConduitRequest($request); 56 + 57 + $editor->applyTransactions($project, $xactions); 58 + 59 + return $this->buildProjectInfoDictionary($project); 60 + } 61 + 62 + }