Skip to content

bitzesty/declarative_authorization

 
 

Repository files navigation

Original docs: https://github.com/stffn/declarative_authorization/blob/master/README.rdoc

This fork keeps Declarative Authorization working on newer Rails versions, including Rails 8 compatibility work, while aiming for backwards compatibility as far as Rails 4.2 and Ruby 2.2 on a best-effort basis.

It also includes performance improvements for larger authorization rule sets and repeated permission checks:

  • indexed rule lookup by context, role, and privilege
  • cached flattened role and privilege hierarchies
  • fast-path handling for unconditional rules
  • per-check caching of repeated if_attribute value blocks
  • per-check caching of repeated nested if_permitted_to checks
  • opt-in request-local caching for repeated permit? / permitted_to? calls

The request-local cache is deliberately short lived and thread local. It does not use Redis, Memcached, or Rails.cache, and it does not cache permit! exception behavior.

To enable request-local permission caching around a block:

Authorization.with_permission_cache do
  authorization_engine.permit?(:show, object: record, user: current_user)
end

For controllers with repeated view/helper permission checks:

class ApplicationController < ActionController::Base
  cache_permission_checks
end

Call Authorization.clear_cache! after permission-relevant writes inside a cached block/request if the same request can re-check mutated objects or roles.

Branch r5: Build Status

Running tests for DA

cp gemfiles/{RAILS_VERSION}.gemfile Gemfile
bundle

bundle exec rake test

Run the opt-in performance tests with:

bundle exec rake test:performance

Run the generic authorization benchmark with:

ruby benchmarks/authorization_rules_benchmark.rb

About

An authorization plugin for Rails

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Ruby 95.3%
  • HTML 4.7%