Skip to content
This repository has been archived by the owner on Nov 19, 2019. It is now read-only.

Commit

Permalink
Whitespace cleanup
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
Nathan Long committed Apr 11, 2013
1 parent 34b85fb commit de65e5d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
28 changes: 14 additions & 14 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ It requires that you already have some kind of user object in your application,

Using Authority, you have:

- Broad, **class-level** rules. Examples:
- Broad, **class-level** rules. Examples:
- "Basic users cannot delete any Widget."
- "Only admin users can create Offices."
- Fine-grained, **instance-level** rules. Examples:
- Fine-grained, **instance-level** rules. Examples:
- "Management users can only edit schedules with date ranges in the future."
- "Users can't create playlists more than 20 songs long unless they've paid."
- A clear syntax for permissions-based views. Examples:
Expand All @@ -54,15 +54,15 @@ Using Authority, you have:

Most importantly, you have **total flexibility**: Authority does not constrain you into using a particular scheme of roles and/or permissions.

Authority lets you control access based on:
Authority lets you control access based on:

- Roles in your app's database ([rolify](http://github.com/EppO/rolify) makes this easy)
- Roles in a separate, single-sign-on app
- Users' points (like StackOverflow)
- Time and date
- Weather, stock prices, vowels in the user's name, or **anything else you can check with Ruby**

All you have to do is define the methods you need on your authorizers. You have all the flexibility of normal Ruby classes.
All you have to do is define the methods you need on your authorizers. You have all the flexibility of normal Ruby classes.

**You** make the rules; Authority enforces them.

Expand All @@ -80,7 +80,7 @@ You can specify a model's authorizer using the class method `authorizer_name=`.

Some example groupings:

Simplest case Logical groups Most granular
Simplest case Logical groups Most granular

ApplicationAuthorizer ApplicationAuthorizer ApplicationAuthorizer
+ + +
Expand All @@ -106,8 +106,8 @@ The authorization process generally flows like this:
+ # If you don't, the inherited one
| # calls `default`...
v
AdminAuthorizer.default(:creatable, current_user) # *You define this method.*
# If you don't, it will use the one
AdminAuthorizer.default(:creatable, current_user) # *You define this method.*
# If you don't, it will use the one
# inherited from ApplicationAuthorizer.
# (Its parent, Authority::Authorizer,
# defines the method as `return false`.)
Expand Down Expand Up @@ -145,7 +145,7 @@ This option determines what methods are added to your users, models and authoriz

```ruby
# Whatever class represents a logged-in user in your app
class User
class User
# Adds `can_create?(resource)`, etc
include Authority::UserAbilities
...
Expand Down Expand Up @@ -195,13 +195,13 @@ class ScheduleAuthorizer < ApplicationAuthorizer
end

# undefined; calls `ScheduleAuthorizer.default(:updatable, user)`
ScheduleAuthorizer.updatable_by?(user)
ScheduleAuthorizer.updatable_by?(user)
```

As you can see, you can specify different logic for every method on every model, if necessary. On the other extreme, you could simply supply a [default method](#default_methods) that covers all your use cases.

<a name="passing_options">
#### Passing Options
#### Passing Options

Any options you pass when checking permissions will be passed right up the chain. One use case for this would be if you needed an associated instance in order to do a class-level check. For example:

Expand Down Expand Up @@ -238,7 +238,7 @@ class ApplicationAuthorizer < Authority::Authorizer
def self.default(able, user)
has_role_granting?(user, able) || user.admin?
end

protected

def has_role_granting(user, able)
Expand All @@ -264,7 +264,7 @@ One nice thing about putting your authorization logic in authorizers is the ease
# An authorizer shared by several admin-only models
describe AdminAuthorizer do

before :each do
before :each do
@user = FactoryGirl.build(:user)
@admin = FactoryGirl.build(:admin)
end
Expand Down Expand Up @@ -329,7 +329,7 @@ class LlamasController < ApplicationController
# Check class-level authorizations before all actions except :create
# Also, to authorize this controller's 'neuter' action, ask whether `current_user.can_update?(Llama)`
authorize_actions_for Llama, :except => :create, :actions => {:neuter => :update},

# To authorize this controller's 'breed' action, ask whether `current_user.can_create?(Llama)`
# To authorize its 'vaporize' action, ask whether `current_user.can_delete?(Llama)`
authority_actions :breed => 'create', :vaporize => 'delete'
Expand All @@ -338,7 +338,7 @@ class LlamasController < ApplicationController

def edit
@llama = Llama.find(params[:id])
authorize_action_for(@llama) # Check to see if you're allowed to edit this llama. failure == SecurityViolation
authorize_action_for(@llama) # Check to see if you're allowed to edit this llama. failure == SecurityViolation
end

def update
Expand Down
2 changes: 1 addition & 1 deletion lib/authority.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def self.adjectives
# @return [Model] resource instance
def self.enforce(action, resource, user, options = {})
unless action_authorized?(action, resource, user, options)
raise SecurityViolation.new(user, action, resource)
raise SecurityViolation.new(user, action, resource)
end
resource
end
Expand Down
6 changes: 3 additions & 3 deletions lib/generators/authority/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Generators
class InstallGenerator < Rails::Generators::Base

source_root File.expand_path("../../templates", __FILE__)
desc "Creates an Authority initializer for your application."
desc "Creates an Authority initializer for your application."

def do_all
create_authorizers_directory
Expand All @@ -19,14 +19,14 @@ def do_all
RUBY
puts message.strip_heredoc

end

private

def create_authorizers_directory
# Creates empty directory if none; doesn't empty the directory
empty_directory "app/authorizers"
empty_directory "app/authorizers"
end

def copy_application_authorizer
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/templates/application_authorizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class ApplicationAuthorizer < Authority::Authorizer

# Any class method from Authority::Authorizer that isn't overridden
# will call its authorizer's default method.
# will call its authorizer's default method.
#
# @param [Symbol] adjective; example: `:creatable`
# @param [Object] user - whatever represents the current user in your app
Expand Down
6 changes: 3 additions & 3 deletions lib/generators/templates/authority_initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Default is:
#
# config.user_method = :current_user

# CONTROLLER_ACTION_MAP
# =====================
# For a given controller method, what verb must a user be able to do?
Expand All @@ -33,7 +33,7 @@
# ABILITIES
# =========
# Teach Authority how to understand the verbs and adjectives in your system. Perhaps you
# need {:microwave => 'microwavable'}. I'm not saying you do, of course. Stop looking at
# need {:microwave => 'microwavable'}. I'm not saying you do, of course. Stop looking at
# me like that.
#
# Defaults are as follows:
Expand All @@ -48,7 +48,7 @@
# LOGGER
# ======
# If a user tries to perform an unauthorized action, where should we log that fact?
# Provide a logger object which responds to `.warn(message)`, unless your
# Provide a logger object which responds to `.warn(message)`, unless your
# security_violation_handler calls a different method.
#
# Default is:
Expand Down
6 changes: 3 additions & 3 deletions spec/authority/controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ def self.before_filter(*args) ; end
end

let(:controller_instance) do
controller_class.new.tap do |cc|
controller_class.new.tap do |cc|
cc.stub(Authority.configuration.user_method).and_return(user)
end
end
end

let(:user) { ExampleUser.new }
Expand Down Expand Up @@ -275,7 +275,7 @@ def self.before_filter(*args) ; end
end

end

end

end

0 comments on commit de65e5d

Please sign in to comment.