restrict 0.1.0 → 0.1.1
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 +3 -0
- data/lib/restrict/rails/controller.rb +12 -12
- data/lib/restrict/version.rb +1 -1
- data/spec/lib/restrict/rails/controller_spec.rb +18 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64c201583341d1cfab486ba72a9a35562a2e453b15586f25a5403177e8e6af48
|
4
|
+
data.tar.gz: c73bcd768f66647315925df95a003e236fd31b1a22384a6670cb94ac5ab8cc96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ff470658e364c155179b26ca04c6ba98c342ebc7c6a8bf3d1019f811c08c6ef9e726d06da5e8baa09f75dbbdba74c74553c4f664274f6db04741dbb7728a734
|
7
|
+
data.tar.gz: 66baa2c8609ba7cc6e2a47fc013e77db2dbb161c7329f6d0b41488d0ac718048ff8ba1a492b74a05363d26a371cf0feb28ffb700030e5356500d8e08b60e77f8
|
data/CHANGELOG.md
CHANGED
@@ -3,16 +3,12 @@ module Restrict
|
|
3
3
|
module Controller
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
def
|
7
|
-
|
6
|
+
def inherited(subclass)
|
7
|
+
subclass.extend Restrict::Rails::Controller
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
self.class.
|
12
|
-
if ancestor.instance_variable_get(:@restrict_gatekeeper_installed)
|
13
|
-
ancestor.__send__(:restrict_restrictions)
|
14
|
-
end
|
15
|
-
end.compact.flatten
|
10
|
+
def restrictions
|
11
|
+
inherited_restrictions + self.class.__send__(:restrict_restrictions)
|
16
12
|
end
|
17
13
|
|
18
14
|
module ClassMethods
|
@@ -29,10 +25,6 @@ module Restrict
|
|
29
25
|
@restrictions ||= []
|
30
26
|
end
|
31
27
|
|
32
|
-
def inherited(subclass)
|
33
|
-
subclass.include Restrict::Rails::Controller
|
34
|
-
end
|
35
|
-
|
36
28
|
# This could happen in included block as well, but often you need
|
37
29
|
# other before filters to happen before you actually check the
|
38
30
|
# restrictions, so lets set it where it is used in the code as well.
|
@@ -45,6 +37,14 @@ module Restrict
|
|
45
37
|
|
46
38
|
private
|
47
39
|
|
40
|
+
def inherited_restrictions
|
41
|
+
self.class.ancestors.map do |ancestor|
|
42
|
+
if ancestor.instance_variable_get(:@restrict_gatekeeper_installed)
|
43
|
+
ancestor.__send__(:restrict_restrictions)
|
44
|
+
end
|
45
|
+
end.compact.flatten
|
46
|
+
end
|
47
|
+
|
48
48
|
def invoke_gatekeeper
|
49
49
|
Restrict::Gatekeeper.new.eye(self)
|
50
50
|
end
|
data/lib/restrict/version.rb
CHANGED
@@ -58,4 +58,22 @@ describe Restrict::Rails::Controller do
|
|
58
58
|
expect(child).to have_restriction_on(:show).unless(:level3?)
|
59
59
|
end
|
60
60
|
end
|
61
|
+
|
62
|
+
describe 'applies inherited general restrictions additionally to explizit restrictions' do
|
63
|
+
let(:base) { ExampleController.new }
|
64
|
+
let(:controller) { InheritingController.new }
|
65
|
+
|
66
|
+
before do
|
67
|
+
base.class.restrict unless: :level1?
|
68
|
+
controller.class.restrict :show, unless: :level2?
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'does not leak restrictions into superclass' do
|
72
|
+
expect(base).to have_restriction_on(:show).unless(:level1?)
|
73
|
+
expect(base).not_to have_restriction_on(:show).unless(:level2?)
|
74
|
+
|
75
|
+
expect(controller).to have_restriction_on(:show).unless(:level1?)
|
76
|
+
expect(controller).to have_restriction_on(:show).unless(:level2?)
|
77
|
+
end
|
78
|
+
end
|
61
79
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restrict
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johannes Opper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|