miau 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +9 -9
- data/lib/miau/error.rb +0 -15
- data/lib/miau/storage.rb +4 -2
- data/lib/miau/version.rb +2 -1
- data/lib/miau.rb +17 -6
- 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: 11d358ab5fa86e9112dec38bcd2a30cf8f2001b35982eb9f68c4e354cbbedd17
|
4
|
+
data.tar.gz: 4380f2fe177ef71910d1456f357793b2822ca5a1d3a31cdd00ab76b57b1a25fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 560524d2fb53017cd0d5070d101ff29fc80ba573f4ef8c83df925c6a67355973887882ce7ad75f2936807580dcec666ac7fc1bb7ce1dbe13ab37566064c78ba5
|
7
|
+
data.tar.gz: 29e32b602528826c9a53ae14b7b8a9cf93bb77949775bea00d862dfbd6a60039140d7f15adb8728013eb733782e7870f9e726a2c8490ca82fe6d47e8c2fde1f5
|
data/Gemfile.lock
CHANGED
@@ -37,7 +37,7 @@ GEM
|
|
37
37
|
erubi (1.10.0)
|
38
38
|
i18n (1.8.11)
|
39
39
|
concurrent-ruby (~> 1.0)
|
40
|
-
loofah (2.
|
40
|
+
loofah (2.13.0)
|
41
41
|
crass (~> 1.0.2)
|
42
42
|
nokogiri (>= 1.5.9)
|
43
43
|
minitest (5.14.4)
|
@@ -45,7 +45,7 @@ GEM
|
|
45
45
|
racc (~> 1.4)
|
46
46
|
observr (1.0.5)
|
47
47
|
parallel (1.21.0)
|
48
|
-
parser (3.0.2
|
48
|
+
parser (3.0.3.2)
|
49
49
|
ast (~> 2.4.1)
|
50
50
|
racc (1.6.0)
|
51
51
|
rack (2.2.3)
|
@@ -58,10 +58,10 @@ GEM
|
|
58
58
|
loofah (~> 2.3)
|
59
59
|
rainbow (3.0.0)
|
60
60
|
rake (13.0.6)
|
61
|
-
regexp_parser (2.
|
61
|
+
regexp_parser (2.2.0)
|
62
62
|
rexml (3.2.5)
|
63
63
|
ricecream (0.2.0)
|
64
|
-
rubocop (1.
|
64
|
+
rubocop (1.23.0)
|
65
65
|
parallel (~> 1.10)
|
66
66
|
parser (>= 3.0.0.0)
|
67
67
|
rainbow (>= 2.2.2, < 4.0)
|
@@ -70,9 +70,9 @@ GEM
|
|
70
70
|
rubocop-ast (>= 1.12.0, < 2.0)
|
71
71
|
ruby-progressbar (~> 1.7)
|
72
72
|
unicode-display_width (>= 1.4.0, < 3.0)
|
73
|
-
rubocop-ast (1.
|
73
|
+
rubocop-ast (1.14.0)
|
74
74
|
parser (>= 3.0.1.1)
|
75
|
-
rubocop-performance (1.
|
75
|
+
rubocop-performance (1.12.0)
|
76
76
|
rubocop (>= 1.7.0, < 2.0)
|
77
77
|
rubocop-ast (>= 0.4.0)
|
78
78
|
ruby-progressbar (1.11.0)
|
@@ -82,9 +82,9 @@ GEM
|
|
82
82
|
simplecov_json_formatter (~> 0.1)
|
83
83
|
simplecov-html (0.12.3)
|
84
84
|
simplecov_json_formatter (0.1.3)
|
85
|
-
standard (1.
|
86
|
-
rubocop (= 1.
|
87
|
-
rubocop-performance (= 1.
|
85
|
+
standard (1.5.0)
|
86
|
+
rubocop (= 1.23.0)
|
87
|
+
rubocop-performance (= 1.12.0)
|
88
88
|
tzinfo (2.0.4)
|
89
89
|
concurrent-ruby (~> 1.0)
|
90
90
|
unicode-display_width (2.1.0)
|
data/lib/miau/error.rb
CHANGED
@@ -4,21 +4,6 @@ module Miau
|
|
4
4
|
class Error < StandardError; end
|
5
5
|
|
6
6
|
class NotAuthorizedError < Error
|
7
|
-
attr_reader :controller, :query, :policy
|
8
|
-
|
9
|
-
def initialize(options = {})
|
10
|
-
if options.is_a? String
|
11
|
-
message = options
|
12
|
-
else
|
13
|
-
@controller = options[:controller]
|
14
|
-
@query = options[:query]
|
15
|
-
@policy = options[:policy]
|
16
|
-
|
17
|
-
message = options.fetch(:message) { "not allowed to #{query} of #{controller} by #{policy.inspect}" }
|
18
|
-
end
|
19
|
-
|
20
|
-
super(message)
|
21
|
-
end
|
22
7
|
end
|
23
8
|
|
24
9
|
class NotDefinedError < Error
|
data/lib/miau/storage.rb
CHANGED
@@ -14,8 +14,10 @@ module Miau
|
|
14
14
|
|
15
15
|
def run(klass, action, user, resource)
|
16
16
|
policy = policy(klass, user, resource)
|
17
|
-
|
18
|
-
|
17
|
+
return policy.send(action) if policy.respond_to?(action)
|
18
|
+
|
19
|
+
msg = "class <#{klass} action <#{action}>"
|
20
|
+
raise Miau::NotDefinedError, msg
|
19
21
|
end
|
20
22
|
|
21
23
|
private
|
data/lib/miau/version.rb
CHANGED
data/lib/miau.rb
CHANGED
@@ -17,15 +17,15 @@ module Miau
|
|
17
17
|
|
18
18
|
def authorize!(resource = nil, hsh = {})
|
19
19
|
@_miau_authorization_performed = true
|
20
|
-
|
21
|
-
|
20
|
+
return true if authorized?(resource, hsh)
|
21
|
+
|
22
|
+
klass, action = klass_action(hsh)
|
23
|
+
msg = "class <#{klass} action <#{action}>"
|
24
|
+
raise Miau::NotAuthorizedError, msg
|
22
25
|
end
|
23
26
|
|
24
27
|
def authorized?(resource = nil, hsh = {})
|
25
|
-
klass = hsh
|
26
|
-
klass ||= params[:controller].camelize
|
27
|
-
action = hsh[:action]
|
28
|
-
action ||= params[:action]
|
28
|
+
klass, action = klass_action(hsh)
|
29
29
|
Miau::PolicyStorage.instance.run(klass, action, miau_user, resource)
|
30
30
|
end
|
31
31
|
|
@@ -44,4 +44,15 @@ module Miau
|
|
44
44
|
def miau_authorization_performed?
|
45
45
|
!!@_miau_authorization_performed
|
46
46
|
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def klass_action(hsh)
|
51
|
+
klass = hsh[:class]
|
52
|
+
klass ||= params[:controller].camelize
|
53
|
+
action = hsh[:action]
|
54
|
+
action ||= params[:action]
|
55
|
+
|
56
|
+
[klass, action]
|
57
|
+
end
|
47
58
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miau
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dittmar Krall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|