minican 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/minican/access_denied.rb +2 -3
- data/lib/minican/controller_additions.rb +21 -3
- data/lib/minican/helpers.rb +2 -3
- data/lib/minican/policy.rb +1 -1
- data/lib/minican/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bce0104e56811dbb5e0851380fc58580cf115a4
|
4
|
+
data.tar.gz: bcadf904c147b2f193a9fde0720ab2d59e3aa1d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64d6a80707ef962e002de0cc74c11e46550fd1c2fa3c824f1f6a4bee4603b7e0519bb0623c13f75265425b2dfafe3bdb90dd4577d8f34e38ee93ab0e89761453
|
7
|
+
data.tar.gz: d52eedb958ada4cc0184f9c20b2431df81e058a4f722a8070c69f2360eb5433e11e7b636ce498725730ec8c353f373d111d22d07b3b95d36428f5e591530eb5b
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Minican
|
2
2
|
class AccessDenied < StandardError
|
3
|
-
|
4
|
-
# This is raised when a policy fails in a controller via
|
3
|
+
# This is raised when a policy fails in a controller via
|
5
4
|
# {Minican::ControllerAdditions}
|
6
5
|
#
|
7
6
|
# @param [policy] The policy that authorized it
|
@@ -11,7 +10,7 @@ module Minican
|
|
11
10
|
|
12
11
|
# Human readable error message
|
13
12
|
def to_s
|
14
|
-
|
13
|
+
'You are not authorized to access this page'
|
15
14
|
end
|
16
15
|
end
|
17
16
|
end
|
@@ -4,14 +4,14 @@ module Minican
|
|
4
4
|
|
5
5
|
private
|
6
6
|
|
7
|
-
# Controller helper method to verify call method on
|
7
|
+
# Controller helper method to verify call method on
|
8
8
|
# policy. Raises {Minican::AccessDenied} if the policy
|
9
9
|
# method fails
|
10
10
|
#
|
11
11
|
# @param method [Symbol] method to be called on the policy
|
12
12
|
# @param object [Object] The object to apply the policy to
|
13
13
|
# @param user [User] The user object to pass to the method
|
14
|
-
#
|
14
|
+
#
|
15
15
|
# @visibility public
|
16
16
|
def authorize!(method, object, user = current_user)
|
17
17
|
policy = policy_for(object)
|
@@ -21,9 +21,27 @@ module Minican
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
# Controller helper method to filter out non-authorized
|
25
|
+
# objects from the passed in array
|
26
|
+
#
|
27
|
+
# @param method [Symbol] method to be called on each policy
|
28
|
+
# @param objects [Array] array of objects to filter
|
29
|
+
# @param user [User] The current user object to pass
|
30
|
+
# @return (Array)
|
31
|
+
#
|
32
|
+
# @visibility public
|
33
|
+
def filter_authorized!(method, objects, user = current_user)
|
34
|
+
object_array = Array(objects)
|
35
|
+
|
36
|
+
object_array.select do |object|
|
37
|
+
policy = policy_for(object)
|
38
|
+
policy.can?(method, user)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
24
42
|
# Helper method available in controllers and views
|
25
43
|
# that returns the value of the policy method
|
26
|
-
#
|
44
|
+
#
|
27
45
|
# @param (see #authorize!)
|
28
46
|
# @return (Boolean)
|
29
47
|
#
|
data/lib/minican/helpers.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Minican
|
2
2
|
module Helpers
|
3
|
-
|
4
3
|
private
|
5
4
|
|
6
5
|
# Returns a new policy for passed in object
|
@@ -13,8 +12,8 @@ module Minican
|
|
13
12
|
end
|
14
13
|
|
15
14
|
# Returns a policy class based on the object
|
16
|
-
# passed in. If object is a class, it will
|
17
|
-
# return itself, if it's an instance it will
|
15
|
+
# passed in. If object is a class, it will
|
16
|
+
# return itself, if it's an instance it will
|
18
17
|
# return a class based on its name.
|
19
18
|
#
|
20
19
|
# @param [object] The object to classify
|
data/lib/minican/policy.rb
CHANGED
data/lib/minican/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minican
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: appraisal
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.0.0.beta2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0.beta2
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|