Skip to content

Commit

Permalink
More fixes to core_Task
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire committed Nov 7, 2017
1 parent c5266a1 commit 74ac340
Show file tree
Hide file tree
Showing 23 changed files with 125 additions and 163 deletions.
4 changes: 1 addition & 3 deletions CRM/Activity/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ public function buildQuickForm() {
$this->addRowSelectors($rows);
}

$permission = CRM_Core_Permission::getPermission();

$this->addTaskMenu(CRM_Activity_Task::permissionedTaskTitles($permission));
$this->addTaskMenu(CRM_Activity_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission()));
}

}
Expand Down
6 changes: 4 additions & 2 deletions CRM/Activity/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ public static function tasks() {
* Show tasks selectively based on the permission level of the user.
*
* @param int $permission
* @param array $params
*
* @return array
* set of tasks that are valid for the user
*/
public static function permissionedTaskTitles($permission, $deleteContacts = FALSE) {
$tasks = array();
public static function permissionedTaskTitles($permission, $params = array()) {
if ($permission == CRM_Core_Permission::EDIT) {
$tasks = self::taskTitles();
}
Expand All @@ -144,6 +144,8 @@ public static function permissionedTaskTitles($permission, $deleteContacts = FAL
$tasks[self::DELETE_ACTIVITIES] = self::$_tasks[self::DELETE_ACTIVITIES]['title'];
}
}

$tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
return $tasks;
}

Expand Down
3 changes: 1 addition & 2 deletions CRM/Campaign/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ public function buildQuickForm() {
$this->addRowSelectors($rows);
}

$permission = CRM_Core_Permission::getPermission();
$allTasks = CRM_Campaign_Task::permissionedTaskTitles($permission);
$allTasks = CRM_Campaign_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission());

