roadblock 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -10
- data/lib/roadblock.rb +1 -0
- data/lib/roadblock/authorizer.rb +14 -0
- data/lib/roadblock/stack.rb +19 -0
- data/lib/roadblock/version.rb +1 -1
- data/roadblock.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb40eb1426760686de8ffb9c7f9df67067b2f179
|
4
|
+
data.tar.gz: f08cb942d2f15451ce06edce262b8d38093bc924
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
45
|
+
auth_object.teams.include?(team)
|
43
46
|
end
|
44
47
|
|
45
48
|
def can_write?(team)
|
46
49
|
scopes.include?("write_teams") && (
|
47
|
-
|
48
|
-
|
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
|
-
|
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
|
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 )
|
data/lib/roadblock.rb
CHANGED
data/lib/roadblock/authorizer.rb
CHANGED
@@ -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)
|
data/lib/roadblock/stack.rb
CHANGED
@@ -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
|
|
data/lib/roadblock/version.rb
CHANGED
data/roadblock.gemspec
CHANGED
@@ -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 = "
|
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.
|
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:
|
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:
|
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.
|
99
|
+
rubygems_version: 2.2.2
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: A simple authorization library.
|