emreakay / CodeIgniter-Aauth

Authorization, Authentication and User Management library for Codeigniter 2.x and 3.x to make easy user management and permission operations
http://emreakay.com
GNU Lesser General Public License v3.0
393 stars 234 forks source link

Problem with permission ID caching #227

Closed Kovah closed 5 years ago

Kovah commented 6 years ago

Hello, first of all thank you for your work on this library. But I have a serious problem with Aauth's permission caching.

The Situation

I use Aauth to add a bunch of new permissions by running something like this:

$permissions = [
  'perm1', 'perm2', 'perm3', 'perm4', 'perm5', 'perm6',...
];
foreach ($permissions as $permission) {
  $this->aauth->create_perm($permission);
}

After that I want to assign these permissions to the default role. Therefore I am using the following code:

foreach ($permissions as $permission) {
  $this->aauth->allow_group('default', $permission);
}

The Problem

Aauth does not save these group-permission relations in the database. On investigation I found that Aauth caches all permission IDs in $this->cache_perm_id in the construction method. I thought that running $this->aauth->get_perm($permission) to just get the permission ID would work but it also tries to get the permission ID from the cache. So I can't create a permission and assign it to a group in the same request?!

I am not sure if I miss something but there is no method to rebuild the cache or something similar and there is no mention of any caching in the documentation. In the moment that would mean I have to re-initialize Aauth just to access the permissions that are already saved in the database?

My suggestion would be to at least add a param for the get_perm($permission) method to force a database query for the given permission.

Kovah commented 6 years ago

Seems to be related to #224

Isn't the master branch the current stable and tested branch?

REJack commented 6 years ago

You are correct in the actual state you can't create and assign a permission in the same request. I'll change the precache_ids() to public then you can rebuild the cache.

The 2.5-stable branch is update to v2.5.14 (latest version)

korllan commented 6 years ago

@REJack Change precache_ids() to public is not the best way to fix this problem, i made a PR for fix that #230

REJack commented 6 years ago

230 is merged, it should fixed now 😄

REJack commented 5 years ago

Issue closed