miau 1.1.6 → 1.1.8
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/README.md +1 -0
- data/lib/miau/error.rb +4 -8
- data/lib/miau/run.rb +2 -2
- data/lib/miau/storage.rb.bak +63 -0
- data/lib/miau/version.rb +3 -1
- data/lib/miau/version.rb.bak +17 -0
- data/lib/miau.rb +5 -0
- data/lib/miau.rb.bak +72 -0
- metadata +16 -44
- data/.github/workflows/rake.yml +0 -27
- data/.gitignore +0 -10
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/Appraisals +0 -13
- data/Gemfile +0 -12
- data/Gemfile.lock +0 -279
- data/Rakefile +0 -10
- data/gemfiles/rails_6.1.gemfile +0 -16
- data/gemfiles/rails_7.0.gemfile +0 -16
- data/gemfiles/rails_7.1.gemfile +0 -15
- data/miau.gemspec +0 -27
- data/test/authorization_test.rb +0 -28
- data/test/benchmark_test.rb +0 -34
- data/test/controller_test.rb +0 -58
- data/test/controllers/orders_controller_test.rb +0 -47
- data/test/internal/app/controllers/application_controller.rb +0 -7
- data/test/internal/app/controllers/orders_controller.rb +0 -61
- data/test/internal/app/controllers/posts_controller.rb +0 -10
- data/test/internal/app/models/application_record.rb +0 -3
- data/test/internal/app/models/order.rb +0 -2
- data/test/internal/app/models/post.rb +0 -2
- data/test/internal/app/policies/orders_policy.rb +0 -16
- data/test/internal/app/policies/posts_policy.rb +0 -18
- data/test/internal/app/views/orders/new.html.erb +0 -5
- data/test/internal/config/database.yml +0 -3
- data/test/internal/config/routes.rb +0 -3
- data/test/internal/db/migrate/20141016161801_create_orders.rb +0 -10
- data/test/internal/db/schema.rb +0 -8
- data/test/miau_test.rb +0 -46
- data/test/run_test.rb +0 -69
- data/test/storage_test.rb +0 -51
- data/test/test_helper.rb +0 -17
- /data/{LICENSE → MIT-LICENSE} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d212c3d6cf76c609635ebf42d2e62229077651d0189a2ec54cb82f9a23924f9
|
4
|
+
data.tar.gz: ae723976d8a6ad3d28e5bd625a4d9884d89e2c387c71094590e64b812b3638fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c25989c839d48abc53be4a99c7e77f605cd599b48f22c5ba6eaafd170874f1cd68cd379bfd58af367c2b3f91b5132a0129ee6485c7b8fa5589777dd7b4b2c3c0
|
7
|
+
data.tar.gz: b1af02057e15ae1a36a8c58ce5c95939513bf321f24f8b7863767b9e9da803e0ff53856e0ebddc4bff8ff70261135a1336039ca1efacb510400dc06730b7bb13
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
[](http://badge.fury.io/rb/miau)
|
4
4
|
[](https://rubygems.org/gems/miau)
|
5
|
+
[](http://choosealicense.com/licenses/mit/)
|
5
6
|
|
6
7
|
Miau (MIcro AUthorization) is a simple authorization gem for Rails
|
7
8
|
inspired by Pundit and Banken.
|
data/lib/miau/error.rb
CHANGED
@@ -3,15 +3,11 @@
|
|
3
3
|
module Miau
|
4
4
|
class Error < StandardError; end
|
5
5
|
|
6
|
-
class NotAuthorizedError < Error
|
7
|
-
end
|
6
|
+
class NotAuthorizedError < Error; end
|
8
7
|
|
9
|
-
class NotDefinedError < Error
|
10
|
-
end
|
8
|
+
class NotDefinedError < Error; end
|
11
9
|
|
12
|
-
class AuthorizationNotPerformedError < Error
|
13
|
-
end
|
10
|
+
class AuthorizationNotPerformedError < Error; end
|
14
11
|
|
15
|
-
class OverwriteError < Error
|
16
|
-
end
|
12
|
+
class OverwriteError < Error; end
|
17
13
|
end
|
data/lib/miau/run.rb
CHANGED
@@ -36,12 +36,12 @@ module Miau
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def raise_undef(policy, action)
|
39
|
-
msg = "
|
39
|
+
msg = "policy <#{policy}> action <#{action}>"
|
40
40
|
raise NotDefinedError, msg
|
41
41
|
end
|
42
42
|
|
43
43
|
def raise_authorize(controller, action)
|
44
|
-
msg = "
|
44
|
+
msg = "controller <#{controller}> action <#{action}>"
|
45
45
|
raise NotAuthorizedError, msg
|
46
46
|
end
|
47
47
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "singleton"
|
4
|
+
require "yaml"
|
5
|
+
|
6
|
+
module Miau
|
7
|
+
class PolicyStorage
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
# Example @policies:
|
11
|
+
# {
|
12
|
+
# posts: {
|
13
|
+
# delete: :delete,
|
14
|
+
# remove: :delete
|
15
|
+
# },
|
16
|
+
# application: {
|
17
|
+
# admin: :check
|
18
|
+
# }
|
19
|
+
# }
|
20
|
+
attr_reader :policies
|
21
|
+
attr_reader :instances # e.g. { posts: PostsPolicy.new }
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
reset
|
25
|
+
end
|
26
|
+
|
27
|
+
def reset
|
28
|
+
@policies = {}
|
29
|
+
@instances = {}
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_policy(kls, action, meth)
|
33
|
+
kls = kls.to_sym
|
34
|
+
action = action.to_sym
|
35
|
+
@policies[kls] ||= {}
|
36
|
+
if @policies[kls][action]
|
37
|
+
raise OverwriteError, "Can't overwrite policy(#{kls}, #{action})"
|
38
|
+
end
|
39
|
+
|
40
|
+
if meth.is_a?(Array)
|
41
|
+
meths = [meth].flatten.collect(&:to_sym)
|
42
|
+
@policies[kls][action] = meths
|
43
|
+
else
|
44
|
+
@policies[kls][action] = meth.to_sym
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def find_or_create_policy(klass)
|
49
|
+
res = @instances[klass]
|
50
|
+
return res unless res.nil?
|
51
|
+
|
52
|
+
name = "#{klass.to_s.camelcase}Policy"
|
53
|
+
return nil unless Object.const_defined?(name)
|
54
|
+
|
55
|
+
instances[klass] = name.constantize.new
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_yaml
|
59
|
+
"# === @policies ===\n" + YAML.dump(@policies) +
|
60
|
+
"# === @instances ===\n" + YAML.dump(@instances)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/miau/version.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Miau
|
4
|
-
VERSION = "1.1.
|
4
|
+
VERSION = "1.1.8" # 2024-04-29
|
5
|
+
# VERSION = "1.1.7" # 2024-04-24
|
6
|
+
# VERSION = "1.1.6" # 2024-01-13
|
5
7
|
# VERSION = "1.1.1" # 2024-01-06
|
6
8
|
# VERSION = "1.1.0" # 2024-01-06
|
7
9
|
# VERSION = "1.0.3" # 2023-12-13
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Miau
|
4
|
+
VERSION = "1.1.7" # 2024-04-24
|
5
|
+
# VERSION = "1.1.6" # 2024-01-13
|
6
|
+
# VERSION = "1.1.1" # 2024-01-06
|
7
|
+
# VERSION = "1.1.0" # 2024-01-06
|
8
|
+
# VERSION = "1.0.3" # 2023-12-13
|
9
|
+
# VERSION = "1.0.2" # 2023-11-05
|
10
|
+
# VERSION = "1.0.1" # 2023-04-24
|
11
|
+
# VERSION = "1.0.0" # 2022-01-23
|
12
|
+
# VERSION = "0.1.2" # 2021-12-10
|
13
|
+
# VERSION = "0.1.1" # 2021-11-06
|
14
|
+
# VERSION = "0.1.0" # 2021-09-13
|
15
|
+
# VERSION = "0.0.2" # 2021-09-11
|
16
|
+
# VERSION = "0.0.1"
|
17
|
+
end
|
data/lib/miau.rb
CHANGED
@@ -44,6 +44,11 @@ module Miau
|
|
44
44
|
controller = params[:controller].to_sym
|
45
45
|
action = params[:action].to_sym
|
46
46
|
policy = PolicyStorage.instance.find_or_create_policy(controller)
|
47
|
+
unless policy
|
48
|
+
msg = "missing class #{controller.capitalize}Policy"
|
49
|
+
raise NotDefinedError, msg
|
50
|
+
end
|
51
|
+
|
47
52
|
policy.user = miau_user
|
48
53
|
policy.action = action
|
49
54
|
|
data/lib/miau.rb.bak
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
require "miau/version"
|
5
|
+
require "miau/error"
|
6
|
+
require "miau/storage"
|
7
|
+
require "miau/run"
|
8
|
+
require "miau/application_policy"
|
9
|
+
|
10
|
+
module Miau
|
11
|
+
extend ActiveSupport::Concern
|
12
|
+
|
13
|
+
included do
|
14
|
+
if respond_to?(:helper_method)
|
15
|
+
helper_method :authorized?
|
16
|
+
helper_method :miau_user
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def authorize!(resource = nil, hsh = {})
|
21
|
+
@_miau_authorization_performed = true
|
22
|
+
return true if authorized?(resource, hsh)
|
23
|
+
|
24
|
+
controller = params[:controller].to_sym
|
25
|
+
action = params[:action].to_sym
|
26
|
+
PolicyRun.instance.raise_authorize(controller, action)
|
27
|
+
end
|
28
|
+
|
29
|
+
def authorized?(resource = nil, hsh = {})
|
30
|
+
controller = params[:controller].to_sym
|
31
|
+
action = params[:action].to_sym
|
32
|
+
policy = PolicyStorage.instance.find_or_create_policy(controller)
|
33
|
+
PolicyRun.instance.raise_undef(policy, action) unless policy
|
34
|
+
|
35
|
+
policy.user = miau_user
|
36
|
+
policy.resource = resource
|
37
|
+
methods = PolicyRun.instance.find_methods(policy, controller, action)
|
38
|
+
PolicyRun.instance.raise_undef(policy, action) unless methods
|
39
|
+
|
40
|
+
PolicyRun.instance.runs(policy, methods)
|
41
|
+
end
|
42
|
+
|
43
|
+
def authorize_controller!
|
44
|
+
controller = params[:controller].to_sym
|
45
|
+
action = params[:action].to_sym
|
46
|
+
policy = PolicyStorage.instance.find_or_create_policy(controller)
|
47
|
+
unless policy
|
48
|
+
msg = "missing class #{controller.capitalize}Policy"
|
49
|
+
raise NotDefinedError, msg
|
50
|
+
end
|
51
|
+
|
52
|
+
policy.user = miau_user
|
53
|
+
policy.action = action
|
54
|
+
|
55
|
+
@_miau_authorization_performed = true
|
56
|
+
return true if PolicyRun.instance.runs(policy, :controller)
|
57
|
+
|
58
|
+
PolicyRun.instance.raise_authorize policy, action
|
59
|
+
end
|
60
|
+
|
61
|
+
def miau_user
|
62
|
+
current_user
|
63
|
+
end
|
64
|
+
|
65
|
+
def verify_authorized
|
66
|
+
raise AuthorizationNotPerformedError unless miau_authorization_performed?
|
67
|
+
end
|
68
|
+
|
69
|
+
def miau_authorization_performed?
|
70
|
+
!!@_miau_authorization_performed
|
71
|
+
end
|
72
|
+
end
|
metadata
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miau
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dittmar Krall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: listen
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
|
-
type: :
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: appraisal
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: combustion
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: ricecream
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -86,49 +86,21 @@ description: |
|
|
86
86
|
email: dittmar.krall@matiq.com
|
87
87
|
executables: []
|
88
88
|
extensions: []
|
89
|
-
extra_rdoc_files:
|
89
|
+
extra_rdoc_files:
|
90
|
+
- README.md
|
91
|
+
- MIT-LICENSE
|
90
92
|
files:
|
91
|
-
-
|
92
|
-
- ".gitignore"
|
93
|
-
- ".ruby-gemset"
|
94
|
-
- ".ruby-version"
|
95
|
-
- Appraisals
|
96
|
-
- Gemfile
|
97
|
-
- Gemfile.lock
|
98
|
-
- LICENSE
|
93
|
+
- MIT-LICENSE
|
99
94
|
- README.md
|
100
|
-
- Rakefile
|
101
|
-
- gemfiles/rails_6.1.gemfile
|
102
|
-
- gemfiles/rails_7.0.gemfile
|
103
|
-
- gemfiles/rails_7.1.gemfile
|
104
95
|
- lib/miau.rb
|
96
|
+
- lib/miau.rb.bak
|
105
97
|
- lib/miau/application_policy.rb
|
106
98
|
- lib/miau/error.rb
|
107
99
|
- lib/miau/run.rb
|
108
100
|
- lib/miau/storage.rb
|
101
|
+
- lib/miau/storage.rb.bak
|
109
102
|
- lib/miau/version.rb
|
110
|
-
- miau.
|
111
|
-
- test/authorization_test.rb
|
112
|
-
- test/benchmark_test.rb
|
113
|
-
- test/controller_test.rb
|
114
|
-
- test/controllers/orders_controller_test.rb
|
115
|
-
- test/internal/app/controllers/application_controller.rb
|
116
|
-
- test/internal/app/controllers/orders_controller.rb
|
117
|
-
- test/internal/app/controllers/posts_controller.rb
|
118
|
-
- test/internal/app/models/application_record.rb
|
119
|
-
- test/internal/app/models/order.rb
|
120
|
-
- test/internal/app/models/post.rb
|
121
|
-
- test/internal/app/policies/orders_policy.rb
|
122
|
-
- test/internal/app/policies/posts_policy.rb
|
123
|
-
- test/internal/app/views/orders/new.html.erb
|
124
|
-
- test/internal/config/database.yml
|
125
|
-
- test/internal/config/routes.rb
|
126
|
-
- test/internal/db/migrate/20141016161801_create_orders.rb
|
127
|
-
- test/internal/db/schema.rb
|
128
|
-
- test/miau_test.rb
|
129
|
-
- test/run_test.rb
|
130
|
-
- test/storage_test.rb
|
131
|
-
- test/test_helper.rb
|
103
|
+
- lib/miau/version.rb.bak
|
132
104
|
homepage: https://github.com/matique/miau
|
133
105
|
licenses:
|
134
106
|
- MIT
|
@@ -148,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
120
|
- !ruby/object:Gem::Version
|
149
121
|
version: '0'
|
150
122
|
requirements: []
|
151
|
-
rubygems_version: 3.5.
|
123
|
+
rubygems_version: 3.5.9
|
152
124
|
signing_key:
|
153
125
|
specification_version: 4
|
154
126
|
summary: Simple and lightweight authorization solution for Rails.
|
data/.github/workflows/rake.yml
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# see also https://github.com/whitequark/parser/blob/master/.github/workflows/test.yml
|
2
|
-
name: Rake
|
3
|
-
|
4
|
-
on: [push]
|
5
|
-
|
6
|
-
jobs:
|
7
|
-
test:
|
8
|
-
strategy:
|
9
|
-
fail-fast: false
|
10
|
-
matrix:
|
11
|
-
ruby_version: ["3.0", 3.2, 3.3]
|
12
|
-
gemfile:
|
13
|
-
- Gemfile
|
14
|
-
- gemfiles/Gemfile.rails-7.1
|
15
|
-
- gemfiles/Gemfile.rails-7.0
|
16
|
-
- gemfiles/Gemfile.rails-6.1
|
17
|
-
runs-on: ubuntu-latest
|
18
|
-
|
19
|
-
steps:
|
20
|
-
- uses: actions/checkout@v3
|
21
|
-
- name: Set up Ruby
|
22
|
-
uses: ruby/setup-ruby@v1
|
23
|
-
with:
|
24
|
-
ruby-version: ${{ matrix.ruby_version }}
|
25
|
-
bundler-cache: true
|
26
|
-
- name: Build and test with Rake
|
27
|
-
run: bundle exec rake
|
data/.gitignore
DELETED
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rails-7.1
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby-3.3.0
|
data/Appraisals
DELETED