Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * | |
38 | */ | |
39 | class CRM_Core_Permission_Base { | |
40 | ||
085823c1 TO |
41 | /** |
42 | * Translate permission | |
43 | * | |
77b97be7 | 44 | * @param $perm |
085823c1 TO |
45 | * @param string $nativePrefix |
46 | * @param array $map array($portableName => $nativeName) | |
77b97be7 EM |
47 | * |
48 | * @internal param string $name e.g. "administer CiviCRM", "cms:access user record", "Drupal:administer content", "Joomla:action:com_asset" | |
085823c1 TO |
49 | * @return NULL|string a permission name |
50 | */ | |
51 | public function translatePermission($perm, $nativePrefix, $map) { | |
52 | list ($civiPrefix, $name) = CRM_Utils_String::parsePrefix(':', $perm, NULL); | |
53 | switch ($civiPrefix) { | |
54 | case $nativePrefix: | |
55 | return $name; // pass through | |
56 | case 'cms': | |
57 | return CRM_Utils_Array::value($name, $map, CRM_Core_Permission::ALWAYS_DENY_PERMISSION); | |
58 | case NULL: | |
59 | return $name; | |
60 | default: | |
61 | return CRM_Core_Permission::ALWAYS_DENY_PERMISSION; | |
62 | } | |
63 | } | |
64 | ||
42762e35 DL |
65 | /** |
66 | * get the current permission of this user | |
67 | * | |
68 | * @return string the permission of the user (edit or view or null) | |
69 | */ | |
70 | public function getPermission() { | |
71 | return CRM_Core_Permission::EDIT; | |
72 | } | |
73 | ||
6a488035 TO |
74 | /** |
75 | * Get the permissioned where clause for the user | |
76 | * | |
77 | * @param int $type the type of permission needed | |
78 | * @param array $tables (reference ) add the tables that are needed for the select clause | |
79 | * @param array $whereTables (reference ) add the tables that are needed for the where clause | |
80 | * | |
81 | * @return string the group where clause for this user | |
82 | * @access public | |
83 | */ | |
84 | public function whereClause($type, &$tables, &$whereTables) { | |
85 | return '( 1 )'; | |
86 | } | |
87 | /** | |
88 | * Get the permissioned where clause for the user when trying to see groups | |
89 | * | |
90 | * @param int $type the type of permission needed | |
91 | * @param array $tables (reference ) add the tables that are needed for the select clause | |
92 | * @param array $whereTables (reference ) add the tables that are needed for the where clause | |
93 | * | |
94 | * @return string the group where clause for this user | |
95 | * @access public | |
96 | */ | |
97 | public function getPermissionedStaticGroupClause($type, &$tables, &$whereTables) { | |
98 | $this->group(); | |
99 | return $this->groupClause($type, $tables, $whereTables); | |
100 | } | |
77b97be7 | 101 | |
6a488035 TO |
102 | /** |
103 | * Get all groups from database, filtered by permissions | |
104 | * for this user | |
105 | * | |
77b97be7 EM |
106 | * @param string $groupType type of group(Access/Mailing) |
107 | * @param bool|\boolen $excludeHidden exclude hidden groups. | |
6a488035 TO |
108 | * |
109 | * @access public | |
110 | * | |
111 | * @return array - array reference of all groups. | |
6a488035 TO |
112 | */ |
113 | public function group($groupType = NULL, $excludeHidden = TRUE) { | |
42762e35 | 114 | return CRM_Core_PseudoConstant::allGroup($groupType, $excludeHidden); |
6a488035 TO |
115 | } |
116 | ||
117 | /** | |
42762e35 | 118 | * Get group clause for this user |
6a488035 TO |
119 | * |
120 | * @param int $type the type of permission needed | |
42762e35 DL |
121 | * @param array $tables (reference ) add the tables that are needed for the select clause |
122 | * @param array $whereTables (reference ) add the tables that are needed for the where clause | |
6a488035 | 123 | * |
42762e35 | 124 | * @return string the group where clause for this user |
6a488035 TO |
125 | * @access public |
126 | */ | |
127 | public function groupClause($type, &$tables, &$whereTables) { | |
42762e35 | 128 | return ' (1) '; |
6a488035 TO |
129 | } |
130 | ||
131 | /** | |
132 | * given a permission string, check for access requirements | |
133 | * | |
134 | * @param string $str the permission to check | |
135 | * | |
136 | * @return boolean true if yes, else false | |
137 | * @access public | |
138 | */ | |
139 | ||
140 | function check($str) { | |
42762e35 | 141 | //no default behaviour |
6a488035 TO |
142 | } |
143 | ||
144 | /** | |
145 | * Given a roles array, check for access requirements | |
146 | * | |
147 | * @param array $array the roles to check | |
148 | * | |
149 | * @return boolean true if yes, else false | |
150 | * @access public | |
151 | */ | |
42762e35 | 152 | |
6a488035 TO |
153 | function checkGroupRole($array) { |
154 | return FALSE; | |
155 | } | |
156 | ||
157 | /** | |
158 | * Get all the contact emails for users that have a specific permission | |
159 | * | |
160 | * @param string $permissionName name of the permission we are interested in | |
161 | * | |
162 | * @return string a comma separated list of email addresses | |
163 | */ | |
164 | public function permissionEmails($permissionName) { | |
165 | CRM_Core_Error::fatal("this function only works in Drupal 6 at the moment"); | |
166 | } | |
167 | ||
168 | /** | |
169 | * Get all the contact emails for users that have a specific role | |
170 | * | |
171 | * @param string $roleName name of the role we are interested in | |
172 | * | |
173 | * @return string a comma separated list of email addresses | |
174 | */ | |
175 | public function roleEmails($roleName) { | |
176 | CRM_Core_Error::fatal("this function only works in Drupal 6 at the moment"); | |
177 | } | |
178 | ||
7fccad46 TO |
179 | /** |
180 | * Determine whether the permission store allows us to store | |
181 | * a list of permissions generated dynamically (eg by | |
182 | * hook_civicrm_permissions.) | |
183 | * | |
184 | * @return bool | |
185 | */ | |
186 | public function isModulePermissionSupported() { | |
187 | return FALSE; | |
188 | } | |
189 | ||
6a488035 | 190 | /** |
0d8fc497 TO |
191 | * Ensure that the CMS supports all the permissions defined by CiviCRM |
192 | * and its extensions. If there are stale permissions, they should be | |
193 | * deleted. This is useful during module upgrade when the newer module | |
194 | * version has removed permission that were defined in the older version. | |
c4bc14ed | 195 | * |
0d8fc497 | 196 | * @param array $permissions same format as CRM_Core_Permission::getCorePermissions(). |
77b97be7 EM |
197 | * |
198 | * @throws CRM_Core_Exception | |
c4bc14ed | 199 | * @see CRM_Core_Permission::getCorePermissions |
6a488035 | 200 | */ |
0d8fc497 | 201 | function upgradePermissions($permissions) { |
7fccad46 | 202 | throw new CRM_Core_Exception("Unimplemented method: CRM_Core_Permission_*::upgradePermissions"); |
6a488035 TO |
203 | } |
204 | ||
205 | /** | |
206 | * Get the permissions defined in the hook_civicrm_permission implementation | |
207 | * of the given module. | |
208 | * | |
789565bf TO |
209 | * Note: At time of writing, this is only used with native extension-modules, so |
210 | * there's one, predictable calling convention (regardless of CMS). | |
211 | * | |
77b97be7 EM |
212 | * @param $module |
213 | * | |
6a488035 | 214 | * @return Array of permissions, in the same format as CRM_Core_Permission::getCorePermissions(). |
b57fc2e3 | 215 | * @see CRM_Core_Permission::getCorePermissions |
6a488035 TO |
216 | */ |
217 | static function getModulePermissions($module) { | |
789565bf TO |
218 | $return_permissions = array(); |
219 | $fn_name = "{$module}_civicrm_permission"; | |
220 | if (function_exists($fn_name)) { | |
221 | $module_permissions = array(); | |
222 | $fn_name($module_permissions); | |
223 | $return_permissions = $module_permissions; | |
224 | } | |
225 | return $return_permissions; | |
6a488035 TO |
226 | } |
227 | ||
228 | /** | |
229 | * Get the permissions defined in the hook_civicrm_permission implementation | |
230 | * in all enabled CiviCRM module extensions. | |
231 | * | |
232 | * @return Array of permissions, in the same format as CRM_Core_Permission::getCorePermissions(). | |
233 | */ | |
234 | function getAllModulePermissions() { | |
235 | $permissions = array(); | |
236 | CRM_Utils_Hook::permission($permissions); | |
237 | return $permissions; | |
238 | } | |
239 | } | |
240 |