3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
39 class CRM_Core_Permission_Base
{
41 // permission mapping to stub check() calls
42 public $permissions = NULL;
45 * Translate permission.
48 * Permission string e.g "administer CiviCRM", "cms:access user record", "Drupal:administer content",
49 * "Joomla:action:com_asset"
51 * @param string $nativePrefix
53 * Array($portableName => $nativeName).
58 public function translatePermission($perm, $nativePrefix, $map) {
59 list ($civiPrefix, $name) = CRM_Utils_String
::parsePrefix(':', $perm, NULL);
60 switch ($civiPrefix) {
66 return CRM_Utils_Array
::value($name, $map, CRM_Core_Permission
::ALWAYS_DENY_PERMISSION
);
72 return CRM_Core_Permission
::ALWAYS_DENY_PERMISSION
;
77 * Get the current permission of this user.
80 * the permission of the user (edit or view or null)
82 public function getPermission() {
83 return CRM_Core_Permission
::EDIT
;
87 * Get the permissioned where clause for the user.
90 * The type of permission needed.
91 * @param array $tables
92 * (reference ) add the tables that are needed for the select clause.
93 * @param array $whereTables
94 * (reference ) add the tables that are needed for the where clause.
97 * the group where clause for this user
99 public function whereClause($type, &$tables, &$whereTables) {
104 * Get the permissioned where clause for the user when trying to see groups.
107 * The type of permission needed.
108 * @param array $tables
109 * (reference ) add the tables that are needed for the select clause.
110 * @param array $whereTables
111 * (reference ) add the tables that are needed for the where clause.
114 * the group where clause for this user
116 public function getPermissionedStaticGroupClause($type, &$tables, &$whereTables) {
118 return $this->groupClause($type, $tables, $whereTables);
122 * Get all groups from database, filtered by permissions
125 * @param string $groupType
126 * Type of group(Access/Mailing).
127 * @param bool $excludeHidden
128 * exclude hidden groups.
132 * array reference of all groups.
134 public function group($groupType = NULL, $excludeHidden = TRUE) {
135 return CRM_Core_PseudoConstant
::allGroup($groupType, $excludeHidden);
139 * Get group clause for this user.
142 * The type of permission needed.
143 * @param array $tables
144 * (reference ) add the tables that are needed for the select clause.
145 * @param array $whereTables
146 * (reference ) add the tables that are needed for the where clause.
149 * the group where clause for this user
151 public function groupClause($type, &$tables, &$whereTables) {
156 * Given a permission string, check for access requirements
159 * The permission to check.
162 public function check($str) {
163 //no default behaviour
167 * Given a roles array, check for access requirements
169 * @param array $array
170 * The roles to check.
173 * true if yes, else false
175 public function checkGroupRole($array) {
180 * Get all the contact emails for users that have a specific permission.
182 * @param string $permissionName
183 * Name of the permission we are interested in.
186 public function permissionEmails($permissionName) {
187 CRM_Core_Error
::fatal("this function only works in Drupal 6 at the moment");
191 * Get all the contact emails for users that have a specific role.
193 * @param string $roleName
194 * Name of the role we are interested in.
197 public function roleEmails($roleName) {
198 CRM_Core_Error
::fatal("this function only works in Drupal 6 at the moment");
202 * Determine whether the permission store allows us to store
203 * a list of permissions generated dynamically (eg by
204 * hook_civicrm_permissions.)
208 public function isModulePermissionSupported() {
213 * Ensure that the CMS supports all the permissions defined by CiviCRM
214 * and its extensions. If there are stale permissions, they should be
215 * deleted. This is useful during module upgrade when the newer module
216 * version has removed permission that were defined in the older version.
218 * @param array $permissions
219 * Same format as CRM_Core_Permission::getCorePermissions().
221 * @throws CRM_Core_Exception
222 * @see CRM_Core_Permission::getCorePermissions
224 public function upgradePermissions($permissions) {
225 throw new CRM_Core_Exception("Unimplemented method: CRM_Core_Permission_*::upgradePermissions");
229 * Get the permissions defined in the hook_civicrm_permission implementation
230 * of the given module.
232 * Note: At time of writing, this is only used with native extension-modules, so
233 * there's one, predictable calling convention (regardless of CMS).
238 * Array of permissions, in the same format as CRM_Core_Permission::getCorePermissions().
239 * @see CRM_Core_Permission::getCorePermissions
241 public static function getModulePermissions($module) {
242 $return_permissions = array();
243 $fn_name = "{$module}_civicrm_permission";
244 if (function_exists($fn_name)) {
245 $module_permissions = array();
246 $fn_name($module_permissions);
247 $return_permissions = $module_permissions;
249 return $return_permissions;
253 * Get the permissions defined in the hook_civicrm_permission implementation
254 * in all enabled CiviCRM module extensions.
257 * Array of permissions, in the same format as CRM_Core_Permission::getCorePermissions().
259 public function getAllModulePermissions() {
260 $permissions = array();
261 CRM_Utils_Hook
::permission($permissions);