Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with permission ID caching #227

Closed
Kovah opened this issue May 5, 2018 · 5 comments
Closed

Problem with permission ID caching #227

Kovah opened this issue May 5, 2018 · 5 comments

Comments

@Kovah
Copy link

Kovah commented May 5, 2018

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
Copy link
Author

Kovah commented May 6, 2018

Seems to be related to #224

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

@REJack
Copy link
Collaborator

REJack commented May 7, 2018

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
Copy link
Contributor

korllan commented May 7, 2018

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

@REJack
Copy link
Collaborator

REJack commented May 16, 2018

#230 is merged, it should fixed now 😄

@REJack
Copy link
Collaborator

REJack commented Nov 11, 2018

Issue closed

@REJack REJack closed this as completed Nov 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants