roadblock 0.1.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17810d3503fa0ba50de4e55d1a73ed4c5ef25a3f
4
- data.tar.gz: 0febc120ca09459feaa6645323ae22f1d348a52f
3
+ metadata.gz: cb40eb1426760686de8ffb9c7f9df67067b2f179
4
+ data.tar.gz: f08cb942d2f15451ce06edce262b8d38093bc924
5
5
  SHA512:
6
- metadata.gz: cd145df7d71e5825164290e904c2a5817e4ea1b67922a3c9e818af20e3cb33e0afb169eccb095ccd3dceef6f66225a52d836ddc4fad7a4f1d1d28a8b9ddf4b6b
7
- data.tar.gz: 81693f50acea05a1cc0a36af7bf3c0d31fa5690ace3bc1d3366e49fabb4075f561f0196e489728f4568fa4f362d8f54bfbdf6928c000afed57ca9dcd4e68ff7a
6
+ metadata.gz: 66d3d12b89928d3d12105162fb3611f31765d3aaa6486f558c65df206cc2ee3f7111c79e73c28e2f046860e81078ef750a2058d1ca87d4c84a881913282bf675
7
+ data.tar.gz: 24f7c0257439053889ae0cc5079ad93ba850c9d54265fe50144ca3fa7c5377378893ad54a945d71a8454328230593bfd72042c4b16db54cc8cfaa60f0379cde9
data/README.md CHANGED
@@ -1,12 +1,15 @@
1
1
  # Roadblock
2
2
 
