Sha256: cf7ca65810c45e79c3a236ced714fb1c746bfb87caefcd319605232fef3ab586

Contents?: true

Size: 1.48 KB

Versions: 4

Compression:

Stored size: 1.48 KB

Contents

# ActionAuthorization
A base policy class for authorizing controller actions with access to the current_user and object.

## Installation
Add this line to your application's Gemfile:

```ruby
gem 'action_authorization'
```

And then execute:
```bash
bundle
```

Or install it with:
```bash
gem install action_authorization
```

## Requirements
ActionAuthorization requires a **current_user** method that returns the currently logged in user.

## Usage
Include the ActionAuthorization module in your ApplicationController (or indvidual controller(s))

```ruby
class ApplicationController < ActionController::Base
  include ActionAuthorization
end
```

Create an authorization policy for a resource.
``` ruby
class DocumentPolicy < ActionAuthorization::BasePolicy
  def show?
    document.owner == user
  end
end
```

Call **authorize** method in controller action.
```ruby
class DocumentController < ApplicationController
  def show
    @document = authorize(Document.find(params[:id]))
  end
end
```

Pass a **policy_class** to authorize to override the default resource based policy.
```ruby
class DocumentController < ApplicationController
  def show
    @document = authorize(Document.find(params[:id]), policy_class: UserOwnerPolicy)
  end
end
```

Check if authorized before displaying a link in the view.

```erb
<%= link_to(@document.name, @document) if policy(@document).show? %>
```

## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
action_authorization-0.3.3 README.md
action_authorization-0.3.2 README.md
action_authorization-0.3.1 README.md
action_authorization-0.3.0 README.md