-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpermissions-737816-test.patch
68 lines (65 loc) · 2.04 KB
/
permissions-737816-test.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
modules/user/user.module | 47 ++++++++++++++++++++++++++++++++++++++---------
1 file changed, 38 insertions(+), 9 deletions(-)
diff --git a/modules/user/user.module b/modules/user/user.module
index 5124207..96674c7 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -3092,22 +3092,51 @@ function user_role_change_permissions($rid, array $permissions = array()) {
*/
function user_role_grant_permissions($rid, array $permissions = array()) {
$modules = user_permission_get_modules();
+ $skipped_permissions = array();
// Grant new permissions for the role.
foreach ($permissions as $name) {
- db_merge('role_permission')
- ->key(array(
- 'rid' => $rid,
- 'permission' => $name,
- ))
- ->fields(array(
- 'module' => $modules[$name],
- ))
- ->execute();
+ if (empty($modules[$name])) {
+ $skipped_permissions[] = $name;
+ }
+ else {
+ user_role_grant_permission($rid, $name, $modules[$name]);
+ }
}
// Clear the user access cache.
drupal_static_reset('user_access');
drupal_static_reset('user_role_permissions');
+
+ if (count($skipped_permissions)) {
+ throw new Exception(format_plural(count($skipped_permissions),
+ 'Unable to grant permission @permissions. The module in which it is defined is not enabled.',
+ 'Unable to grant permissions: @permissions. The module(s) in which they are defined are not enabled.',
+ array('@permissions' => implode(', ', $skipped_permissions))
+ ));
+ }
+}
+
+/**
+ * Grant a permission to a user role.
+ *
+ * @param $rid
+ * The ID of a user role to alter.
+ * @param $permission
+ * The name of the permission grant.
+ * @param $module
+ * The name of the module the permission belongs to.
+ *
+ * @return int
+ * Database query status code.
+ */
+function user_role_grant_permission($rid, $permission, $module) {
+ return db_merge('role_permission')
+ ->key(array(
+ 'rid' => $rid,
+ 'permission' => $permission,
+ 'module' => $module,
+ ))
+ ->execute();
}
/**