Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * | |
38 | */ | |
39 | class CRM_Core_Permission_Drupal extends CRM_Core_Permission_DrupalBase{ | |
40 | ||
41 | /** | |
42 | * is this user someone with access for the entire system | |
43 | * | |
44 | * @var boolean | |
45 | */ | |
46 | protected $_viewAdminUser = FALSE; | |
47 | protected $_editAdminUser = FALSE; | |
48 | ||
49 | /** | |
50 | * am in in view permission or edit permission? | |
51 | * @var boolean | |
52 | */ | |
53 | protected $_viewPermission = FALSE; | |
54 | protected $_editPermission = FALSE; | |
55 | ||
56 | /** | |
57 | * the current set of permissioned groups for the user | |
58 | * | |
59 | * @var array | |
60 | */ | |
61 | protected $_viewPermissionedGroups; | |
62 | protected $_editPermissionedGroups; | |
63 | ||
64 | ||
085823c1 TO |
65 | /** |
66 | * given a permission string, check for access requirements | |
67 | * | |
68 | * @param string $str the permission to check | |
69 | * | |
70 | * @return boolean true if yes, else false | |
71 | * @access public | |
72 | */ | |
73 | function check($str, $contactID = NULL) { | |
74 | $str = $this->translatePermission($str, 'Drupal', array( | |
75 | 'view user account' => 'access user profiles', | |
ccd74e76 | 76 | 'administer users' => 'administer users', |
085823c1 TO |
77 | )); |
78 | if ($str == CRM_Core_Permission::ALWAYS_DENY_PERMISSION) { | |
79 | return FALSE; | |
80 | } | |
81 | if ($str == CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION) { | |
82 | return TRUE; | |
83 | } | |
84 | if (function_exists('user_access')) { | |
85 | return user_access($str) ? TRUE : FALSE; | |
86 | } | |
87 | return TRUE; | |
88 | } | |
6a488035 TO |
89 | |
90 | /** | |
91 | * Given a roles array, check for access requirements | |
92 | * | |
93 | * @param array $array the roles to check | |
94 | * | |
95 | * @return boolean true if yes, else false | |
96 | * @access public | |
97 | */ | |
98 | function checkGroupRole($array) { | |
99 | if (function_exists('user_load') && isset($array)) { | |
100 | $user = user_load( $GLOBALS['user']->uid); | |
101 | //if giver roles found in user roles - return true | |
102 | foreach ($array as $key => $value) { | |
103 | if (in_array($value, $user->roles)) { | |
104 | return TRUE; | |
105 | } | |
106 | } | |
107 | } | |
108 | return FALSE; | |
109 | } | |
110 | ||
7fccad46 TO |
111 | /** |
112 | * {@inheritDoc} | |
113 | */ | |
114 | public function isModulePermissionSupported() { | |
115 | return TRUE; | |
116 | } | |
117 | ||
6a488035 | 118 | /** |
c4bc14ed | 119 | * {@inheritdoc} |
6a488035 | 120 | */ |
0d8fc497 TO |
121 | function upgradePermissions($permissions) { |
122 | if (empty($permissions)) { | |
123 | throw new CRM_Core_Exception("Cannot upgrade permissions: permission list missing"); | |
6a488035 | 124 | } |
0d8fc497 TO |
125 | $query = db_delete('role_permission') |
126 | ->condition('module', 'civicrm') | |
127 | ->condition('permission', array_keys($permissions), 'NOT IN'); | |
6a488035 TO |
128 | $query->execute(); |
129 | } | |
6a488035 TO |
130 | } |
131 |