pastore 0.0.2 → 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/Gemfile.lock +1 -1
- data/lib/pastore/guards/settings.rb +20 -7
- data/lib/pastore/guards.rb +1 -1
- data/lib/pastore/version.rb +1 -1
- 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: 77eb4179686bdc087cb3b82d5187714473d61d178a690ece61d23f4f238fc973
|
4
|
+
data.tar.gz: 66432435a048060675f5f61b966a99e917a8a810c8d713736202e334e510d42c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 929a9b868a8d659728e7ebe2688fdec531ba9b718c195d40aeb2bb3ac313d59bac4c6ab6e3180f58a43af82930a7ae45bc5409ef0bfa439c4d4055d281d203a6
|
7
|
+
data.tar.gz: ea444e38cad30fb09fd6cfcf86fab000abcba0f3451ec2834e35bb13b7dca8fd062dc74d56879cf8f0c779e2b4fccb9d674dc34e7e2e36c238d4da6c330bb9cc
|
data/Gemfile.lock
CHANGED
@@ -4,15 +4,16 @@ module Pastore
|
|
4
4
|
module Guards
|
5
5
|
# Implements a structure where to store the settings for the guards.
|
6
6
|
class Settings # rubocop:disable Metrics/ClassLength
|
7
|
-
|
8
|
-
attr_reader :strategy
|
7
|
+
attr_writer :role_detector, :forbidden_cbk
|
9
8
|
|
10
|
-
def initialize
|
9
|
+
def initialize(superklass)
|
10
|
+
@super_guards = superklass.pastore_guards if superklass.respond_to?(:pastore_guards)
|
11
|
+
@superclass = superklass
|
11
12
|
reset!
|
12
13
|
end
|
13
14
|
|
14
15
|
def reset!
|
15
|
-
@strategy =
|
16
|
+
@strategy = nil
|
16
17
|
@role_detector = nil
|
17
18
|
@forbidden_cbk = nil
|
18
19
|
@actions = {}
|
@@ -21,6 +22,14 @@ module Pastore
|
|
21
22
|
@forced_guards = []
|
22
23
|
end
|
23
24
|
|
25
|
+
def role_detector
|
26
|
+
@role_detector || @super_guards&.role_detector
|
27
|
+
end
|
28
|
+
|
29
|
+
def forbidden_cbk
|
30
|
+
@forbidden_cbk || @super_guards&.forbidden_cbk
|
31
|
+
end
|
32
|
+
|
24
33
|
def use_allow_strategy!
|
25
34
|
@strategy = :allow
|
26
35
|
end
|
@@ -29,6 +38,10 @@ module Pastore
|
|
29
38
|
@strategy = :deny
|
30
39
|
end
|
31
40
|
|
41
|
+
def strategy
|
42
|
+
@strategy || @super_guards&.strategy || :deny
|
43
|
+
end
|
44
|
+
|
32
45
|
def permit_role(*roles)
|
33
46
|
new_roles = [roles].flatten.compact.uniq.map(&:to_s)
|
34
47
|
conflicts = @buffer.fetch(:denied_roles, []) & new_roles
|
@@ -101,9 +114,9 @@ module Pastore
|
|
101
114
|
|
102
115
|
# Returns the current role for the controller.
|
103
116
|
def current_role(controller)
|
104
|
-
return nil if
|
117
|
+
return nil if role_detector.blank?
|
105
118
|
|
106
|
-
controller.instance_exec(
|
119
|
+
controller.instance_exec(&role_detector)&.to_s
|
107
120
|
end
|
108
121
|
|
109
122
|
def access_granted?(controller, action_name) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
@@ -119,7 +132,7 @@ module Pastore
|
|
119
132
|
|
120
133
|
return false if action&.dig(:denied_roles)&.include?(role)
|
121
134
|
|
122
|
-
|
135
|
+
strategy == :allow || (strategy == :deny && action&.dig(:permitted_roles)&.include?(role)) || false
|
123
136
|
end
|
124
137
|
|
125
138
|
private
|
data/lib/pastore/guards.rb
CHANGED
@@ -28,7 +28,7 @@ module Pastore
|
|
28
28
|
attr_accessor :_pastore_guards
|
29
29
|
|
30
30
|
def pastore_guards
|
31
|
-
self._pastore_guards ||= Pastore::Guards::Settings.new
|
31
|
+
self._pastore_guards ||= Pastore::Guards::Settings.new(superclass)
|
32
32
|
end
|
33
33
|
|
34
34
|
# Sets the logic to use for current role detection.
|
data/lib/pastore/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pastore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Groza Sergiu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|