| 1 | | I'm using latest sfDoctrineGuardUser. When I'm trying to get users permissions, I'm getting only those, which are assigned to the user directly, but groups permissions, in which he is, are ommited.[[BR]] |
|---|
| 2 | | |
|---|
| 3 | | For example we have user john, he is in groups moderators and admins, group moderatrs has permission block_user, group admins has permission delete_user, and john has permission write_articles. [[BR]] |
|---|
| 4 | | |
|---|
| 5 | | $john->hasPermission('delete_user') and $john->hasPermission('block_user') returns false,[[BR]] |
|---|
| 6 | | $john->hasPermission('write_articles') returns true,[[BR]] |
|---|
| 7 | | array_keys($john->getAllPermissions()) returns array('write_articles','block_user','delete_user')[[BR]] |
|---|
| 8 | | |
|---|
| 9 | | The solution for me is to override sfGuardSecuirtyUser::hasPermissions in this way: |
|---|
| 10 | | |
|---|
| 11 | | {{{ |
|---|
| 12 | | public function hasPermission($name) |
|---|
| 13 | | { |
|---|
| 14 | | if ( !($guardUser = $this->getGuardUser()) ) { |
|---|
| 15 | | return false; |
|---|
| 16 | | } |
|---|
| 17 | | $guardUser->loadGroupsAndPermissions(); |
|---|
| 18 | | return isset($guardUser->allPermissions[$name]); //use allPermissions instead of permissions array |
|---|
| 19 | | } |
|---|
| 20 | | }}} |