3
+ [![Codeship Status for teamsnap/roadblock](https://www.codeship.io/projects/33848a30-df96-0131-12c9-6668820c1116/status)](https://www.codeship.io/projects/25009)
4
+
3
5
  [![Gem Version](https://badge.fury.io/rb/roadblock.png)](http://badge.fury.io/rb/roadblock)
4
- [![Semaphore](https://semaphoreapp.com/api/v1/projects/f1ccf0c3ff7565f975caef0fdfcf649f24f033fb/118939/shields_badge.png)](https://semaphoreapp.com/minter/roadblock)
5
6
  [![Code Climate](https://codeclimate.com/github/teamsnap/roadblock.png)](https://codeclimate.com/github/teamsnap/roadblock)
6
7
  [![Coverage Status](https://coveralls.io/repos/teamsnap/roadblock/badge.png?branch=master)](https://coveralls.io/r/teamsnap/roadblock?branch=master)
7
8
  [![Dependency Status](https://gemnasium.com/teamsnap/roadblock.png)](https://gemnasium.com/teamsnap/roadblock)
8
9
  [![License](http://img.shields.io/license/MIT.png?color=green)](http://opensource.org/licenses/MIT)
9
10
 
11
+ [Documentation](http://www.rubydoc.info/github/teamsnap/roadblock)
12
+
10
13
  A simple authorization library.
11
14
 
12
15
  ![Roadblock](http://i.imgur.com/RzJlc7D.jpg)
@@ -39,13 +42,13 @@ class TeamAuthorizer
39
42
 
40
43
  def can_read?(team)
41
44
  scopes.include?("read") &&
42
- user.teams.include?(team)
45
+ auth_object.teams.include?(team)
43
46
  end
44
47
 
45
48
  def can_write?(team)
46
49
  scopes.include?("write_teams") && (
47
- user.managed_teams.include?(team) ||
48
- user.owned_teams.include?(team)
50
+ auth_object.managed_teams.include?(team) ||
51
+ auth_object.owned_teams.include?(team)
49
52
  )
50
53
  end
51
54
  end
@@ -79,7 +82,7 @@ class TeamAuthorizer
79
82
  include Roadblock.authorizer
80
83
 
81
84
  def can_read?(team)
82
- user.teams.include?(team)
85
+ auth_object.teams.include?(team)
83
86
  end
84
87
  end
85
88
 
@@ -87,7 +90,7 @@ class AdminAuthorizer
87
90
  include Roadblock.authorizer
88
91
 
89
92
  def can?(action, object)
90
- if user.is_admin?
93
+ if auth_object.is_admin?
91
94
  true
92
95
  else
93
96
  yield(object)
@@ -104,10 +107,6 @@ stack.can?(:read, team) # or stack.can_read?(team)
104
107
  stack.can?(:read, teams) # or stack.can_read?(teams)
105
108
  ```
106
109
 
107
- ## Roadmap
108
-
109
- - Add optional faliure messages
110
-
111
110
  ## Contributing
112
111
 
113
112
  1. Fork it ( http://github.com/teamsnap/roadblock/fork )
@@ -3,6 +3,7 @@ require_relative "roadblock/stack"
3
3
  require_relative "roadblock/version"
4
4
 
5
5
  module Roadblock
6
+ # Include Roadblock.authorizer into a class to make it an authorizer.
6
7
  def self.authorizer
7
8
  Module.new do
8
9
  def self.included(descendant)
@@ -1,10 +1,24 @@
1
1
  module Roadblock
2
2
  module Authorizer
3
+ # Creates an authorizer for the given object and any provided scopes.
4
+ #
5
+ # @param auth_object [Object] the object (usually a user) to authorize for.
6
+ # @param scopes [Array<Symbol>] the scopes (if any) associated with the
7
+ # auth_object.
8
+ #
9
+ # @return [self]
3
10
  def initialize(auth_object, scopes: [])
4
11
  self.auth_object = auth_object
5
12
  self.scopes = scopes
6
13
  end
7
14
 
15
+ # Returns whether the current auth_object can perform the given action on
16
+ # the provided object.
17
+ #
18
+ # @param action [Symbol] the action to check. Most often :read or :write.
19
+ # @param object [Object] the object to authorize against.
20
+ #
21
+ # @return [true, false]
8
22
  def can?(action, object)
9
23
  if block_given?
10
24
  yield(object)
@@ -2,16 +2,35 @@ module Roadblock
2
2
  class Stack
3
3
  NULL_AUTHORIZER_PROC = lambda { |object| false }
4
4
 
5
+ # The Stack allows you to create middleware layers of authorizer to reduce
6
+ # duplication, escape early, etc.
7
+ #
8
+ # @param auth_object [Object] the object to authorize for. Usually a user.
9
+ # @param scopes [Array<Symbol>] the scopes (if any) associated with the
10
+ # auth_object.
11
+ #
12
+ # @return [self]
5
13
  def initialize(auth_object, scopes: [])
6
14
  self.auth_object = auth_object
7
15
  self.scopes = scopes
8
16
  self.authorizers = []
9
17
  end
10
18
 
19
+ # Adds one or more authorizers to the Stack.
20
+ #
21
+ # @param *auths [Authorizer] the authorizer(s) to add to the Stack.
22
+ #
23
+ # @return [Array<Authorizer>] the current stack.
11
24
  def add(*auths)
12
25
  self.authorizers = authorizers + auths
13
26
  end
14
27
 
28
+ # Checks if the given action can be performed on all the objects.
29
+ #
30
+ # @param action [Symbol] the action the authorize for.
31
+ # @param objects [Array<Object>] the objects to authorize against.
32
+ #
33
+ # @return [true, false]
15
34
  def can?(action, objects)
16
35
  objects = [*objects]
17
36
 
@@ -1,3 +1,3 @@
1
1
  module Roadblock
2
- VERSION = "0.1.1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -15,7 +15,7 @@ the current user in your rails controller can read/write the object they're
15
15
  attempting to access.
16
16
  DESC
17
17
  spec.summary = "A simple authorization library."
18
- spec.homepage = "https://github.com/teamsnap/roadblock"
18
+ spec.homepage = "http://teamsnap.github.io/roadblock"
19
19
  spec.license = "MIT"
20
20
 
21
21
  spec.files = `git ls-files`.split($/)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roadblock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Emmons
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-20 00:00:00.000000000 Z
12
+ date: 2015-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -76,7 +76,7 @@ files:
76
76
  - roadblock.gemspec
77
77
  - spec/roadblock_spec.rb
78
78
  - spec/spec_helper.rb
79
- homepage: https://github.com/teamsnap/roadblock
79
+ homepage: http://teamsnap.github.io/roadblock
80
80
  licenses:
81
81
  - MIT
82
82
  metadata: {}
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  version: '0'
97
97
  requirements: []
98
98
  rubyforge_project:
99
- rubygems_version: 2.2.0
99
+ rubygems_version: 2.2.2
100
100
  signing_key:
101
101
  specification_version: 4
102
102
  summary: A simple authorization library.