restrict 0.0.3 → 0.0.4
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +4 -0
- data/lib/restrict.rb +1 -0
- data/lib/restrict/gatekeeper.rb +5 -4
- data/lib/restrict/rails/controller.rb +1 -2
- data/lib/restrict/version.rb +1 -1
- data/spec/lib/restrict/gatekeeper_spec.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09e06d807f7718b921ec0d017f48ff530dcd9543
|
4
|
+
data.tar.gz: 75009eec3d441e82bd472ab8b263080fcc45a8f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 436c9d5a3c3c85463ea8685660c99f5263be59d55d064282d6dcd8a200f0533d9e1a4913142ebb2191eab8478e1a6d61b08e72a747f6979f88464958961cd907
|
7
|
+
data.tar.gz: 3a79026f12d31af31fcde2904ef3d860c519649be71c54e7ec059933c3b09e59fc4a22a4c51f05f5a39ba8f6e38fd519223b2a2b31618869c229c7499e1b8d50
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -58,6 +58,10 @@ Restrict.config.authentication_validation_method = :current_user
|
|
58
58
|
|
59
59
|
You may set the method that is used to figure out whether a user is signed in or not to whatever you like, however it's default is `:user_signed_in?` which is the most common (devise) method in use.
|
60
60
|
|
61
|
+
## Todo Ideas
|
62
|
+
|
63
|
+
* restrict :all_actions, except: [:new], allow_if: 'dsfsdf'
|
64
|
+
|
61
65
|
## Contributing
|
62
66
|
|
63
67
|
You know how this works and bonus points for feature branches!
|
data/lib/restrict.rb
CHANGED
data/lib/restrict/gatekeeper.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
module Restrict
|
2
2
|
class Gatekeeper
|
3
3
|
def eye(controller)
|
4
|
-
|
5
|
-
|
4
|
+
Array(concerning_restrictions(controller)).each do |restriction|
|
5
|
+
handle_restriction(restriction, controller)
|
6
|
+
end
|
6
7
|
end
|
7
8
|
|
8
9
|
private
|
@@ -17,9 +18,9 @@ module Restrict
|
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
|
-
def
|
21
|
+
def concerning_restrictions(controller)
|
21
22
|
controller.restrictions or return
|
22
|
-
controller.restrictions.
|
23
|
+
controller.restrictions.select do |restriction|
|
23
24
|
restriction.concerning?(controller.action_name)
|
24
25
|
end
|
25
26
|
end
|
data/lib/restrict/version.rb
CHANGED
@@ -63,5 +63,17 @@ describe Restrict::Gatekeeper do
|
|
63
63
|
expect { gatekeeper.eye(controller) }.not_to raise_error
|
64
64
|
end
|
65
65
|
end
|
66
|
+
|
67
|
+
context 'with multiple restrictions' do
|
68
|
+
before do
|
69
|
+
controller.class.restrict :all_actions
|
70
|
+
controller.class.restrict :edit, allow_if: :falsy
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'denies access if any restriction fails' do
|
74
|
+
controller.current_user = user
|
75
|
+
expect { gatekeeper.eye(controller) }.to raise_error(Restrict::AccessDenied)
|
76
|
+
end
|
77
|
+
end
|
66
78
|
end
|
67
79
|
end
|