Skip to content

Commit

Permalink
Merge pull request #10046 from JMAConsulting/CRM-20332
Browse files Browse the repository at this point in the history
CRM-20332 Added support for third column of actions list to be modifi…
  • Loading branch information
eileenmcnaughton authored Mar 29, 2017
2 parents 3aff619 + 9309f5c commit 2522469
Show file tree
Hide file tree
Showing 2 changed files with 183 additions and 95 deletions.
236 changes: 173 additions & 63 deletions CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -3006,6 +3006,79 @@ public static function contextMenu($contactId = NULL) {
),
);

$menu['otherActions'] = array(
'print' => array(
'title' => ts('Print Summary'),
'description' => ts('Printer-friendly view of this page.'),
'weight' => 5,
'ref' => 'crm-contact-print',
'key' => 'print',
'tab' => 'print',
'href' => CRM_Utils_System::url('civicrm/contact/view/print',
"reset=1&print=1"
),
'class' => 'print',
'icon' => 'crm-i fa-print',
),
'vcard' => array(
'title' => ts('vCard'),
'description' => ts('vCard record for this contact.'),
'weight' => 10,
'ref' => 'crm-contact-vcard',
'key' => 'vcard',
'tab' => 'vcard',
'href' => CRM_Utils_System::url('civicrm/contact/view/vcard',
"reset=1"
),
'class' => 'vcard',
'icon' => 'crm-i fa-list-alt',
),
);

if (CRM_Core_Permission::check('access Contact Dashboard')) {
$menu['otherActions']['dashboard'] = array(
'title' => ts('Contact Dashboard'),
'description' => ts('Contact Dashboard'),
'weight' => 15,
'ref' => 'crm-contact-dashboard',
'key' => 'dashboard',
'tab' => 'dashboard',
'class' => 'dashboard',
// NOTE: As an alternative you can also build url on CMS specific way
// as CRM_Core_Config::singleton()->userSystem->getUserRecordUrl($contactId)
'href' => CRM_Utils_System::url('civicrm/user', "reset=1&id={$contactId}"),
'icon' => 'crm-i fa-tachometer',
);
}

$uid = CRM_Core_BAO_UFMatch::getUFId($contactId);
if ($uid) {
$menu['otherActions']['user-record'] = array(
'title' => ts('User Record'),
'description' => ts('User Record'),
'weight' => 20,
'ref' => 'crm-contact-user-record',
'key' => 'user-record',
'tab' => 'user-record',
'class' => 'user-record',
'href' => CRM_Core_Config::singleton()->userSystem->getUserRecordUrl($contactId),
'icon' => 'crm-i fa-user',
);
}
elseif (CRM_Core_Config::singleton()->userSystem->checkPermissionAddUser()) {
$menu['otherActions']['user-add'] = array(
'title' => ts('Create User Record'),
'description' => ts('Create User Record'),
'weight' => 25,
'ref' => 'crm-contact-user-add',
'key' => 'user-add',
'tab' => 'user-add',
'class' => 'user-add',
'href' => CRM_Utils_System::url('civicrm/contact/view/useradd', 'reset=1&action=add&cid=' . $contactId),
'icon' => 'crm-i fa-user-plus',
);
}

CRM_Utils_Hook::summaryActions($menu, $contactId);
//1. check for component is active.
//2. check for user permissions.
Expand All @@ -3023,89 +3096,126 @@ public static function contextMenu($contactId = NULL) {
);
$corePermission = CRM_Core_Permission::getPermission();

$config = CRM_Core_Config::singleton();

