Closed (fixed)
Project:
Permissions API
Version:
6.x-2.11
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Reporter:
Created:
7 Oct 2010 at 02:41 UTC
Updated:
2 Apr 2012 at 14:50 UTC
I didn't have time to really dig deeper, but permissions_grant_permissions() intermittently fails to grant a role a permission. What i did find was that this returned nothing when the failure happens:
// Fetch the permissions string for the given role id
$permissions = permissions_get_permissions_for_role($role->name);
I ended up implementing my own simpler version of this function (scary though because of the security implications).
Comments
Comment #1
ebeyrent commentedComment #2
Nick Robillard commentedSomething i didn't mention - role granting always worked for "authenticated user" role, but failed for a custom role.
Comment #3
ebeyrent commentedHi there,
I am sorry you're having some trouble with the module. In order to help you, I'm going to need some more specific information, and possibly a code sample to see what's happening.
- Are you running the latest stable version of the module?
- Have you checked watchdog for any errors?
I whipped up a sample module to test some basic functionality, and I'm not seeing any issues. Perhaps you could take a look at this example and compare it to what you've got?
When I go to update.php and I run these updates, here's the results:
The following queries were executed
my_module module
Update #6001
* Successfully created role demo with id 5
Update #6002
* Failed: Role 'demo' has no assigned permissions.
Update #6003
* Role 'demo' has 21 permissions
Update #6004
* Role 'demo' has 61 permissions
You'll notice that update 2 failed because the newly created role didn't have any permissions, which is expected. The subsequent updates grant permissions to the role, and you can see how that's reflected in the results.
You can also take a look at the documentation for this module: http://drupal.org/node/802272
Comment #4
ebeyrent commentedComment #5
michaelraasch commentedI have come across the same problem and can give you more details. The culprit is in function permissions_grant_permissions()
in the check for
When a role is stripped of its last permission then the field {permission}.perm is set to an empty string. However when a new permission is applied, thenif(count($permissions) > 0)if(count($permissions) > 0)returns FALSE and a new row is inserted instead of running an update of the existing row.Try this to reproduce:
I suggest either
db_query('DELETE FROM {permission} WHERE rid = %d', $role->rid);before the INSERT-statementor
- get rid of the if-statement completely, merge the $permissions and $new_permissions, run a DELETE and INSERT statement all the time.
Personally I think option 2 is better because clearer. I hope this makes sense.Comment #6
ebeyrent commentedI have confirmed this behavior and will fix it sometime this week. Thanks for tracking this down!
Comment #7
ebeyrent commentedActually, the problem is in the permissions_revoke_permissions() function. If the user only has one permission and that permission is revoked, the row in the permissions table is getting updated instead of deleted.
Comment #8
michaelraasch commented@ebeyrent: That would be even cleaner and more correct of course.
Comment #9
ebeyrent commentedThis is fixed in the latest commit, and in 6.x-2.13.
Comment #10
ebeyrent commented