Merge remote-tracking branch 'upstream/4.4' into 4.4-4.5-2014-09-08-20-42-29
[civicrm-core.git] / CRM / Core / Permission / Drupal6.php
index 8c7d2c26fead03c55f6ceb0f50f735d0d899ea9f..2b14cb61cc2c7cbbe055df563d78bc3a43fa1a50 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -61,6 +61,33 @@ class CRM_Core_Permission_Drupal6 extends CRM_Core_Permission_DrupalBase {
   protected $_viewPermissionedGroups;
   protected $_editPermissionedGroups;
 
+  /**
+   * given a permission string, check for access requirements
+   *
+   * @param string $str the permission to check
+   *
+   * @param null $contactID
+   *
+   * @return boolean true if yes, else false
+   * @access public
+   */
+  function check($str, $contactID = NULL) {
+    $str = $this->translatePermission($str, 'Drupal6', array(
+      'view user account' => 'access user profiles',
+      'administer users' => 'administer users',
+    ));
+    if ($str == CRM_Core_Permission::ALWAYS_DENY_PERMISSION) {
+      return FALSE;
+    }
+    if ($str == CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION) {
+      return TRUE;
+    }
+    if (function_exists('user_access')) {
+      return user_access($str) ? TRUE : FALSE;
+    }
+    return TRUE;
+  }
+
   /**
    * Given a roles array, check for access requirements
    *
@@ -169,6 +196,8 @@ class CRM_Core_Permission_Drupal6 extends CRM_Core_Permission_DrupalBase {
    * Get the permissions defined in the hook_civicrm_permission implementation
    * of the given module.
    *
+   * @param $module
+   *
    * @return Array of permissions, in the same format as CRM_Core_Permission::getCorePermissions().
    */
   static function getModulePermissions($module) {