How to reload authorization rules?

102 views
Skip to first unread message

Bishma Stornelli

unread,
Aug 24, 2012, 10:46:38 AM8/24/12
to declarative_...@googlegroups.com
I'm trying to store roles and permissions in the database and it's working fine. The only problem I have is that I need to reload the server for changes to take effect.

Is there a way to force Declarative Authorization to reload the authorization rules?

I tried modifying Authorization::Engine.instance like this:

def self.instance (dsl_file = nil)
    @@instance = new(dsl_file)
end

And it works but it reload rules on every request. I could accept that but when I'm testing with cucumber, I don't know why it doesn't work.

My scenario start like this:

  Given I am authenticated as "<email>"
  And I am authorized to "<permission>"
  When I visit the "<page>" page

If I use at that point save_and_open_page I get the not authorized error. It works fine out of cucumber. Any thoughts?


Edward Rudd

unread,
Aug 24, 2012, 12:28:09 PM8/24/12
to declarative_...@googlegroups.com

Pull down the latest code from github as there are some fixes to the auto-reloading of rule files in dev mode.. Take a look at that code to see how lazy-reloading of rules only when they change can work.

Specifically this commit.  https://github.com/stffn/declarative_authorization/commit/a5e6beac067e8339c73b76498a4fa817ba786ba6

On 2012-08-24 10:46, Bishma Stornelli wrote:

I'm trying to store roles and permissions in the database and it's working fine. The only problem I have is that I need to reload the server for changes to take effect.

Is there a way to force Declarative Authorization to reload the authorization rules?
I tried modifying Authorization::Engine.instance like this:
def self.instance (dsl_file = nil)
    @@instance = new(dsl_file)
end
And it works but it reload rules on every request. I could accept that but when I'm testing with cucumber, I don't know why it doesn't work.
My scenario start like this:
  Given I am authenticated as ""
  And I am authorized to ""
  When I visit the "" page
If I use at that point save_and_open_page I get the not authorized error. It works fine out of cucumber. Any thoughts?

 

--
You received this message because you are subscribed to the Google Groups "declarative_authorization" group.
To view this discussion on the web visit https://groups.google.com/d/msg/declarative_authorization/-/kTzqNYdasrsJ.
To post to this group, send email to declarative_...@googlegroups.com.
To unsubscribe from this group, send email to declarative_author...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/declarative_authorization?hl=en.

 

 

Bishma Stornelli

unread,
Aug 25, 2012, 8:59:39 AM8/25/12
to declarative_...@googlegroups.com
Thank you very much.

That wasn't what I need but gave me the idea to make it.


It allows me to use this code in my Role class:

def reload_authorization_rules
    Authorization::Engine.force_reload
end

And now I can have my roles and permissions stored in the database and updated after_save roles.
To unsubscribe from this group, send email to declarative_authorization+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages