Details
-
Type: Improvement
-
Status: Done/Fixed
-
Priority: Trivial
-
Resolution: Fixed/Completed
-
Affects Version/s: 4.2.0
-
Fix Version/s: 4.3.0
-
Component/s: None
-
Labels:None
Description
Hi Tim,
I noticed the D6 permission class CRM_Core_Permission_Drupal6 seems to differ from the d7 one - but the differences all seem to be a case of people improving d7 & not d6
I can't see any reason for any difference & am thinking we should either copy the d7 changes into d6 or empty out the d6 class & make it an extension of d7 - thoughts? Here's what a diff looks like - the extra functions at the end - one looks generic (all CMS) & the other would work d6 or d7
index bd3cf87..b430644 100644
— a/CRM/Core/Permission/Drupal6.php
+++ b/CRM/Core/Permission/Drupal6.php
@@ -77,43 +77,49 @@ class CRM_Core_Permission_Drupal6 {
public static function &group($groupType = NULL, $excludeHidden = TRUE) {
if (!isset(self::$_viewPermissionedGroups))
+
+ $groupKey = $groupType ? $groupType : 'all';
+
+ if (!isset(self::$_viewPermissionedGroups[$groupKey])) {
+ self::$_viewPermissionedGroups[$groupKey] = self::$_editPermissionedGroups[$groupKey] = array();
- $groups = &CRM_Core_PseudoConstant::allGroup($groupType, $excludeHidden);
+ $groups = CRM_Core_PseudoConstant::allGroup($groupType, $excludeHidden);
if (self::check('edit all contacts'))
{ // this is the most powerful permission, so we return // immediately rather than dilute it further self::$_editAdminUser = self::$_viewAdminUser = TRUE; self::$_editPermission = self::$_viewPermission = TRUE; - self::$_editPermissionedGroups = $groups; - self::$_viewPermissionedGroups = $groups; - return self::$_viewPermissionedGroups; + self::$_editPermissionedGroups[$groupKey] = $groups; + self::$_viewPermissionedGroups[$groupKey] = $groups; + return self::$_viewPermissionedGroups[$groupKey]; }elseif (self::check('view all contacts'))
{ self::$_viewAdminUser = TRUE; self::$_viewPermission = TRUE; - self::$_viewPermissionedGroups = $groups; + self::$_viewPermissionedGroups[$groupKey] = $groups; } $ids = CRM_ACL_API::group(CRM_Core_Permission::VIEW, NULL, 'civicrm_saved_search', $groups);
foreach (array_values($ids) as $id)
- return self::$_viewPermissionedGroups;
+ return self::$_viewPermissionedGroups[$groupKey];
}
/**
@@ -131,28 +137,30 @@ class CRM_Core_Permission_Drupal6
+ // we basically get all the groups here
+ $groupKey = 'all';
if ($type == CRM_Core_Permission::EDIT) {
if (self::$_editAdminUser)
- elseif (empty(self::$_editPermissionedGroups)) {
+ elseif (empty(self::$_editPermissionedGroups[$groupKey])) { $clause = ' ( 0 ) '; }
else {
$clauses = array();
- $groups = implode(', ', self::$_editPermissionedGroups);
- $clauses[] = ' ( civicrm_group_contact.group_id IN ( ' . implode(', ', array_keys(self::$_editPermissionedGroups)) . " ) AND civicrm_group_contact.status = 'Added' ) ";
+ $groups = implode(', ', self::$_editPermissionedGroups[$groupKey]);
+ $clauses[] = ' ( civicrm_group_contact.group_id IN ( ' . implode(', ', array_keys(self::$_editPermissionedGroups[$groupKey])) . " ) AND civicrm_group_contact.status = 'Added' ) ";
$tables['civicrm_group_contact'] = 1;
$whereTables['civicrm_group_contact'] = 1;
// foreach group that is potentially a saved search, add the saved search clause
- foreach (array_keys(self::$_editPermissionedGroups) as $id) {
+ foreach (array_keys(self::$_editPermissionedGroups[$groupKey]) as $id) {
$group = new CRM_Contact_DAO_Group();
$group->id = $id;
if ($group->find(TRUE) && $group->saved_search_id) {
$clause = CRM_Contact_BAO_SavedSearch::whereClause($group->saved_search_id,
- $tables,
- $whereTables
+ $tables,
+ $whereTables
);
if (trim($clause)) {
$clauses[] = $clause;
@@ -166,25 +174,25 @@ class CRM_Core_Permission_Drupal6 {
if (self::$_viewAdminUser) { $clause = ' ( 1 ) '; }
- elseif (empty(self::$_viewPermissionedGroups)) {
+ elseif (empty(self::$_viewPermissionedGroups[$groupKey])) { $clause = ' ( 0 ) '; }else {
$clauses = array(); - $groups = implode(', ', self::$_viewPermissionedGroups);
- $clauses[] = ' ( civicrm_group_contact.group_id IN (' . implode(', ', array_keys(self::$_viewPermissionedGroups)) . " ) AND civicrm_group_contact.status = 'Added' ) ";
+ $groups = implode(', ', self::$_viewPermissionedGroups[$groupKey]);
+ $clauses[] = ' ( civicrm_group_contact.group_id IN (' . implode(', ', array_keys(self::$_viewPermissionedGroups[$groupKey])) . " ) AND civicrm_group_contact.status = 'Added' ) ";
$tables['civicrm_group_contact'] = 1;
$whereTables['civicrm_group_contact'] = 1;
// foreach group that is potentially a saved search, add the saved search clause
- foreach (array_keys(self::$_viewPermissionedGroups) as $id) {
+ foreach (array_keys(self::$_viewPermissionedGroups[$groupKey]) as $id) {
$group = new CRM_Contact_DAO_Group();
$group->id = $id;
if ($group->find(TRUE) && $group->saved_search_id) {
$clause = CRM_Contact_BAO_SavedSearch::whereClause($group->saved_search_id, - $tables,
- $whereTables
+ $tables,
+ $whereTables
);
if (trim($clause)) {
$clauses[] = $clause;
@@ -241,8 +249,7 @@ class CRM_Core_Permission_Drupal6 {
- @static
- @access public
*/
- static
- function check($str, $contactID = NULL) {
+ static function check($str, $contactID = NULL) {
if (function_exists('user_access')) { return user_access($str) ? TRUE : FALSE; }@@ -268,8 +275,7 @@ class CRM_Core_Permission_Drupal6 {
- @static
- @access public
*/
- static
- function checkGroupRole($array) {
+ static function checkGroupRole($array) {
if (function_exists('user_load') && isset($array)) {
$user = user_load(array('uid' => $GLOBALS['user']->uid));
//if giver roles found in user roles - return true
@@ -279,7 +285,99 @@ class CRM_Core_Permission_Drupal6 {
}
}
}
+
return FALSE;
}
-}
+
+ /**
+ * Get all the contact emails for users that have a specific permission
+ *
+ * @param string $permissionName name of the permission we are interested in
+ *
+ * @return string a comma separated list of email addresses
+ */
+ public static function permissionEmails($permissionName)Unknown macro: {+ static $_cache = array();++ if (isset($_cache[$permissionName])) { + return $_cache[$permissionName]; + }++ $uids = array();+ $sql = "+ SELECT {users}.uid, {permission}.perm
+ FROM {users}+ LEFT JOIN {users_roles} ON {users}.uid = {users_roles}.uid+ INNER JOIN {permission} ON ( {permission}.rid = {users_roles}.rid OR {permission}.rid = 2 )
+ WHERE {permission}.perm LIKE '%%{$permissionName}%%'
+ AND {users}.status = 1
+ ";
+
+ $query = db_query($sql);
+ while ($result = db_fetch_object($query)) { + $uids[] = $result->uid; + }
+
+ $_cache[$permissionName] = self::getContactEmails($uids);
+ return $_cache[$permissionName];
+ }
+
+ /**
+ * Get all the contact emails for users that have a specific role
+ *
+ * @param string $roleName name of the role we are interested in
+ *
+ * @return string a comma separated list of email addresses
+ */
+ public static function roleEmails($roleName) {
+ static $_cache = array();
+
+ if (isset($_cache[$roleName])) { + return $_cache[$roleName]; + }
+
+ $uids = array();
+ $sql = "
+ SELECT {users}.uid, {permission}.perm
+ FROM {users}
+ LEFT JOIN {users_roles} ON {users}.uid = {users_roles}.uid
+ INNER JOIN {role} ON ( {role}.rid = {users_roles}.rid OR {role}.rid = 2 )
+ WHERE {role}. name LIKE '%%{$roleName}%%'
+ AND {users}.status = 1+ ";++ $query = db_query($sql);+ while ($result = db_fetch_object($query)) { + $uids[] = $result->uid; + }++ $_cache[$roleName] = self}+
+ static function getContactEmails($uids)Unknown macro: {+ if (empty($uids)) { + return ''; + }+ $uidString = implode(',', $uids);+ $sql = "+ SELECT e.email+ FROM civicrm_contact c+ INNER JOIN civicrm_email e ON ( c.id = e.contact_id AND e.is_primary = 1 )+ INNER JOIN civicrm_uf_match uf ON ( c.id = uf.contact_id )+ WHERE c.is_deceased = 0+ AND c.is_deleted = 0+ AND uf.uf_id IN ( $uidString )+ ";++ $dao = CRM_Core_DAO}+ }