1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 03:50:54 +01:00
phorge-phorge/src/applications/maniphest/controller/ManiphestBatchEditController.php

218 lines
6.3 KiB
PHP
Raw Normal View History

<?php
final class ManiphestBatchEditController extends ManiphestController {
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$this->requireApplicationCapability(
ManiphestBulkEditCapability::CAPABILITY);
$project = null;
$board_id = $request->getInt('board');
if ($board_id) {
$project = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withIDs(array($board_id))
->executeOne();
if (!$project) {
return new Aphront404Response();
}
}
$task_ids = $request->getArr('batch');
if (!$task_ids) {
$task_ids = $request->getStrList('batch');
}
if (!$task_ids) {
throw new Exception(
pht(
'No tasks are selected.'));
}
$tasks = id(new ManiphestTaskQuery())
->setViewer($viewer)
->withIDs($task_ids)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->needSubscriberPHIDs(true)
Maniphest - introduce needProjectPHIDs Summary: Ref T5245. This is some of the associated cleanup there. Test Plan: foreach ManiphestTaskQuery site, I made the change (or not) and tested as follows: === Call sites where added needProjectPHIDs === - PhabricatorHomeMainController - loaded the home page - ManiphestBatchEditController - batch edited some tasks (added a project) - ManiphestConduitAPIMethod - tested implicitly when tested ManiphestUpdateConduitAPIMethod - ManiphestInfoConduitAPIMethod - used the method via conduit console with input id : 1 - ManiphestQueryConduitAPIMethod - used the method via conduit console with input ids : [1, 2] - ManiphestUpdateConduitAPIMethod - used the method via conduit with input id : 1 and comment : “asdasds" - ManiphestReportController - viewed “By User” and “By Project” - ManiphestSubpriorityController - changed the priority of a task via a drag on manphest home - ManiphestTaskMailReceiver - updated Task 1 via bin/mail receive-test with a comment that is the README - ManiphestTaskSearchEngine - loaded Manifest home page - ManiphestTaskEditController - edited a task - ManiphestTransactionEditor - closed a blocking task - ManiphestTransactionSaveController - commented on a task - PhabricatorProjectProfileController - viewed project with id of 1 that has a few tasks in it - PhabricatorSearchAttachController - merged tasks together - DifferentialTransactionEditor - submit a diff that references a task; commit the diff (thus closing the diff) and the task gets updated - PhabricatorRepositoryCommitMessageParserWorker - submit a diff that references a task; commit the diff (thus closing the diff) and the task gets updated === Calls sites where *did not* add needProjectPHIDs (they do not appear in this revision) === - PhabricatorManiphestApplication - loaded the home page - ManiphestGetTaskTransactionsConduitAPIMethod - used the method via conduit console with input ids : [1, 2] ManiphestTaskDetailController - viewed a task with and without associated projects; finished workflow creating a task with a parent - ManiphestTransactionPreviewController - verified transaction preview showed up properly - PhabricatorProjectBoardViewController - viewed a board - PhabricatorProjectMoveController - moved a task around - ManiphestRemarkupRule - made a task reference like {T123} - ManiphestTaskQuery - executed a custom query for all tasks with page size of 2 and paginated through some tasks - ManiphestTaskPHIDType - nothing random seems broken? =D === Call sites where had to do something funky === - ManiphestHovercardEventListener - loaded hover cards from task mentions Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T5245 Differential Revision: https://secure.phabricator.com/D11004
2014-12-18 22:53:45 +01:00
->needProjectPHIDs(true)
->execute();
if (!$tasks) {
throw new Exception(
pht("You don't have permission to edit any of the selected tasks."));
}
if ($project) {
$cancel_uri = '/project/board/'.$project->getID().'/';
$redirect_uri = $cancel_uri;
} else {
$cancel_uri = '/maniphest/';
$redirect_uri = '/maniphest/?ids='.implode(',', mpull($tasks, 'getID'));
}
$actions = $request->getStr('actions');
if ($actions) {
$actions = phutil_json_decode($actions);
}
if ($request->isFormPost() && $actions) {
$job = PhabricatorWorkerBulkJob::initializeNewJob(
$viewer,
new ManiphestTaskEditBulkJobType(),
array(
'taskPHIDs' => mpull($tasks, 'getPHID'),
'actions' => $actions,
'cancelURI' => $cancel_uri,
'doneURI' => $redirect_uri,
));
$type_status = PhabricatorWorkerBulkJobTransaction::TYPE_STATUS;
$xactions = array();
$xactions[] = id(new PhabricatorWorkerBulkJobTransaction())
->setTransactionType($type_status)
->setNewValue(PhabricatorWorkerBulkJob::STATUS_CONFIRM);
$editor = id(new PhabricatorWorkerBulkJobEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnMissingFields(true)
->applyTransactions($job, $xactions);
return id(new AphrontRedirectResponse())
->setURI($job->getMonitorURI());
}
$handles = ManiphestTaskListView::loadTaskHandles($viewer, $tasks);
$list = new ManiphestTaskListView();
$list->setTasks($tasks);
$list->setUser($viewer);
$list->setHandles($handles);
$template = new AphrontTokenizerTemplateView();
$template = $template->render();
$projects_source = new PhabricatorProjectDatasource();
$mailable_source = new PhabricatorMetaMTAMailableDatasource();
$mailable_source->setViewer($viewer);
$owner_source = new ManiphestAssigneeDatasource();
$owner_source->setViewer($viewer);
$spaces_source = id(new PhabricatorSpacesNamespaceDatasource())
->setViewer($viewer);
require_celerity_resource('maniphest-batch-editor');
Javelin::initBehavior(
'maniphest-batch-editor',
array(
'root' => 'maniphest-batch-edit-form',
'tokenizerTemplate' => $template,
'sources' => array(
'project' => array(
'src' => $projects_source->getDatasourceURI(),
'placeholder' => $projects_source->getPlaceholderText(),
'browseURI' => $projects_source->getBrowseURI(),
),
'owner' => array(
'src' => $owner_source->getDatasourceURI(),
'placeholder' => $owner_source->getPlaceholderText(),
'browseURI' => $owner_source->getBrowseURI(),
'limit' => 1,
),
'cc' => array(
'src' => $mailable_source->getDatasourceURI(),
'placeholder' => $mailable_source->getPlaceholderText(),
'browseURI' => $mailable_source->getBrowseURI(),
),
'spaces' => array(
'src' => $spaces_source->getDatasourceURI(),
'placeholder' => $spaces_source->getPlaceholderText(),
'browseURI' => $spaces_source->getBrowseURI(),
'limit' => 1,
),
),
'input' => 'batch-form-actions',
'priorityMap' => ManiphestTaskPriority::getTaskPriorityMap(),
'statusMap' => ManiphestTaskStatus::getTaskStatusMap(),
));
$form = id(new AphrontFormView())
->setUser($viewer)
->addHiddenInput('board', $board_id)
->setID('maniphest-batch-edit-form');
foreach ($tasks as $task) {
$form->appendChild(
phutil_tag(
'input',
array(
'type' => 'hidden',
'name' => 'batch[]',
'value' => $task->getID(),
)));
}
$form->appendChild(
phutil_tag(
'input',
array(
'type' => 'hidden',
'name' => 'actions',
'id' => 'batch-form-actions',
)));
$form->appendChild(
id(new PHUIFormInsetView())
->setTitle(pht('Actions'))
->setRightButton(javelin_tag(
'a',
array(
'href' => '#',
'class' => 'button green',
'sigil' => 'add-action',
'mustcapture' => true,
),
pht('Add Another Action')))
->setContent(javelin_tag(
'table',
array(
'sigil' => 'maniphest-batch-actions',
'class' => 'maniphest-batch-actions-table',
),
'')))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Update Tasks'))
->addCancelButton($cancel_uri));
$title = pht('Batch Editor');
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($title);
$task_box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Selected Tasks'))
->setObjectList($list);
$form_box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Batch Editor'))
->setForm($form);
return $this->buildApplicationPage(
array(
$crumbs,
$task_box,
$form_box,
),
array(
'title' => $title,
));
}
}