How to reset rule cache ? #283
Unanswered
nflorentin
asked this question in
Q&A
Replies: 1 comment
-
I just found out that using |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
First of all, thanks for your amazing work, I'm really appreciate action_policy, by far the best gem for authorization !
My little issue is I'm wondering how to reset a rule cached.
I seemed to have understand that it takes place here in
@__rules_cache__
.https://github.com/palkan/action_policy/blob/1f7b80bab2b79b82cc1ffe0cdd417cfa7f4b328d/lib/action_policy/policy/cached_apply.rb
I browsed the doc with no success and did not find an answer reading the codebase.
My use-case is very simple:
1/ I'm the owner of a project, so I'm allowed to transfer the ownership (the policy returns true)
2/ I transfer the ownership of the project to another user
3/ I'm no longer the owner, I can't transfer the ownership anymore (the policy should returns false)
In step 1, I call
allowed_to?(:edit, project, with: Projects::OwnershipPolicy)
.In step 3, when I render the view in my server response, I call the same
allowed_to?
again and it returns true because the result is in cache. I would like to reset the cache in my controller action, in order to make it worked.I could use
Projects::OwnershipPolicy.new(project).edit?
but I found it ugly to have authorizations computed with different syntaxes.Thanks in advance for your answer !
Beta Was this translation helpful? Give feedback.
All reactions