miau 1.0.2 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +15 -14
- data/.ruby-gemset +1 -1
- data/.ruby-version +1 -1
- data/Appraisals +13 -0
- data/Gemfile.lock +31 -25
- data/LICENSE +1 -1
- data/README.md +30 -14
- data/gemfiles/rails_6.1.gemfile +15 -0
- data/gemfiles/rails_6.1.gemfile.lock +223 -0
- data/gemfiles/rails_7.0.gemfile +15 -0
- data/gemfiles/rails_7.0.gemfile.lock +255 -0
- data/gemfiles/rails_7.1.gemfile +14 -0
- data/gemfiles/rails_7.1.gemfile.lock +253 -0
- data/lib/miau/application_policy.rb +2 -1
- data/lib/miau/error.rb +3 -0
- data/lib/miau/run.rb +47 -0
- data/lib/miau/storage.rb +17 -53
- data/lib/miau/version.rb +4 -1
- data/lib/miau.rb +15 -14
- data/miau.gemspec +2 -2
- metadata +27 -6
data/lib/miau.rb
CHANGED
@@ -4,6 +4,7 @@ require "active_support/concern"
|
|
4
4
|
require "miau/version"
|
5
5
|
require "miau/error"
|
6
6
|
require "miau/storage"
|
7
|
+
require "miau/run"
|
7
8
|
require "miau/application_policy"
|
8
9
|
|
9
10
|
module Miau
|
@@ -20,24 +21,20 @@ module Miau
|
|
20
21
|
@_miau_authorization_performed = true
|
21
22
|
return true if authorized?(resource, hsh)
|
22
23
|
|
23
|
-
klass, action = klass_action
|
24
|
+
klass, action = klass_action
|
24
25
|
msg = "class <#{klass} action <#{action}>"
|
25
|
-
raise
|
26
|
+
raise NotAuthorizedError, msg
|
26
27
|
end
|
27
28
|
|
28
29
|
def authorized?(resource = nil, hsh = {})
|
29
|
-
klass, action = klass_action
|
30
|
-
|
30
|
+
klass, action = klass_action
|
31
|
+
PolicyRun.instance.run(klass, action, miau_user, resource)
|
31
32
|
end
|
32
33
|
|
33
34
|
def miau_user
|
34
35
|
current_user
|
35
36
|
end
|
36
37
|
|
37
|
-
def skip_authorization
|
38
|
-
@_miau_authorization_performed = true
|
39
|
-
end
|
40
|
-
|
41
38
|
def verify_authorized
|
42
39
|
raise AuthorizationNotPerformedError unless miau_authorization_performed?
|
43
40
|
end
|
@@ -46,13 +43,17 @@ module Miau
|
|
46
43
|
!!@_miau_authorization_performed
|
47
44
|
end
|
48
45
|
|
46
|
+
def authorize_controller!
|
47
|
+
name = params[:controller].to_sym
|
48
|
+
policy = PolicyStorage.instance.find_or_create_policy(name)
|
49
|
+
raise NotDefinedError unless policy&.respond_to?(:controller)
|
50
|
+
|
51
|
+
policy.send(:controller)
|
52
|
+
end
|
53
|
+
|
49
54
|
private
|
50
55
|
|
51
|
-
def klass_action
|
52
|
-
|
53
|
-
klass ||= params[:controller]
|
54
|
-
action = hsh[:action]
|
55
|
-
action ||= params[:action]
|
56
|
-
[klass.to_sym, action.to_sym]
|
56
|
+
def klass_action
|
57
|
+
[params[:controller].to_sym, params[:action].to_sym]
|
57
58
|
end
|
58
59
|
end
|
data/miau.gemspec
CHANGED
@@ -12,7 +12,6 @@ Gem::Specification.new do |s|
|
|
12
12
|
resources a given user is allowed to access.
|
13
13
|
EOS
|
14
14
|
|
15
|
-
s.metadata["source_code_uri"] = "https://github.com/matique/miau"
|
16
15
|
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
17
16
|
s.require_paths = ["lib"]
|
18
17
|
|
@@ -23,7 +22,8 @@ Gem::Specification.new do |s|
|
|
23
22
|
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|features)/}) }
|
24
23
|
|
25
24
|
s.add_runtime_dependency "activesupport"
|
26
|
-
s.add_development_dependency "rake"
|
27
25
|
|
26
|
+
s.add_development_dependency "appraisal"
|
27
|
+
s.add_development_dependency "minitest"
|
28
28
|
s.add_development_dependency "ricecream"
|
29
29
|
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: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dittmar Krall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -25,7 +25,21 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: appraisal
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
@@ -64,22 +78,29 @@ files:
|
|
64
78
|
- ".gitignore"
|
65
79
|
- ".ruby-gemset"
|
66
80
|
- ".ruby-version"
|
81
|
+
- Appraisals
|
67
82
|
- Gemfile
|
68
83
|
- Gemfile.lock
|
69
84
|
- LICENSE
|
70
85
|
- README.md
|
71
86
|
- Rakefile
|
87
|
+
- gemfiles/rails_6.1.gemfile
|
88
|
+
- gemfiles/rails_6.1.gemfile.lock
|
89
|
+
- gemfiles/rails_7.0.gemfile
|
90
|
+
- gemfiles/rails_7.0.gemfile.lock
|
91
|
+
- gemfiles/rails_7.1.gemfile
|
92
|
+
- gemfiles/rails_7.1.gemfile.lock
|
72
93
|
- lib/miau.rb
|
73
94
|
- lib/miau/application_policy.rb
|
74
95
|
- lib/miau/error.rb
|
96
|
+
- lib/miau/run.rb
|
75
97
|
- lib/miau/storage.rb
|
76
98
|
- lib/miau/version.rb
|
77
99
|
- miau.gemspec
|
78
100
|
homepage: https://github.com/matique/miau
|
79
101
|
licenses:
|
80
102
|
- MIT
|
81
|
-
metadata:
|
82
|
-
source_code_uri: https://github.com/matique/miau
|
103
|
+
metadata: {}
|
83
104
|
post_install_message:
|
84
105
|
rdoc_options: []
|
85
106
|
require_paths:
|
@@ -95,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
116
|
- !ruby/object:Gem::Version
|
96
117
|
version: '0'
|
97
118
|
requirements: []
|
98
|
-
rubygems_version: 3.
|
119
|
+
rubygems_version: 3.5.3
|
99
120
|
signing_key:
|
100
121
|
specification_version: 4
|
101
122
|
summary: Simple and lightweight authorization solution for Rails.
|