Commit 3b0ca7b7 authored by Chad Little's avatar Chad Little
Browse files

Partially update Maniphest for handleProcess

Summary: Starts conversion of Maniphest to handleProcess, chopping up to reduce errors.

Test Plan: New Task, Edit Task, Change Priority, Move on workboard, view reports, batch edit tasks

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T8628

Differential Revision: https://secure.phabricator.com/D13773
parent f087bce2
......@@ -2,27 +2,19 @@
final class ManiphestExportController extends ManiphestController {
private $key;
public function willProcessRequest(array $data) {
$this->key = $data['key'];
return $this;
}
/**
* @phutil-external-symbol class PHPExcel
* @phutil-external-symbol class PHPExcel_IOFactory
* @phutil-external-symbol class PHPExcel_Style_NumberFormat
* @phutil-external-symbol class PHPExcel_Cell_DataType
*/
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$key = $request->getURIData('key');
$ok = @include_once 'PHPExcel.php';
if (!$ok) {
$dialog = new AphrontDialogView();
$dialog->setUser($user);
$dialog = $this->newDialog();
$inst1 = pht(
'This system does not have PHPExcel installed. This software '.
......@@ -54,14 +46,14 @@ final class ManiphestExportController extends ManiphestController {
// for that here, since it fatals if we don't have the ZipArchive class.
$saved = id(new PhabricatorSavedQueryQuery())
->setViewer($user)
->withQueryKeys(array($this->key))
->setViewer($viewer)
->withQueryKeys(array($key))
->executeOne();
if (!$saved) {
$engine = id(new ManiphestTaskSearchEngine())
->setViewer($user);
if ($engine->isBuiltinQuery($this->key)) {
$saved = $engine->buildSavedQueryFromBuiltin($this->key);
->setViewer($viewer);
if ($engine->isBuiltinQuery($key)) {
$saved = $engine->buildSavedQueryFromBuiltin($key);
}
if (!$saved) {
return new Aphront404Response();
......@@ -76,7 +68,7 @@ final class ManiphestExportController extends ManiphestController {
if (!$request->isDialogFormPost()) {
$dialog = new AphrontDialogView();
$dialog->setUser($user);
$dialog->setUser($viewer);
$dialog->setTitle(pht('Export Tasks to Excel'));
$dialog->appendChild(
......@@ -108,22 +100,22 @@ final class ManiphestExportController extends ManiphestController {
$saved->setParameter('limit', PHP_INT_MAX);
$engine = id(new ManiphestTaskSearchEngine())
->setViewer($user);
->setViewer($viewer);
$query = $engine->buildQueryFromSavedQuery($saved);
$query->setViewer($user);
$query->setViewer($viewer);
$tasks = $query->execute();
$all_projects = array_mergev(mpull($tasks, 'getProjectPHIDs'));
$all_assigned = mpull($tasks, 'getOwnerPHID');
$handles = id(new PhabricatorHandleQuery())
->setViewer($user)
->setViewer($viewer)
->withPHIDs(array_merge($all_projects, $all_assigned))
->execute();
$workbook = new PHPExcel();
$format->buildWorkbook($workbook, $tasks, $handles, $user);
$format->buildWorkbook($workbook, $tasks, $handles, $viewer);
$writer = PHPExcel_IOFactory::createWriter($workbook, 'Excel2007');
ob_start();
......
......@@ -4,13 +4,9 @@ final class ManiphestReportController extends ManiphestController {
private $view;
public function willProcessRequest(array $data) {
$this->view = idx($data, 'view');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$this->view = $request->getURIData('view');
if ($request->isFormPost()) {
$uri = $request->getRequestURI();
......@@ -64,7 +60,7 @@ final class ManiphestReportController extends ManiphestController {
public function renderBurn() {
$request = $this->getRequest();
$user = $request->getUser();
$viewer = $request->getUser();
$handle = null;
......@@ -132,7 +128,7 @@ final class ManiphestReportController extends ManiphestController {
$day_bucket = phabricator_format_local_time(
$row['dateCreated'],
$user,
$viewer,
'Yz');
$day_buckets[$day_bucket] = $row['dateCreated'];
if (empty($stats[$day_bucket])) {
......@@ -166,12 +162,12 @@ final class ManiphestReportController extends ManiphestController {
$week_bucket = phabricator_format_local_time(
$epoch,
$user,
$viewer,
'YW');
if ($week_bucket != $last_week) {
if ($week) {
$rows[] = $this->formatBurnRow(
pht('Week of %s', phabricator_date($last_week_epoch, $user)),
pht('Week of %s', phabricator_date($last_week_epoch, $viewer)),
$week);
$rowc[] = 'week';
}
......@@ -182,12 +178,12 @@ final class ManiphestReportController extends ManiphestController {
$month_bucket = phabricator_format_local_time(
$epoch,
$user,
$viewer,
'Ym');
if ($month_bucket != $last_month) {
if ($month) {
$rows[] = $this->formatBurnRow(
phabricator_format_local_time($last_month_epoch, $user, 'F, Y'),
phabricator_format_local_time($last_month_epoch, $viewer, 'F, Y'),
$month);
$rowc[] = 'month';
}
......@@ -196,7 +192,7 @@ final class ManiphestReportController extends ManiphestController {
$last_month_epoch = $epoch;
}
$rows[] = $this->formatBurnRow(phabricator_date($epoch, $user), $info);
$rows[] = $this->formatBurnRow(phabricator_date($epoch, $viewer), $info);
$rowc[] = null;
$week['open'] += $info['open'];
$week['close'] += $info['close'];
......@@ -315,10 +311,10 @@ final class ManiphestReportController extends ManiphestController {
private function renderReportFilters(array $tokens, $has_window) {
$request = $this->getRequest();
$user = $request->getUser();
$viewer = $request->getUser();
$form = id(new AphrontFormView())
->setUser($user)
->setUser($viewer)
->appendControl(
id(new AphrontFormTokenizerControl())
->setDatasource(new PhabricatorProjectDatasource())
......@@ -390,11 +386,11 @@ final class ManiphestReportController extends ManiphestController {
public function renderOpenTasks() {
$request = $this->getRequest();
$user = $request->getUser();
$viewer = $request->getUser();
$query = id(new ManiphestTaskQuery())
->setViewer($user)
->setViewer($viewer)
->withStatuses(ManiphestTaskStatus::getOpenStatusConstants());
switch ($this->view) {
......@@ -420,7 +416,7 @@ final class ManiphestReportController extends ManiphestController {
$recently_closed = $this->loadRecentlyClosedTasks();
$date = phabricator_date(time(), $user);
$date = phabricator_date(time(), $viewer);
switch ($this->view) {
case 'user':
......@@ -615,7 +611,7 @@ final class ManiphestReportController extends ManiphestController {
$cclass[] = 'n';
list($ignored, $window_epoch) = $this->getWindow();
$edate = phabricator_datetime($window_epoch, $user);
$edate = phabricator_datetime($window_epoch, $viewer);
$cname[] = javelin_tag(
'span',
array(
......@@ -726,7 +722,7 @@ final class ManiphestReportController extends ManiphestController {
*/
private function getWindow() {
$request = $this->getRequest();
$user = $request->getUser();
$viewer = $request->getUser();
$window_str = $this->getRequest()->getStr('window', '12 AM 7 days ago');
......@@ -736,7 +732,7 @@ final class ManiphestReportController extends ManiphestController {
// Do locale-aware parsing so that the user's timezone is assumed for
// time windows like "3 PM", rather than assuming the server timezone.
$window_epoch = PhabricatorTime::parseLocalTime($window_str, $user);
$window_epoch = PhabricatorTime::parseLocalTime($window_str, $viewer);
if (!$window_epoch) {
$error = 'Invalid';
$window_epoch = time() - (60 * 60 * 24 * 7);
......
......@@ -2,16 +2,15 @@
final class ManiphestSubpriorityController extends ManiphestController {
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
if (!$request->validateCSRF()) {
return new Aphront403Response();
}
$task = id(new ManiphestTaskQuery())
->setViewer($user)
->setViewer($viewer)
->withIDs(array($request->getInt('task')))
->needProjectPHIDs(true)
->requireCapabilities(
......@@ -26,7 +25,7 @@ final class ManiphestSubpriorityController extends ManiphestController {
if ($request->getInt('after')) {
$after_task = id(new ManiphestTaskQuery())
->setViewer($user)
->setViewer($viewer)
->withIDs(array($request->getInt('after')))
->executeOne();
if (!$after_task) {
......@@ -52,7 +51,7 @@ final class ManiphestSubpriorityController extends ManiphestController {
->setNewValue($sub);
$editor = id(new ManiphestTransactionEditor())
->setActor($user)
->setActor($viewer)
->setContinueOnMissingFields(true)
->setContinueOnNoEffect(true)
->setContentSourceFromRequest($request);
......
......@@ -2,27 +2,21 @@
final class ManiphestTaskDetailController extends ManiphestController {
private $id;
public function shouldAllowPublic() {
return true;
}
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$id = $request->getURIData('id');
$e_title = null;
$priority_map = ManiphestTaskPriority::getTaskPriorityMap();
$task = id(new ManiphestTaskQuery())
->setViewer($user)
->withIDs(array($this->id))
->setViewer($viewer)
->withIDs(array($id))
->needSubscriberPHIDs(true)
->executeOne();
if (!$task) {
......@@ -33,7 +27,7 @@ final class ManiphestTaskDetailController extends ManiphestController {
$parent_task = null;
if ($workflow && is_numeric($workflow)) {
$parent_task = id(new ManiphestTaskQuery())
->setViewer($user)
->setViewer($viewer)
->withIDs(array($workflow))
->executeOne();
}
......@@ -42,7 +36,7 @@ final class ManiphestTaskDetailController extends ManiphestController {
$task,
PhabricatorCustomField::ROLE_VIEW);
$field_list
->setViewer($user)
->setViewer($viewer)
->readFieldsFromStorage($task);
$e_commit = ManiphestTaskHasCommitEdgeType::EDGECONST;
......@@ -83,7 +77,7 @@ final class ManiphestTaskDetailController extends ManiphestController {
}
$phids = array_keys($phids);
$handles = $user->loadHandles($phids);
$handles = $viewer->loadHandles($phids);
$info_view = null;
if ($parent_task) {
......@@ -115,7 +109,7 @@ final class ManiphestTaskDetailController extends ManiphestController {
}
$engine = new PhabricatorMarkupEngine();
$engine->setViewer($user);
$engine->setViewer($viewer);
$engine->setContextObject($task);
$engine->addObject($task, ManiphestTask::MARKUP_FIELD_DESCRIPTION);
......@@ -169,12 +163,13 @@ final class ManiphestTaskDetailController extends ManiphestController {
}
$default_claim = array(
$user->getPHID() => $user->getUsername().' ('.$user->getRealName().')',
$viewer->getPHID() => $viewer->getUsername().
' ('.$viewer->getRealName().')',
);
$draft = id(new PhabricatorDraft())->loadOneWhere(
'authorPHID = %s AND draftKey = %s',
$user->getPHID(),
$viewer->getPHID(),
$task->getPHID());
if ($draft) {
$draft_text = $draft->getDraft();
......@@ -188,7 +183,7 @@ final class ManiphestTaskDetailController extends ManiphestController {
$comment_form = new AphrontFormView();
$comment_form
->setUser($user)
->setUser($viewer)
->setWorkflow(true)
->setAction('/maniphest/transaction/save/')
->setEncType('multipart/form-data')
......@@ -249,12 +244,12 @@ final class ManiphestTaskDetailController extends ManiphestController {
->setControlStyle('display: none'))
->appendChild(
id(new PhabricatorRemarkupControl())
->setUser($user)
->setUser($viewer)
->setLabel(pht('Comments'))
->setName('comments')
->setValue($draft_text)
->setID('transaction-comments')
->setUser($user))
->setUser($viewer))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Submit')));
......@@ -288,7 +283,7 @@ final class ManiphestTaskDetailController extends ManiphestController {
);
// TODO: Initializing these behaviors for logged out users fatals things.
if ($user->isLoggedIn()) {
if ($viewer->isLoggedIn()) {
Javelin::initBehavior('maniphest-transaction-controls', array(
'select' => 'transaction-action',
'controlMap' => $control_map,
......@@ -330,11 +325,11 @@ final class ManiphestTaskDetailController extends ManiphestController {
$task, $field_list, $edges, $actions, $handles);
$description = $this->buildDescriptionView($task, $engine);
if (!$user->isLoggedIn()) {
if (!$viewer->isLoggedIn()) {
// TODO: Eventually, everything should run through this. For now, we're
// only using it to get a consistent "Login to Comment" button.
$comment_box = id(new PhabricatorApplicationTransactionCommentView())
->setUser($user)
->setUser($viewer)
->setRequestURI($request->getRequestURI());
$preview_panel = null;
} else {
......
......@@ -2,15 +2,9 @@
final class ManiphestTaskEditController extends ManiphestController {
private $id;
public function willProcessRequest(array $data) {
$this->id = idx($data, 'id');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$id = $request->getURIData('id');
$response_type = $request->getStr('responseType', 'task');
$order = $request->getStr('order', PhabricatorProjectColumn::DEFAULT_ORDER);
......@@ -26,22 +20,22 @@ final class ManiphestTaskEditController extends ManiphestController {
$can_edit_status = $this->hasApplicationCapability(
ManiphestEditStatusCapability::CAPABILITY);
$can_create_projects = PhabricatorPolicyFilter::hasCapability(
$user,
$viewer,
PhabricatorApplication::getByClass('PhabricatorProjectApplication'),
ProjectCreateProjectsCapability::CAPABILITY);
$parent_task = null;
$template_id = null;
if ($this->id) {
if ($id) {
$task = id(new ManiphestTaskQuery())
->setViewer($user)
->setViewer($viewer)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->withIDs(array($this->id))
->withIDs(array($id))
->needSubscriberPHIDs(true)
->needProjectPHIDs(true)
->executeOne();
......@@ -49,7 +43,7 @@ final class ManiphestTaskEditController extends ManiphestController {
return new Aphront404Response();
}
} else {
$task = ManiphestTask::initializeNewTask($user);
$task = ManiphestTask::initializeNewTask($viewer);
// We currently do not allow you to set the task status when creating
// a new task, although now that statuses are custom it might make
......@@ -82,7 +76,7 @@ final class ManiphestTaskEditController extends ManiphestController {
}
$default_projects = id(new PhabricatorObjectQuery())
->setViewer($user)
->setViewer($viewer)
->withNames($tokens)
->execute();
$default_projects = mpull($default_projects, 'getPHID');
......@@ -109,12 +103,12 @@ final class ManiphestTaskEditController extends ManiphestController {
$assign = $request->getStr('assign');
if (strlen($assign)) {
$assign_user = id(new PhabricatorPeopleQuery())
->setViewer($user)
->setViewer($viewer)
->withUsernames(array($assign))
->executeOne();
if (!$assign_user) {
$assign_user = id(new PhabricatorPeopleQuery())
->setViewer($user)
->setViewer($viewer)
->withPHIDs(array($assign))
->executeOne();
}
......@@ -132,7 +126,7 @@ final class ManiphestTaskEditController extends ManiphestController {
$parent_id = $request->getInt('parent');
if (strlen($parent_id)) {
$parent_task = id(new ManiphestTaskQuery())
->setViewer($user)
->setViewer($viewer)
->withIDs(array($parent_id))
->executeOne();
if (!$parent_task) {
......@@ -150,7 +144,7 @@ final class ManiphestTaskEditController extends ManiphestController {
$field_list = PhabricatorCustomField::getObjectFields(
$task,
PhabricatorCustomField::ROLE_EDIT);
$field_list->setViewer($user);
$field_list->setViewer($viewer);
$field_list->readFieldsFromStorage($task);
$aux_fields = $field_list->getFields();
......@@ -250,7 +244,7 @@ final class ManiphestTaskEditController extends ManiphestController {
// allow for putting a task in a project column at creation -only-
if (!$task->getID() && $column_phid && $projects) {
$column = id(new PhabricatorProjectColumnQuery())
->setViewer($user)
->setViewer($viewer)
->withProjectPHIDs($projects)
->withPHIDs(array($column_phid))
->executeOne();
......@@ -329,7 +323,7 @@ final class ManiphestTaskEditController extends ManiphestController {
'new' => $is_new,
'transactions' => $transactions,
));
$event->setUser($user);
$event->setUser($viewer);
$event->setAphrontRequest($request);
PhutilEventEngine::dispatchEvent($event);
......@@ -337,7 +331,7 @@ final class ManiphestTaskEditController extends ManiphestController {
$transactions = $event->getValue('transactions');
$editor = id(new ManiphestTransactionEditor())
->setActor($user)
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->applyTransactions($task, $transactions);
......@@ -349,7 +343,7 @@ final class ManiphestTaskEditController extends ManiphestController {
'new' => $is_new,
'transactions' => $transactions,
));
$event->setUser($user);
$event->setUser($viewer);
$event->setAphrontRequest($request);
PhutilEventEngine::dispatchEvent($event);
}
......@@ -372,19 +366,19 @@ final class ManiphestTaskEditController extends ManiphestController {
$owner = null;
if ($task->getOwnerPHID()) {
$owner = id(new PhabricatorHandleQuery())
->setViewer($user)
->setViewer($viewer)
->withPHIDs(array($task->getOwnerPHID()))
->executeOne();
}
$tasks = id(new ProjectBoardTaskCard())
->setViewer($user)
->setViewer($viewer)
->setTask($task)
->setOwner($owner)
->setCanEdit(true)
->getItem();
$column = id(new PhabricatorProjectColumnQuery())
->setViewer($user)
->setViewer($viewer)
->withPHIDs(array($request->getStr('columnPHID')))
->executeOne();
if (!$column) {
......@@ -403,13 +397,13 @@ final class ManiphestTaskEditController extends ManiphestController {
}
$positions = id(new PhabricatorProjectColumnPositionQuery())
->setViewer($user)
->setViewer($viewer)
->withColumns(array($column))
->execute();
$task_phids = mpull($positions, 'getObjectPHID');
$column_tasks = id(new ManiphestTaskQuery())
->setViewer($user)
->setViewer($viewer)
->withPHIDs($task_phids)
->execute();
......@@ -461,11 +455,11 @@ final class ManiphestTaskEditController extends ManiphestController {
} else {
if (!$task->getID()) {
$task->attachSubscriberPHIDs(array(
$user->getPHID(),
$viewer->getPHID(),
));
if ($template_id) {
$template_task = id(new ManiphestTaskQuery())
->setViewer($user)
->setViewer($viewer)
->withIDs(array($template_id))
->needSubscriberPHIDs(true)
->needProjectPHIDs(true)
......@@ -473,7 +467,7 @@ final class ManiphestTaskEditController extends ManiphestController {
if ($template_task) {
$cc_phids = array_unique(array_merge(
$template_task->getSubscriberPHIDs(),
array($user->getPHID())));
array($viewer->getPHID())));
$task->attachSubscriberPHIDs($cc_phids);
$task->attachProjectPHIDs($template_task->getProjectPHIDs());
$task->setOwnerPHID($template_task->getOwnerPHID());
......@@ -499,7 +493,7 @@ final class ManiphestTaskEditController extends ManiphestController {
if ($fields) {
id(new PhabricatorCustomFieldList($fields))
->setViewer($user)
->setViewer($viewer)
->readFieldsFromStorage($template_task);
foreach ($fields as $key => $field) {
......@@ -563,7 +557,7 @@ final class ManiphestTaskEditController extends ManiphestController {
$form = new AphrontFormView();
$form
->setUser($user)
->setUser($viewer)
->addHiddenInput('template', $template_id)
->addHiddenInput('responseType', $response_type)
->addHiddenInput('order', $order)
......@@ -575,7 +569,7 @@ final class ManiphestTaskEditController extends ManiphestController {
->appendChild(
id(new AphrontFormStaticControl())
->setLabel(pht('Parent Task'))