CRM-11925 - Modify upgradePermissions to work with all permissions (not just single...
[civicrm-core.git] / CRM / Core / Permission / Drupal.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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 */
39class 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
65
66 /**
67 * Given a roles array, check for access requirements
68 *
69 * @param array $array the roles to check
70 *
71 * @return boolean true if yes, else false
72 * @access public
73 */
74 function checkGroupRole($array) {
75 if (function_exists('user_load') && isset($array)) {
76 $user = user_load( $GLOBALS['user']->uid);
77 //if giver roles found in user roles - return true
78 foreach ($array as $key => $value) {
79 if (in_array($value, $user->roles)) {
80 return TRUE;
81 }
82 }
83 }
84 return FALSE;
85 }
86
7fccad46
TO
87 /**
88 * {@inheritDoc}
89 */
90 public function isModulePermissionSupported() {
91 return TRUE;
92 }
93
6a488035
TO
94 /**
95 * Remove all vestiges of permissions for the given module.
96 */
97 function uninstallPermissions($module) {
98 db_delete('role_permission')
99 ->condition('permission', "$module|%", 'LIKE')
100 ->condition('module', 'civicrm')
101 ->execute();
102 }
103
104 /**
c4bc14ed 105 * {@inheritdoc}
6a488035 106 */
0d8fc497
TO
107 function upgradePermissions($permissions) {
108 if (empty($permissions)) {
109 throw new CRM_Core_Exception("Cannot upgrade permissions: permission list missing");
6a488035 110 }
0d8fc497
TO
111 $query = db_delete('role_permission')
112 ->condition('module', 'civicrm')
113 ->condition('permission', array_keys($permissions), 'NOT IN');
6a488035
TO
114 $query->execute();
115 }
6a488035
TO
116}
117