miau 1.1.8 → 1.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d212c3d6cf76c609635ebf42d2e62229077651d0189a2ec54cb82f9a23924f9
4
- data.tar.gz: ae723976d8a6ad3d28e5bd625a4d9884d89e2c387c71094590e64b812b3638fb
3
+ metadata.gz: e8cc7ff577168357fb277d134fa4ef13b2a4474596490cf8c985b67ec4cd0f3c
4
+ data.tar.gz: ac8986cf724bf7d6c294a4743016a0b1a4e85b04f42603c075b56279c596fc0a
5
5
  SHA512:
6
- metadata.gz: c25989c839d48abc53be4a99c7e77f605cd599b48f22c5ba6eaafd170874f1cd68cd379bfd58af367c2b3f91b5132a0129ee6485c7b8fa5589777dd7b4b2c3c0
7
- data.tar.gz: b1af02057e15ae1a36a8c58ce5c95939513bf321f24f8b7863767b9e9da803e0ff53856e0ebddc4bff8ff70261135a1336039ca1efacb510400dc06730b7bb13
6
+ metadata.gz: 2a4c85dd96321208a6e82514324167548023b682ee3223f46fa846e131f93566b8539ad25ba8a2bc76cf4bde7e178b6114fb87535c0d81cc85912193b5e63489
7
+ data.tar.gz: d0b727e3a439e34b20208c3e070e4d63958da4c5a03d7e018cf69a1847e5ee32df7dc32564ca016272fd0db691ada524c09f1fab5607e7e6c18912a62db5c195
data/MIT-LICENSE CHANGED
@@ -1,5 +1,3 @@
1
- The MIT License (MIT)
2
-
3
1
  Copyright (c) 2021-2024 Dittmar Krall (www.matiq.com)
4
2
 
5
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # Miau
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/miau.png)](http://badge.fury.io/rb/miau)
3
+ [![Gem Version](https://badge.fury.io/rb/miau.svg)](http://badge.fury.io/rb/miau)
4
4
  [![GEM Downloads](https://img.shields.io/gem/dt/miau?color=168AFE&logo=ruby&logoColor=FE1616)](https://rubygems.org/gems/miau)
5
+ [![rake](https://github.com/matique/miau/actions/workflows/rake.yml/badge.svg)](https://github.com/matique/miau/actions/workflows/rake.yml)
6
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/standardrb/standard)
5
7
  [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](http://choosealicense.com/licenses/mit/)
6
8
 
7
9
  Miau (MIcro AUthorization) is a simple authorization gem for Rails
data/lib/miau/version.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Miau
4
- VERSION = "1.1.8" # 2024-04-29
4
+ VERSION = "1.1.10" # 2024-10-20
5
+ # VERSION = "1.1.8" # 2024-04-29
5
6
  # VERSION = "1.1.7" # 2024-04-24
6
7
  # VERSION = "1.1.6" # 2024-01-13
7
8
  # VERSION = "1.1.1" # 2024-01-06
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Miau
4
- VERSION = "1.1.7" # 2024-04-24
4
+ VERSION = "1.1.9" # 2024-10-20
5
+ # VERSION = "1.1.8" # 2024-04-29
6
+ # VERSION = "1.1.7" # 2024-04-24
5
7
  # VERSION = "1.1.6" # 2024-01-13
6
8
  # VERSION = "1.1.1" # 2024-01-06
7
9
  # VERSION = "1.1.0" # 2024-01-06
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.1.8
4
+ version: 1.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dittmar Krall
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-29 00:00:00.000000000 Z
11
+ date: 2024-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: listen
@@ -93,19 +93,17 @@ files:
93
93
  - MIT-LICENSE
94
94
  - README.md
95
95
  - lib/miau.rb
96
- - lib/miau.rb.bak
97
96
  - lib/miau/application_policy.rb
98
97
  - lib/miau/error.rb
99
98
  - lib/miau/run.rb
100
99
  - lib/miau/storage.rb
101
- - lib/miau/storage.rb.bak
102
100
  - lib/miau/version.rb
103
101
  - lib/miau/version.rb.bak
104
102
  homepage: https://github.com/matique/miau
105
103
  licenses:
106
104
  - MIT
107
105
  metadata: {}
108
- post_install_message:
106
+ post_install_message:
109
107
  rdoc_options: []
110
108
  require_paths:
111
109
  - lib
@@ -120,8 +118,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
118
  - !ruby/object:Gem::Version
121
119
  version: '0'
122
120
  requirements: []
123
- rubygems_version: 3.5.9
124
- signing_key:
121
+ rubygems_version: 3.5.20
122
+ signing_key:
125
123
  specification_version: 4
126
124
  summary: Simple and lightweight authorization solution for Rails.
127
125
  test_files: []
@@ -1,63 +0,0 @@
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.rb.bak DELETED
@@ -1,72 +0,0 @@
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