restrict 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a311cd60d3877b78f14d2baa83f6155a86a1f3f2
4
- data.tar.gz: 4a974335ee21c330485d91de9cc54f9d861812dc
3
+ metadata.gz: 09e06d807f7718b921ec0d017f48ff530dcd9543
4
+ data.tar.gz: 75009eec3d441e82bd472ab8b263080fcc45a8f6
5
5
  SHA512:
6
- metadata.gz: a49f1610e19cb448b598ff93e965e277788e1e7e482b2541eb5c6275a7b290afbdd1397a51f55dd518894063b34e63dc85ab835e832b0e6a8de52b667f8a3b14
7
- data.tar.gz: c50d8015c07fb09a5061f606b2ca8aaeacf45c9d5dc3ed4e0d50d445fef2a849e0372ba31854ed56b0e856d673996d397aa6ff446948939eb1764cc49a403c67
6
+ metadata.gz: 436c9d5a3c3c85463ea8685660c99f5263be59d55d064282d6dcd8a200f0533d9e1a4913142ebb2191eab8478e1a6d61b08e72a747f6979f88464958961cd907
7
+ data.tar.gz: 3a79026f12d31af31fcde2904ef3d860c519649be71c54e7ec059933c3b09e59fc4a22a4c51f05f5a39ba8f6e38fd519223b2a2b31618869c229c7499e1b8d50
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ [0.0.4] - 2014-08-23
2
+ * Bugfixes
3
+ * Multiple restrictions for the same action are possible
4
+
1
5
  [0.0.3] - 2014-08-23
2
6
  * Added railtie to require controller extension instantly
3
7
  * Added :all_actions matcher
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
@@ -1,4 +1,5 @@
1
1
  require 'active_support'
2
+ require 'active_support/core_ext/class/attribute.rb'
2
3
 
3
4
  require 'restrict/version'
4
5
  require 'restrict/configuration'
@@ -1,8 +1,9 @@
1
1
  module Restrict
2
2
  class Gatekeeper
3
3
  def eye(controller)
4
- restriction = current_restriction(controller)
5
- restriction and handle_restriction(restriction, controller)
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 current_restriction(controller)
21
+ def concerning_restrictions(controller)
21
22
  controller.restrictions or return
22
- controller.restrictions.find do |restriction|
23
+ controller.restrictions.select do |restriction|
23
24
  restriction.concerning?(controller.action_name)
24
25
  end
25
26
  end
@@ -4,8 +4,7 @@ module Restrict
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- cattr_accessor :restrictions
8
- self.restrictions ||= []
7
+ class_attribute :restrictions
9
8
  before_filter :invoke_gatekeeper
10
9
  end
11
10
 
@@ -1,3 +1,3 @@
1
1
  module Restrict
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restrict
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Opper