//hack to serve right page to state machine.
$taskMapping = array(
Expand Down
4 changes: 3 additions & 1 deletion CRM/Campaign/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ public static function tasks() {
* of the user
*
* @param int $permission
* @param array $params
*
* @return array
* set of tasks that are valid for the user
*/
public static function permissionedTaskTitles($permission, $deleteContacts = FALSE) {
public static function permissionedTaskTitles($permission, $params = array()) {
$tasks = self::taskTitles();

$tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
return $tasks;
}

Expand Down
8 changes: 3 additions & 5 deletions CRM/Case/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,13 @@ public function buildQuickForm() {
$this->addRowSelectors($rows);
}

$permission = CRM_Core_Permission::getPermission();

$tasks = CRM_Case_Task::permissionedTaskTitles($permission);
$tasks = CRM_Case_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission());

if (!empty($this->_formValues['case_deleted'])) {
unset($tasks[1]);
unset($tasks[CRM_Case_Task::DELETE_CASES]);
}
else {
unset($tasks[4]);
unset($tasks[CRM_Case_Task::RESTORE_CASES]);
}

$this->addTaskMenu($tasks);
Expand Down
6 changes: 4 additions & 2 deletions CRM/Case/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ public static function tasks() {
* of the user
*
* @param int $permission
* @param array $params
*
* @return array
* set of tasks that are valid for the user
*/
public static function permissionedTaskTitles($permission, $deletedContacts = FALSE) {
$tasks = array();
public static function permissionedTaskTitles($permission, $params = array()) {
if (($permission == CRM_Core_Permission::EDIT)
|| CRM_Core_Permission::check('access all cases and activities')
|| CRM_Core_Permission::check('access my cases and activities')
Expand All @@ -116,6 +116,8 @@ public static function permissionedTaskTitles($permission, $deletedContacts = FA
$tasks[self::DELETE_CASES] = self::$_tasks[self::DELETE_CASES]['title'];
}
}

$tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
return $tasks;
}

Expand Down
37 changes: 7 additions & 30 deletions CRM/Contact/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,25 +337,15 @@ public static function getModeSelect() {
*/
public function buildTaskList() {
if ($this->_context !== 'amtg') {
$permission = CRM_Core_Permission::getPermission();

$taskParams['deletedContacts'] = FALSE;
if ($this->_componentMode == CRM_Contact_BAO_Query::MODE_CONTACTS || $this->_componentMode == CRM_Contact_BAO_Query::MODE_CONTACTSRELATED) {
$this->_taskList += CRM_Contact_Task::permissionedTaskTitles($permission,
CRM_Utils_Array::value('deleted_contacts', $this->_formValues)
);
}
else {
$className = $this->_modeValue['taskClassName'];
$this->_taskList += $className::permissionedTaskTitles($permission, FALSE);
}

// Only offer the "Update Smart Group" task if a smart group/saved search is already in play
if (isset($this->_ssID) && $permission == CRM_Core_Permission::EDIT) {
$this->_taskList += CRM_Contact_Task::optionalTaskTitle();
$taskParams['deletedContacts'] = CRM_Utils_Array::value('deleted_contacts', $this->_formValues);
}
$className = $this->_modeValue['taskClassName'];
$taskParams['ssID'] = isset($this->_ssID) ? $this->_ssID : NULL;
$this->_taskList += $className::permissionedTaskTitles(CRM_Core_Permission::getPermission(), $taskParams);
}

asort($this->_taskList);
return $this->_taskList;
}

Expand All @@ -368,24 +358,11 @@ public function buildQuickForm() {
// jsTree is needed for tags popup
->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)
->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header');
$permission = CRM_Core_Permission::getPermission();

// some tasks.. what do we want to do with the selected contacts ?
$tasks = array();
if ($this->_componentMode == CRM_Contact_BAO_Query::MODE_CONTACTS || $this->_componentMode == CRM_Contact_BAO_Query::MODE_CONTACTSRELATED) {
$tasks += CRM_Contact_Task::permissionedTaskTitles($permission,
CRM_Utils_Array::value('deleted_contacts', $this->_formValues)
);
}
else {
$className = $this->_modeValue['taskClassName'];
$tasks += $className::permissionedTaskTitles($permission, FALSE);
}
$this->_taskList = $this->buildTaskList();

if (isset($this->_ssID)) {
if ($permission == CRM_Core_Permission::EDIT) {
$tasks = $tasks + CRM_Contact_Task::optionalTaskTitle();
}

$search_custom_id
= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'search_custom_id');

Expand Down
13 changes: 9 additions & 4 deletions CRM/Contact/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,19 @@ public static function tasks() {
* of the user
*
* @param int $permission
* @param bool $deletedContacts
* Are these tasks for operating on deleted contacts?.
* @param array $params:
* bool deletedContacts: Are these tasks for operating on deleted contacts?.
*
* @return array
* set of tasks that are valid for the user
*/
public static function permissionedTaskTitles($permission, $deletedContacts = FALSE) {
public static function permissionedTaskTitles($permission, $params = array()) {
if (!isset($params['deletedContacts'])) {
$params['deletedContacts'] = FALSE;
}
self::tasks();
$tasks = array();
if ($deletedContacts) {
if ($params['deletedContacts']) {
if (CRM_Core_Permission::check('access deleted contacts')) {
$tasks[self::RESTORE] = self::$_tasks[self::RESTORE]['title'];
if (CRM_Core_Permission::check('delete contacts')) {
Expand Down Expand Up @@ -283,6 +286,8 @@ public static function permissionedTaskTitles($permission, $deletedContacts = FA
$tasks[self::CREATE_MAILING] = self::$_tasks[self::CREATE_MAILING]['title'];
}
}

$tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
return $tasks;
}

Expand Down
6 changes: 3 additions & 3 deletions CRM/Contribute/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ public function buildQuickForm() {
$permission = CRM_Core_Permission::getPermission();

$queryParams = $this->get('queryParams');
$softCreditFiltering = FALSE;
$taskParams['softCreditFiltering'] = FALSE;
if (!empty($queryParams)) {
$softCreditFiltering = CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled($queryParams);
$taskParams['softCreditFiltering'] = CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled($queryParams);
}
$tasks = CRM_Contribute_Task::permissionedTaskTitles($permission, $softCreditFiltering);
$tasks = CRM_Contribute_Task::permissionedTaskTitles($permission, $taskParams);
$this->addTaskMenu($tasks);
}

Expand Down
13 changes: 9 additions & 4 deletions CRM/Contribute/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,16 @@ public static function tasks() {
*
* @param int $permission
*
* @param bool $softCreditFiltering
* @param array $params:
* bool softCreditFiltering: derived from CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled
*
* @return array
* set of tasks that are valid for the user
*/
public static function permissionedTaskTitles($permission, $softCreditFiltering = FALSE) {
$tasks = array();
public static function permissionedTaskTitles($permission, $params = array()) {
if (!isset($params['softCreditFiltering'])) {
$params['softCreditFiltering'] = FALSE;
}
if (($permission == CRM_Core_Permission::EDIT)
|| CRM_Core_Permission::check('edit contributions')
) {
Expand All @@ -154,9 +157,11 @@ public static function permissionedTaskTitles($permission, $softCreditFiltering
$tasks[self::DELETE_CONTRIBUTIONS] = self::$_tasks[self::DELETE_CONTRIBUTIONS]['title'];
}
}
if ($softCreditFiltering) {
if ($params['softCreditFiltering']) {
unset($tasks[self::BATCH_CONTRIBUTIONS], $tasks[self::PDF_RECEIPT]);
}

$tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
return $tasks;
}

Expand Down
49 changes: 29 additions & 20 deletions CRM/Core/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ abstract class CRM_Core_Task {
// Pledge tasks
DELETE_PLEDGES = 66,
PRINT_PLEDGES = 67,
EXPORT_PLEDGES = 68;
EXPORT_PLEDGES = 68,
// Grant Tasks
DELETE_GRANTS = 1,
PRINT_GRANTS = 2,
EXPORT_GRANTS = 3,
UPDATE_GRANTS = 4;

/**
* The task array
Expand All @@ -120,13 +125,6 @@ abstract class CRM_Core_Task {
*/
static $_tasks = NULL;

/**
* The optional task array
*
* @var array
*/
static $_optionalTasks = NULL;

abstract public static function tasks();

/**
Expand All @@ -144,9 +142,6 @@ public static function taskTitles() {
$titles[$id] = $value['title'];
}

// hack unset update saved search
unset($titles[self::SAVE_SEARCH_UPDATE]);

if (!CRM_Utils_Mail::validOutBoundMail()) {
unset($titles[self::EMAIL_CONTACTS]);
unset($titles[self::CREATE_MAILING]);
Expand All @@ -164,26 +159,40 @@ public static function taskTitles() {
/**
* Show tasks selectively based on the permission level
* of the user
* This function should be call parent::corePermissionedTaskTitles
*
* @param int $permission
* @param bool $deletedContacts
* Are these tasks for operating on deleted contacts?.
* @param array $params
* "ssID: Saved Search ID": If !empty we are in saved search context
*
* @return array
* set of tasks that are valid for the user
*/
abstract public static function permissionedTaskTitles($permission, $deletedContacts = FALSE);
abstract public static function permissionedTaskTitles($permission, $params);

/**
* These tasks get added based on the context the user is in.
* Show tasks selectively based on the permission level
* of the user
* This function should be called by permissionedTaskTitles in children
*
* @param int $permission
* @param array $params
* "ssID: Saved Search ID": If !empty we are in saved search context
* @param array $tasks: The array of tasks generated by permissionedTaskTitles
*
* @return array
* the set of optional tasks for a group of contacts
* set of tasks that are valid for the user
*/
public static function optionalTaskTitle() {
$tasks = array(
self::SAVE_SEARCH_UPDATE => self::$_tasks[self::SAVE_SEARCH_UPDATE]['title'],
);
public static function corePermissionedTaskTitles($tasks, $permission, $params) {
// Only offer the "Update Smart Group" task if a smart group/saved search is already in play and we have edit permissions
if (!empty($params['ssID']) && ($permission == CRM_Core_Permission::EDIT)) {
$tasks[self::SAVE_SEARCH_UPDATE] = self::$_tasks[self::SAVE_SEARCH_UPDATE]['title'];
}
else {
unset($tasks[self::SAVE_SEARCH_UPDATE]);
}

asort($tasks);
return $tasks;
}

Expand Down
8 changes: 2 additions & 6 deletions CRM/Event/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,10 @@ public function buildQuickForm() {
$this->assign('participantCount', $participantCount);
$this->assign('lineItems', $lineItems);

$permission = CRM_Core_Permission::getPermission();
$taskParams['ssID'] = isset($this->_ssID) ? $this->_ssID : NULL;
$tasks = CRM_Event_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission(), $taskParams);

$tasks = CRM_Event_Task::permissionedTaskTitles($permission);
if (isset($this->_ssID)) {
if ($permission == CRM_Core_Permission::EDIT) {
$tasks = $tasks + CRM_Event_Task::optionalTaskTitle();
}

$savedSearchValues = array(
'id' => $this->_ssID,
'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'),
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Form/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static function preProcessCommon(&$form, $useTable = FALSE) {

$form->_task = $values['task'];
$tasks = CRM_Event_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission());
if (!array_key_exists($form->_task, CRM_Event_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission()))) {
if (!array_key_exists($form->_task, $tasks)) {
CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.'));
}
$form->assign('taskName', $tasks[$form->_task]);
Expand Down
8 changes: 4 additions & 4 deletions CRM/Event/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,12 @@ public static function tasks() {
* of the user
*
* @param int $permission
* @param bool $deletedContacts
* Are these tasks for operating on deleted contacts?.
* @param array $params
*
* @return array
* set of tasks that are valid for the user
*/
public static function permissionedTaskTitles($permission, $deletedContacts = FALSE) {
$tasks = array();
public static function permissionedTaskTitles($permission, $params = array()) {
if (($permission == CRM_Core_Permission::EDIT)
|| CRM_Core_Permission::check('edit event participants')
) {
Expand All @@ -163,6 +161,8 @@ public static function permissionedTaskTitles($permission, $deletedContacts = FA
$tasks[self::DELETE_EVENTS] = self::$_tasks[self::DELETE_EVENTS]['title'];
}
}

$tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
return $tasks;
}

Expand Down
4 changes: 1 addition & 3 deletions CRM/Grant/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ public function buildQuickForm() {
$this->addRowSelectors($rows);
}

$permission = CRM_Core_Permission::getPermission();

$this->addTaskMenu(CRM_Grant_Task::permissionedTaskTitles($permission));
$this->addTaskMenu(CRM_Grant_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission()));
}

}
Expand Down
Loading

0 comments on commit 74ac340

Please sign in to comment.