summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Johnson <christopher.johnson@wikimedia.de>2015-04-04 10:52:33 (GMT)
committerChristopher Johnson <christopher.johnson@wikimedia.de>2015-04-09 10:12:12 (GMT)
commit892251823ba4db1d1fa86708ecd4e8a0db91feba (patch)
treed823398cd6d30d8b28d79ca55f46b7240bbfb87c
parentee514afdda2daa770563f71c4593ea335c31012c (diff)
downloadphabricator-sprint-892251823ba4db1d1fa86708ecd4e8a0db91feba.tar.gz
phabricator-sprint-892251823ba4db1d1fa86708ecd4e8a0db91feba.tar.xz
adds Conduit methods for Sprint creation
Bug: T91529 Bug: T89859 Bug: T91516 Bug: T95079 Change-Id: If1ce84eb13605cb3c0373cc6392e9135be8eec02
-rw-r--r--src/__phutil_library_map__.php5
-rw-r--r--src/conduit/SprintConduitAPIMethod.php48
-rw-r--r--src/conduit/SprintCreateConduitAPIMethod.php92
-rw-r--r--src/controller/SprintController.php2
-rw-r--r--src/view/burndown/BurndownChartExporter.php11
5 files changed, 146 insertions, 12 deletions
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
index 4536c4e..296ba37 100644
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -14,6 +14,7 @@ phutil_register_library_map(array(
'BoardDataProvider' => 'storage/BoardDataProvider.php',
'BoardDataTableView' => 'view/burndown/BoardDataTableView.php',
'BurndownActionMenuEventListener' => 'events/BurndownActionMenuEventListener.php',
+ 'BurndownChartExporter' => 'view/burndown/BurndownChartExporter.php',
'BurndownChartView' => 'view/burndown/BurndownChartView.php',
'BurndownDataDate' => 'util/BurndownDataDate.php',
'BurndownException' => 'exception/BurndownException.php',
@@ -37,9 +38,11 @@ phutil_register_library_map(array(
'SprintBoardTaskEditController' => 'controller/board/SprintBoardTaskEditController.php',
'SprintBoardViewController' => 'controller/board/SprintBoardViewController.php',
'SprintColumnTransaction' => 'storage/SprintColumnTransaction.php',
+ 'SprintConduitAPIMethod' => 'conduit/SprintConduitAPIMethod.php',
'SprintConstants' => 'constants/SprintConstants.php',
'SprintController' => 'controller/SprintController.php',
'SprintControllerTest' => 'tests/SprintControllerTest.php',
+ 'SprintCreateConduitAPIMethod' => 'conduit/SprintCreateConduitAPIMethod.php',
'SprintCustomFieldTest' => 'tests/SprintCustomFieldTest.php',
'SprintDAO' => 'storage/SprintDAO.php',
'SprintDataView' => 'view/burndown/SprintDataView.php',
@@ -90,8 +93,10 @@ phutil_register_library_map(array(
'SprintBoardReorderController' => 'SprintBoardController',
'SprintBoardTaskEditController' => 'ManiphestController',
'SprintBoardViewController' => 'SprintBoardController',
+ 'SprintConduitAPIMethod' => 'ConduitAPIMethod',
'SprintController' => 'PhabricatorController',
'SprintControllerTest' => 'SprintTestCase',
+ 'SprintCreateConduitAPIMethod' => 'SprintConduitAPIMethod',
'SprintCustomFieldTest' => 'SprintTestCase',
'SprintDAO' => 'PhabricatorLiskDAO',
'SprintDataView' => 'SprintView',
diff --git a/src/conduit/SprintConduitAPIMethod.php b/src/conduit/SprintConduitAPIMethod.php
new file mode 100644
index 0000000..2cf96f8
--- /dev/null
+++ b/src/conduit/SprintConduitAPIMethod.php
@@ -0,0 +1,48 @@
+<?php
+
+abstract class SprintConduitAPIMethod extends ConduitAPIMethod {
+
+ final public function getApplication() {
+ return PhabricatorApplication::getByClass('SprintApplication');
+ }
+
+ protected function buildProjectInfoDictionary(PhabricatorProject $project) {
+ $results = $this->buildProjectInfoDictionaries(array($project));
+ return idx($results, $project->getPHID());
+ }
+
+ protected function buildProjectInfoDictionaries(array $projects) {
+ assert_instances_of($projects, 'PhabricatorProject');
+ if (!$projects) {
+ return array();
+ }
+
+ $result = array();
+ foreach ($projects as $project) {
+
+ $member_phids = $project->getMemberPHIDs();
+ $member_phids = array_values($member_phids);
+
+ $project_slugs = $project->getSlugs();
+ $project_slugs = array_values(mpull($project_slugs, 'getSlug'));
+
+ $project_icon = PhabricatorProjectIcon::getAPIName($project->getIcon());
+
+ $result[$project->getPHID()] = array(
+ 'id' => $project->getID(),
+ 'phid' => $project->getPHID(),
+ 'name' => $project->getName(),
+ 'profileImagePHID' => $project->getProfileImagePHID(),
+ 'icon' => $project_icon,
+ 'color' => $project->getColor(),
+ 'members' => $member_phids,
+ 'slugs' => $project_slugs,
+ 'dateCreated' => $project->getDateCreated(),
+ 'dateModified' => $project->getDateModified(),
+ );
+ }
+
+ return $result;
+ }
+
+}
diff --git a/src/conduit/SprintCreateConduitAPIMethod.php b/src/conduit/SprintCreateConduitAPIMethod.php
new file mode 100644
index 0000000..920e40b
--- /dev/null
+++ b/src/conduit/SprintCreateConduitAPIMethod.php
@@ -0,0 +1,92 @@
+<?php
+
+final class SprintCreateConduitAPIMethod extends SprintConduitAPIMethod {
+
+ public function getAPIMethodName() {
+ return 'sprint.create';
+ }
+
+ public function getMethodDescription() {
+ return pht('Create a Sprint Project');
+ }
+
+ public function defineParamTypes() {
+ return array(
+ 'name' => 'required string ("name")',
+ 'members' => 'optional list ([<phid>]) - empty list enter []',
+ 'startdate' => 'required string ("YYYY-MM-DD H:i")',
+ 'enddate' => 'required string ("YYYY-MM-DD H:i")',
+ );
+ }
+
+ 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',
+ PhabricatorProjectProjectHasMemberEdgeType::EDGECONST)
+ ->setNewValue(
+ array(
+ '+' => array_fuse($members),
+ ));
+
+ $xactions[] = id(new PhabricatorProjectTransaction())
+ ->setTransactionType(PhabricatorProjectTransaction::TYPE_ICON)
+ ->setNewValue('fa-calendar');
+
+ $xactions[] = id(new PhabricatorProjectTransaction())
+ ->setTransactionType(PhabricatorProjectTransaction::TYPE_COLOR)
+ ->setNewValue('green');
+
+ $xactions[] = id(new PhabricatorProjectTransaction())
+ ->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD)
+ ->setMetadataValue('customfield:key', 'isdc:sprint:issprint')
+ ->setOldValue(null)
+ ->setNewValue(1);
+
+ $xactions[] = id(new PhabricatorProjectTransaction())
+ ->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD)
+ ->setMetadataValue('customfield:key', 'isdc:sprint:startdate')
+ ->setOldValue(null)
+ ->setNewValue(strtotime($request->getValue('startdate')));
+
+ $xactions[] = id(new PhabricatorProjectTransaction())
+ ->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD)
+ ->setMetadataValue('customfield:key', 'isdc:sprint:enddate')
+ ->setOldValue(0)
+ ->setNewValue(strtotime($request->getValue('enddate')));
+
+ $editor = id(new PhabricatorProjectTransactionEditor())
+ ->setActor($user)
+ ->setContinueOnNoEffect(true)
+ ->setContentSourceFromConduitRequest($request);
+
+ $editor->applyTransactions($project, $xactions);
+
+ return $this->buildProjectInfoDictionary($project);
+ }
+
+}
diff --git a/src/controller/SprintController.php b/src/controller/SprintController.php
index 461c19e..957a51e 100644
--- a/src/controller/SprintController.php
+++ b/src/controller/SprintController.php
@@ -73,7 +73,7 @@ abstract class SprintController extends PhabricatorController {
$crumbs->addAction(
id(new PHUIListItemView())
->setName(pht('Create Sprint'))
- ->setHref($this->getProjectsURI().'create/')
+ ->setHref('/conduit/method/sprint.create/')
->setIcon('fa-calendar')
->setDisabled(!$can_create));
diff --git a/src/view/burndown/BurndownChartExporter.php b/src/view/burndown/BurndownChartExporter.php
deleted file mode 100644
index f41e889..0000000
--- a/src/view/burndown/BurndownChartExporter.php
+++ /dev/null
@@ -1,11 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: christopher
- * Date: 27.03.15
- * Time: 17:53
- */
-
-class BurndownChartExporter {
-
-}