Differential D8677 Diff 20571 src/applications/maniphest/controller/ManiphestBatchEditController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/maniphest/controller/ManiphestBatchEditController.php
<?php | <?php | ||||
/** | |||||
* @group maniphest | |||||
*/ | |||||
final class ManiphestBatchEditController extends ManiphestController { | final class ManiphestBatchEditController extends ManiphestController { | ||||
public function processRequest() { | public function processRequest() { | ||||
$this->requireApplicationCapability( | $this->requireApplicationCapability( | ||||
ManiphestCapabilityBulkEdit::CAPABILITY); | ManiphestCapabilityBulkEdit::CAPABILITY); | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | public function processRequest() { | ||||
$list = new ManiphestTaskListView(); | $list = new ManiphestTaskListView(); | ||||
$list->setTasks($tasks); | $list->setTasks($tasks); | ||||
$list->setUser($user); | $list->setUser($user); | ||||
$list->setHandles($handles); | $list->setHandles($handles); | ||||
$template = new AphrontTokenizerTemplateView(); | $template = new AphrontTokenizerTemplateView(); | ||||
$template = $template->render(); | $template = $template->render(); | ||||
$first_task = head($tasks); | |||||
$policies = id(new PhabricatorPolicyQuery()) | |||||
->setViewer($user) | |||||
->setObject($first_task) | |||||
->execute(); | |||||
print_r($policies); | |||||
$edit_policy_control = id(new AphrontFormPolicyControl()) | |||||
->setUser($user) | |||||
->setCapability(PhabricatorPolicyCapability::CAN_EDIT) | |||||
->setPolicyObject($first_task) | |||||
->setPolicies($policies) | |||||
->setName('edit_policy'); | |||||
$view_policy_control = id(new AphrontFormPolicyControl()) | |||||
->setUser($user) | |||||
->setCapability(PhabricatorPolicyCapability::CAN_VIEW) | |||||
->setPolicyObject($first_task) | |||||
->setPolicies($policies) | |||||
->setName('view_policy'); | |||||
require_celerity_resource('maniphest-batch-editor'); | require_celerity_resource('maniphest-batch-editor'); | ||||
Javelin::initBehavior( | Javelin::initBehavior( | ||||
'maniphest-batch-editor', | 'maniphest-batch-editor', | ||||
array( | array( | ||||
'root' => 'maniphest-batch-edit-form', | 'root' => 'maniphest-batch-edit-form', | ||||
'tokenizerTemplate' => $template, | 'tokenizerTemplate' => $template, | ||||
'sources' => array( | 'sources' => array( | ||||
'project' => array( | 'project' => array( | ||||
'src' => '/typeahead/common/projects/', | 'src' => '/typeahead/common/projects/', | ||||
'placeholder' => pht('Type a project name...'), | 'placeholder' => pht('Type a project name...'), | ||||
), | ), | ||||
'owner' => array( | 'owner' => array( | ||||
'src' => '/typeahead/common/searchowner/', | 'src' => '/typeahead/common/searchowner/', | ||||
'placeholder' => pht('Type a user name...'), | 'placeholder' => pht('Type a user name...'), | ||||
'limit' => 1, | 'limit' => 1, | ||||
), | ), | ||||
'cc' => array( | 'cc' => array( | ||||
'src' => '/typeahead/common/mailable/', | 'src' => '/typeahead/common/mailable/', | ||||
'placeholder' => pht('Type a user name...'), | 'placeholder' => pht('Type a user name...'), | ||||
) | ) | ||||
), | ), | ||||
'editPolicyControl' => $edit_policy_control, | |||||
'viewPolicyControl' => $view_policy_control, | |||||
'input' => 'batch-form-actions', | 'input' => 'batch-form-actions', | ||||
'priorityMap' => ManiphestTaskPriority::getTaskPriorityMap(), | 'priorityMap' => ManiphestTaskPriority::getTaskPriorityMap(), | ||||
'statusMap' => ManiphestTaskStatus::getTaskStatusMap(), | 'statusMap' => ManiphestTaskStatus::getTaskStatusMap(), | ||||
'actionMap' => $this->getActionMap(), | |||||
)); | )); | ||||
$form = new AphrontFormView(); | $form = new AphrontFormView(); | ||||
$form->setUser($user); | $form->setUser($user); | ||||
$form->setID('maniphest-batch-edit-form'); | $form->setID('maniphest-batch-edit-form'); | ||||
foreach ($tasks as $task) { | foreach ($tasks as $task) { | ||||
$form->appendChild( | $form->appendChild( | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | $type_map = array( | ||||
'add_comment' => PhabricatorTransactions::TYPE_COMMENT, | 'add_comment' => PhabricatorTransactions::TYPE_COMMENT, | ||||
'assign' => ManiphestTransaction::TYPE_OWNER, | 'assign' => ManiphestTransaction::TYPE_OWNER, | ||||
'status' => ManiphestTransaction::TYPE_STATUS, | 'status' => ManiphestTransaction::TYPE_STATUS, | ||||
'priority' => ManiphestTransaction::TYPE_PRIORITY, | 'priority' => ManiphestTransaction::TYPE_PRIORITY, | ||||
'add_project' => ManiphestTransaction::TYPE_PROJECTS, | 'add_project' => ManiphestTransaction::TYPE_PROJECTS, | ||||
'remove_project' => ManiphestTransaction::TYPE_PROJECTS, | 'remove_project' => ManiphestTransaction::TYPE_PROJECTS, | ||||
'add_ccs' => ManiphestTransaction::TYPE_CCS, | 'add_ccs' => ManiphestTransaction::TYPE_CCS, | ||||
'remove_ccs' => ManiphestTransaction::TYPE_CCS, | 'remove_ccs' => ManiphestTransaction::TYPE_CCS, | ||||
'view_policy' => PhabricatorTransactions::TYPE_VIEW_POLICY, | |||||
'edit_policy' => PhabricatorTransactions::TYPE_EDIT_POLICY, | |||||
); | ); | ||||
$edge_edit_types = array( | $edge_edit_types = array( | ||||
'add_project' => true, | 'add_project' => true, | ||||
'remove_project' => true, | 'remove_project' => true, | ||||
'add_ccs' => true, | 'add_ccs' => true, | ||||
'remove_ccs' => true, | 'remove_ccs' => true, | ||||
); | ); | ||||
Show All 29 Lines | foreach ($actions as $action) { | ||||
$current = $task->getPriority(); | $current = $task->getPriority(); | ||||
break; | break; | ||||
case ManiphestTransaction::TYPE_PROJECTS: | case ManiphestTransaction::TYPE_PROJECTS: | ||||
$current = $task->getProjectPHIDs(); | $current = $task->getProjectPHIDs(); | ||||
break; | break; | ||||
case ManiphestTransaction::TYPE_CCS: | case ManiphestTransaction::TYPE_CCS: | ||||
$current = $task->getCCPHIDs(); | $current = $task->getCCPHIDs(); | ||||
break; | break; | ||||
case PhabricatorTransactions::TYPE_VIEW_POLICY: | |||||
$current = $task->getViewPolicy(); | |||||
break; | |||||
case PhabricatorTransactions::TYPE_EDIT_POLICY: | |||||
$current = $task->getEditPolicy(); | |||||
break; | |||||
} | } | ||||
} | } | ||||
// Check if the value is meaningful / provided, and normalize it if | // Check if the value is meaningful / provided, and normalize it if | ||||
// necessary. This discards, e.g., empty comments and empty owner | // necessary. This discards, e.g., empty comments and empty owner | ||||
// changes. | // changes. | ||||
$value = $action['value']; | $value = $action['value']; | ||||
Show All 17 Lines | foreach ($actions as $action) { | ||||
continue 2; | continue 2; | ||||
} | } | ||||
break; | break; | ||||
case ManiphestTransaction::TYPE_CCS: | case ManiphestTransaction::TYPE_CCS: | ||||
if (empty($value)) { | if (empty($value)) { | ||||
continue 2; | continue 2; | ||||
} | } | ||||
break; | break; | ||||
case PhabricatorTransactions::TYPE_VIEW_POLICY: | |||||
case PhabricatorTransactions::TYPE_EDIT_POLICY: | |||||
if (empty($value)) { | |||||
continue 2; | |||||
} | |||||
break; | |||||
} | } | ||||
// If the edit doesn't change anything, go to the next action. This | // If the edit doesn't change anything, go to the next action. This | ||||
// check is only valid for changes like "owner", "status", etc, not | // check is only valid for changes like "owner", "status", etc, not | ||||
// for edge edits, because we should still apply an edit like | // for edge edits, because we should still apply an edit like | ||||
// "Remove Projects: A, B" to a task with projects "A, B". | // "Remove Projects: A, B" to a task with projects "A, B". | ||||
if (empty($edge_edit_types[$action['action']])) { | if (empty($edge_edit_types[$action['action']])) { | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | foreach ($value_map as $type => $value) { | ||||
} | } | ||||
$xactions[] = $xaction; | $xactions[] = $xaction; | ||||
} | } | ||||
return $xactions; | return $xactions; | ||||
} | } | ||||
private function getActionMap() { | |||||
return array( | |||||
'add_project' => pht('Add Projects'), | |||||
'remove_project' => pht('Remove Projects'), | |||||
'priority' => pht('Change Priority'), | |||||
'status' => pht('Change Status'), | |||||
'add_comment' => pht('Comment'), | |||||
'assign' => pht('Assign'), | |||||
'add_ccs' => pht('Add CCs'), | |||||
'remove_ccs' => pht('Remove CCs'), | |||||
'view_policy' => pht('Change View Policy'), | |||||
'edit_policy' => pht('Change Edit Policy')); | |||||
} | |||||
} | } |