Using Authority with Dossier reports

Nathan Long edited this page Jun 21, 2013 · 6 revisions

To use Authority with Dossier in a Rails app, you need to do two things:

1) Configure the reports controller

# config/initializers/dossier.rb
Rails.application.config.to_prepare do
  Dossier::ReportsController.authorize_actions_for :report_class, actions: {multi: :read}
  Dossier::Report.send(:include, Authority::Abilities)
  Dossier::MultiReport.send(:include, Authority::Abilities)

2) Point your reports to an authorizer

class MyAwesomeReport < Dossier::Report
  self.authorizer_name = '::ReportsAuthorizer'

That's it! You can hide report links as usual: if current_user.can_read?(MyAwesomeReport). The controller side is already handled.