$contextMenu = array();
foreach ($menu as $key => $values) {
$componentName = CRM_Utils_Array::value('component', $values);
if ($key != 'otherActions') {

// if component action - make sure component is enable.
if ($componentName && !in_array($componentName, $config->enableComponents)) {
continue;
}

// make sure user has all required permissions.
$hasAllPermissions = FALSE;

$permissions = CRM_Utils_Array::value('permissions', $values);
if (!is_array($permissions) || empty($permissions)) {
$hasAllPermissions = TRUE;
}

// iterate for required permissions in given permissions array.
if (!$hasAllPermissions) {
$hasPermissions = 0;
foreach ($permissions as $permission) {
if (CRM_Core_Permission::check($permission)) {
$hasPermissions++;
}
}

if (count($permissions) == $hasPermissions) {
$hasAllPermissions = TRUE;
// user does not have necessary permissions.
if (!self::checkUserMenuPermissions($aclPermissionedTasks, $corePermission, $values)) {
continue;
}

// if still user does not have required permissions, check acl.
if (!$hasAllPermissions && $values['ref'] != 'delete-contact') {
if (in_array($values['ref'], $aclPermissionedTasks) &&
$corePermission == CRM_Core_Permission::EDIT
) {
$hasAllPermissions = TRUE;
}
elseif (in_array($values['ref'], array(
'new-email',
))) {
// grant permissions for these tasks.
$hasAllPermissions = TRUE;
}
// build directly accessible action menu.
if (in_array($values['ref'], array(
'view-contact',
'edit-contact',
))) {
$contextMenu['primaryActions'][$key] = array(
'title' => $values['title'],
'ref' => $values['ref'],
'class' => CRM_Utils_Array::value('class', $values),
'key' => $values['key'],
);
continue;
}
}

// user does not have necessary permissions.
if (!$hasAllPermissions) {
continue;
}

// build directly accessible action menu.
if (in_array($values['ref'], array(
'view-contact',
'edit-contact',
))) {
$contextMenu['primaryActions'][$key] = array(
// finally get menu item for -more- action widget.
$contextMenu['moreActions'][$values['weight']] = array(
'title' => $values['title'],
'ref' => $values['ref'],
'href' => CRM_Utils_Array::value('href', $values),
'tab' => CRM_Utils_Array::value('tab', $values),
'class' => CRM_Utils_Array::value('class', $values),
'key' => $values['key'],
);
continue;
}
else {
foreach ($values as $value) {
// user does not have necessary permissions.
if (!self::checkUserMenuPermissions($aclPermissionedTasks, $corePermission, $value)) {
continue;
}

// finally get menu item for -more- action widget.
$contextMenu['moreActions'][$values['weight']] = array(
'title' => $values['title'],
'ref' => $values['ref'],
'href' => CRM_Utils_Array::value('href', $values),
'tab' => CRM_Utils_Array::value('tab', $values),
'class' => CRM_Utils_Array::value('class', $values),
'key' => $values['key'],
);
// finally get menu item for -more- action widget.
$contextMenu['otherActions'][$value['weight']] = array(
'title' => $value['title'],
'ref' => $value['ref'],
'href' => CRM_Utils_Array::value('href', $value),
'tab' => CRM_Utils_Array::value('tab', $value),
'class' => CRM_Utils_Array::value('class', $value),
'icon' => CRM_Utils_Array::value('icon', $value),
'key' => $value['key'],
);
}
}
}

ksort($contextMenu['moreActions']);
ksort($contextMenu['otherActions']);

return $contextMenu;
}

/**
* Check if user has permissions to access items in action menu.
*
* @param array $aclPermissionedTasks
* Array containing ACL related tasks.
* @param string $corePermission
* The permission of the user (edit or view or null).
* @param array $menuOptions
* Array containing params of the menu (title, href, etc).
*
* @return bool
* TRUE if user has all permissions, FALSE if otherwise.
*/
public static function checkUserMenuPermissions($aclPermissionedTasks, $corePermission, $menuOptions) {
$componentName = CRM_Utils_Array::value('component', $menuOptions);

// if component action - make sure component is enable.
if ($componentName && !in_array($componentName, CRM_Core_Config::singleton()->enableComponents)) {
return FALSE;
}

// make sure user has all required permissions.
$hasAllPermissions = FALSE;

$permissions = CRM_Utils_Array::value('permissions', $menuOptions);
if (!is_array($permissions) || empty($permissions)) {
$hasAllPermissions = TRUE;
}

// iterate for required permissions in given permissions array.
if (!$hasAllPermissions) {
$hasPermissions = 0;
foreach ($permissions as $permission) {
if (CRM_Core_Permission::check($permission)) {
$hasPermissions++;
}
}

if (count($permissions) == $hasPermissions) {
$hasAllPermissions = TRUE;
}

// if still user does not have required permissions, check acl.
if (!$hasAllPermissions && $menuOptions['ref'] != 'delete-contact') {
if (in_array($values['ref'], $aclPermissionedTasks) &&
$corePermission == CRM_Core_Permission::EDIT
) {
$hasAllPermissions = TRUE;
}
elseif (in_array($menuOptions['ref'], array(
'new-email',
))) {
// grant permissions for these tasks.
$hasAllPermissions = TRUE;
}
}
}

return $hasAllPermissions;
}

/**
* Retrieve display name of contact that address is shared.
*
Expand Down
42 changes: 10 additions & 32 deletions templates/CRM/Contact/Page/Inline/Actions.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,17 @@
<div class="crm-contact_activities-list">
{include file="CRM/Activity/Form/ActivityLinks.tpl" as_select=false}
</div>

<div class="crm-contact_print-list">
<ul class="contact-print">
<li class="crm-contact-print">
<a class="print" title="{ts}Printer-friendly view of this page.{/ts}" href='{crmURL p='civicrm/contact/view/print' q="reset=1&print=1&cid=$contactId"}'>
<span><i class="crm-i fa-print"></i> {ts}Print Summary{/ts}</span>
</a>
</li>
<li>
<a class="vcard " title="{ts}vCard record for this contact.{/ts}" href="{crmURL p='civicrm/contact/view/vcard' q="reset=1&cid=$contactId"}"><span><i class="crm-i fa-list-alt"></i> {ts}vCard{/ts}</span>
</a>
</li>
{if !empty($dashboardURL)}
<li class="crm-contact-dashboard">
<a href="{$dashboardURL}" class="dashboard " title="{ts}dashboard{/ts}">
<span><i class="crm-i fa-tachometer"></i> {ts}Contact Dashboard{/ts}</span>
</a>
</li>
{/if}
{if !empty($userRecordUrl)}
<li class="crm-contact-user-record">
<a href="{$userRecordUrl}" class="user-record " title="{ts}User Record{/ts}">
<span><i class="crm-i fa-user"></i> {ts}User Record{/ts}</span>
</a>
</li>
{/if}
{if !empty($userAddUrl)}
<li class="crm-contact-user-record">
<a href="{$userAddUrl}" class="user-record " title="{ts}Create User Record{/ts}">
<span><i class="crm-i fa-user-plus"></i> {ts}Create User Record{/ts}</span>
</a>
</li>
<div class="crm-contact_print-list">
<ul class="contact-print">
{foreach from=$actionsMenuList.otherActions item='row'}
{if !empty($row.href) or !empty($row.tab)}
<li class="crm-contact-{$row.ref}">
<a href="{if !empty($row.href)}{$row.href}&cid={$contactId}{else}#{/if}" title="{$row.title}" data-tab="{$row.tab}" {if !empty($row.class)}class="{$row.class}"{/if}>
<span><i {if !empty($row.icon)}class="{$row.icon}"{/if}></i> {$row.title}</span>
</a>
</li>
{/if}
{/foreach}
</ul>
</div>
<div class="crm-contact_actions-list">
Expand Down

0 comments on commit 2522469

Please sign in to comment.