3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
39 class CRM_Core_Permission_Base
{
42 * get the current permission of this user
44 * @return string the permission of the user (edit or view or null)
46 public function getPermission() {
47 return CRM_Core_Permission
::EDIT
;
51 * Get the permissioned where clause for the user
53 * @param int $type the type of permission needed
54 * @param array $tables (reference ) add the tables that are needed for the select clause
55 * @param array $whereTables (reference ) add the tables that are needed for the where clause
57 * @return string the group where clause for this user
60 public function whereClause($type, &$tables, &$whereTables) {
64 * Get the permissioned where clause for the user when trying to see groups
66 * @param int $type the type of permission needed
67 * @param array $tables (reference ) add the tables that are needed for the select clause
68 * @param array $whereTables (reference ) add the tables that are needed for the where clause
70 * @return string the group where clause for this user
73 public function getPermissionedStaticGroupClause($type, &$tables, &$whereTables) {
75 return $this->groupClause($type, $tables, $whereTables);
78 * Get all groups from database, filtered by permissions
81 * @param string $groupType type of group(Access/Mailing)
82 * @param boolen $excludeHidden exclude hidden groups.
86 * @return array - array reference of all groups.
89 public function group($groupType = NULL, $excludeHidden = TRUE) {
90 return CRM_Core_PseudoConstant
::allGroup($groupType, $excludeHidden);
94 * Get group clause for this user
96 * @param int $type the type of permission needed
97 * @param array $tables (reference ) add the tables that are needed for the select clause
98 * @param array $whereTables (reference ) add the tables that are needed for the where clause
100 * @return string the group where clause for this user
103 public function groupClause($type, &$tables, &$whereTables) {
108 * given a permission string, check for access requirements
110 * @param string $str the permission to check
112 * @return boolean true if yes, else false
116 function check($str) {
117 //no default behaviour
121 * Given a roles array, check for access requirements
123 * @param array $array the roles to check
125 * @return boolean true if yes, else false
129 function checkGroupRole($array) {
134 * Get all the contact emails for users that have a specific permission
136 * @param string $permissionName name of the permission we are interested in
138 * @return string a comma separated list of email addresses
140 public function permissionEmails($permissionName) {
141 CRM_Core_Error
::fatal("this function only works in Drupal 6 at the moment");
145 * Get all the contact emails for users that have a specific role
147 * @param string $roleName name of the role we are interested in
149 * @return string a comma separated list of email addresses
151 public function roleEmails($roleName) {
152 CRM_Core_Error
::fatal("this function only works in Drupal 6 at the moment");
156 * Determine whether the permission store allows us to store
157 * a list of permissions generated dynamically (eg by
158 * hook_civicrm_permissions.)
162 public function isModulePermissionSupported() {
167 * Ensure that the CMS supports all the permissions defined by CiviCRM
168 * and its extensions. If there are stale permissions, they should be
169 * deleted. This is useful during module upgrade when the newer module
170 * version has removed permission that were defined in the older version.
172 * @param array $permissions same format as CRM_Core_Permission::getCorePermissions().
173 * @see CRM_Core_Permission::getCorePermissions
175 function upgradePermissions($permissions) {
176 throw new CRM_Core_Exception("Unimplemented method: CRM_Core_Permission_*::upgradePermissions");
180 * Get the permissions defined in the hook_civicrm_permission implementation
181 * of the given module.
183 * Note: At time of writing, this is only used with native extension-modules, so
184 * there's one, predictable calling convention (regardless of CMS).
186 * @return Array of permissions, in the same format as CRM_Core_Permission::getCorePermissions().
187 * @see CRM_Core_Permission::getCorePermissions
189 static function getModulePermissions($module) {
190 $return_permissions = array();
191 $fn_name = "{$module}_civicrm_permission";
192 if (function_exists($fn_name)) {
193 $module_permissions = array();
194 $fn_name($module_permissions);
195 $return_permissions = $module_permissions;
197 return $return_permissions;
201 * Get the permissions defined in the hook_civicrm_permission implementation
202 * in all enabled CiviCRM module extensions.
204 * @return Array of permissions, in the same format as CRM_Core_Permission::getCorePermissions().
206 function getAllModulePermissions() {
207 $permissions = array();
208 CRM_Utils_Hook
::permission($permissions);