bogus permissions set when granting permissions to a new role
| Project: | Patterns |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
This one was frustrating.
When granting permissions to a role that didn't have any permissions at all - like a brand-new created one, that role was always being given access to the first perm on the global list (in my case 'administer blocks')
After a lot of trials and tracing, I found that at one point the code that looks up the 'previous' perms was, instead of returning an empty array, returning an array that looked like array(0 => '');
This somehow was making it through the system and marking checkbox #1 as active all the time.
Meh.
Here's the fix for that.
@@ -252,8 +252,11 @@ function user_patterns($op, $id = null,
if (!$data['overwrite']) {
$p = db_result(db_query("SELECT perm FROM {permission} WHERE rid = %d", $data['rid']));
$p = explode(',', $p);
- $p = array_map('trim', $p);
- $perms = array_combine($p, $p);
+ $perms = array();
+ if (!empty($p)) {
+ $p = array_map('trim', $p);
+ $perms = array_combine($p, $p);
+ }
if (!empty($perms)) {
$data[$data['rid']] = array_merge($perms, $data[$data['rid']]);
}Also, I find the XML/code to define 50 different permissions way too tedious and verbose to manage because I can't cut & paste it from anywhere.
<actions>
<permissions role="authenticated user">
<value>upload files</value>
<value>view uploaded files</value>
...+ dozens and dozens
</permissions>
</actions>The doc says I can separate the values in one big string with commas (phew!) but still...
my lists (copied from PHP dumps) look like this:
<actions>
<permissions role="authenticated user">
<value>
'create blog entries',
'delete own blog entries',
'edit own blog entries',
'access comments',
...
..
</value>Note the quotes.
So I added an extra trim() onto the process to discard quotes too. This is closer to CSV support than the simple explode() that was there before.
- $val = trim($value);
+ $val = trim(trim($value), '\'"');| Attachment | Size |
|---|---|
| patterns-permissions_oddities.patch | 1.29 KB |

#1
Looking great. Thanks a lot! Committed.
#2
this was committed (see #1)
#3
Automatically closed -- issue fixed for 2 weeks with no activity.