super_auth 0.3.0 → 0.3.2
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/CHANGELOG.md +19 -0
- data/Gemfile.lock +45 -37
- data/README.md +15 -0
- data/app/controllers/super_auth/graph_controller.rb +1 -8
- data/lib/generators/super_auth/install/templates/super_auth.rb +3 -1
- data/lib/super_auth/active_record/authorization.rb +17 -0
- data/lib/super_auth/active_record/by_current_user.rb +4 -1
- data/lib/super_auth/version.rb +1 -1
- data/lib/super_auth.rb +14 -0
- metadata +1 -2
- data/super_auth.gemspec +0 -35
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f8b9f0044162ed48bfd00d97ec8c865d426a1b23eba3843c812ddb06d9d074e6
|
|
4
|
+
data.tar.gz: 5359617185bba8cb18f7defa857f388deed32fb458fbdbc02e324a435f91daac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8835d68b13a025b2fcf6a56746716d08b595f1d26b649823110938c9e55496f21f9394b27cb88dfbacce01cdb564844c7423d400881d3ea3b5995b58fa69cfc6
|
|
7
|
+
data.tar.gz: fb79208c943335fb1a6b9fc6de388f413384ab383068f29e118e1e3b4ee386fca9d5285b121356af140686643b30e7a96f348c5caa7c320314fb874f36856961
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.3.2] - 2026-03-10
|
|
4
|
+
|
|
5
|
+
- Feature: Add `SuperAuth.missing_user_behavior` configuration option
|
|
6
|
+
- `:none` (default) — returns empty result set when `current_user` is blank (existing behavior)
|
|
7
|
+
- `:raise` — raises `SuperAuth::Error` when `current_user` is blank (fail-fast for apps that always require authentication)
|
|
8
|
+
|
|
9
|
+
## [0.3.1] - 2026-03-10
|
|
10
|
+
|
|
11
|
+
- Refactor: move authorization compilation logic into Authorization model (`compile!` and `from_graph` class methods)
|
|
12
|
+
|
|
13
|
+
## [0.3.0]
|
|
14
|
+
|
|
15
|
+
- Fix: ByCurrentUser mixin — correct subquery column, add admin wildcard, remove dead code
|
|
16
|
+
- Remove unused tests
|
|
17
|
+
|
|
18
|
+
## [0.2.0]
|
|
19
|
+
|
|
20
|
+
- Version bump with various improvements
|
|
21
|
+
|
|
3
22
|
## [0.1.0] - 2023-12-09
|
|
4
23
|
|
|
5
24
|
- Initial release
|
data/Gemfile.lock
CHANGED
|
@@ -1,80 +1,88 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
super_auth (0.2
|
|
4
|
+
super_auth (0.3.2)
|
|
5
5
|
sequel
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
activemodel (
|
|
11
|
-
activesupport (=
|
|
12
|
-
activerecord (
|
|
13
|
-
activemodel (=
|
|
14
|
-
activesupport (=
|
|
10
|
+
activemodel (8.1.2)
|
|
11
|
+
activesupport (= 8.1.2)
|
|
12
|
+
activerecord (8.1.2)
|
|
13
|
+
activemodel (= 8.1.2)
|
|
14
|
+
activesupport (= 8.1.2)
|
|
15
15
|
timeout (>= 0.4.0)
|
|
16
|
-
activesupport (
|
|
16
|
+
activesupport (8.1.2)
|
|
17
17
|
base64
|
|
18
|
-
benchmark (>= 0.3)
|
|
19
18
|
bigdecimal
|
|
20
19
|
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
21
20
|
connection_pool (>= 2.2.5)
|
|
22
21
|
drb
|
|
23
22
|
i18n (>= 1.6, < 2)
|
|
23
|
+
json
|
|
24
24
|
logger (>= 1.4.2)
|
|
25
25
|
minitest (>= 5.1)
|
|
26
26
|
securerandom (>= 0.3)
|
|
27
27
|
tzinfo (~> 2.0, >= 2.0.5)
|
|
28
|
+
uri (>= 0.13.1)
|
|
28
29
|
after_commit_everywhere (1.6.0)
|
|
29
30
|
activerecord (>= 4.2)
|
|
30
31
|
activesupport
|
|
31
32
|
base64 (0.3.0)
|
|
32
|
-
|
|
33
|
-
bigdecimal (3.2.2)
|
|
33
|
+
bigdecimal (4.0.1)
|
|
34
34
|
coderay (1.1.3)
|
|
35
|
-
concurrent-ruby (1.3.
|
|
36
|
-
connection_pool (
|
|
37
|
-
diff-lcs (1.
|
|
35
|
+
concurrent-ruby (1.3.6)
|
|
36
|
+
connection_pool (3.0.2)
|
|
37
|
+
diff-lcs (1.6.2)
|
|
38
38
|
drb (2.2.3)
|
|
39
|
-
i18n (1.14.
|
|
39
|
+
i18n (1.14.8)
|
|
40
40
|
concurrent-ruby (~> 1.0)
|
|
41
|
+
io-console (0.8.2)
|
|
42
|
+
json (2.19.1)
|
|
41
43
|
logger (1.7.0)
|
|
42
|
-
method_source (1.
|
|
43
|
-
minitest (6.0.
|
|
44
|
+
method_source (1.1.0)
|
|
45
|
+
minitest (6.0.2)
|
|
46
|
+
drb (~> 2.0)
|
|
44
47
|
prism (~> 1.5)
|
|
45
48
|
mysql2 (0.5.7)
|
|
46
49
|
bigdecimal
|
|
47
|
-
pg (1.
|
|
50
|
+
pg (1.6.3-arm64-darwin)
|
|
51
|
+
pg (1.6.3-x86_64-linux)
|
|
48
52
|
prism (1.9.0)
|
|
49
|
-
pry (0.
|
|
53
|
+
pry (0.16.0)
|
|
50
54
|
coderay (~> 1.1)
|
|
51
55
|
method_source (~> 1.0)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
rspec-
|
|
59
|
-
|
|
56
|
+
reline (>= 0.6.0)
|
|
57
|
+
rake (13.3.1)
|
|
58
|
+
reline (0.6.3)
|
|
59
|
+
io-console (~> 0.5)
|
|
60
|
+
rspec (3.13.2)
|
|
61
|
+
rspec-core (~> 3.13.0)
|
|
62
|
+
rspec-expectations (~> 3.13.0)
|
|
63
|
+
rspec-mocks (~> 3.13.0)
|
|
64
|
+
rspec-core (3.13.6)
|
|
65
|
+
rspec-support (~> 3.13.0)
|
|
66
|
+
rspec-expectations (3.13.5)
|
|
60
67
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
61
|
-
rspec-support (~> 3.
|
|
62
|
-
rspec-mocks (3.
|
|
68
|
+
rspec-support (~> 3.13.0)
|
|
69
|
+
rspec-mocks (3.13.8)
|
|
63
70
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
64
|
-
rspec-support (~> 3.
|
|
65
|
-
rspec-support (3.
|
|
71
|
+
rspec-support (~> 3.13.0)
|
|
72
|
+
rspec-support (3.13.7)
|
|
66
73
|
securerandom (0.4.1)
|
|
67
|
-
sequel (5.
|
|
74
|
+
sequel (5.102.0)
|
|
68
75
|
bigdecimal
|
|
69
|
-
sequel-activerecord_connection (2.0.
|
|
70
|
-
activerecord (>= 5.
|
|
76
|
+
sequel-activerecord_connection (2.0.1)
|
|
77
|
+
activerecord (>= 5.1)
|
|
71
78
|
sequel (~> 5.38)
|
|
72
|
-
sqlite3 (2.9.
|
|
73
|
-
sqlite3 (2.9.
|
|
74
|
-
timeout (0.
|
|
79
|
+
sqlite3 (2.9.1-arm64-darwin)
|
|
80
|
+
sqlite3 (2.9.1-x86_64-linux-gnu)
|
|
81
|
+
timeout (0.6.1)
|
|
75
82
|
tzinfo (2.0.6)
|
|
76
83
|
concurrent-ruby (~> 1.0)
|
|
77
|
-
|
|
84
|
+
uri (1.1.1)
|
|
85
|
+
zeitwerk (2.7.5)
|
|
78
86
|
|
|
79
87
|
PLATFORMS
|
|
80
88
|
arm64-darwin-22
|
data/README.md
CHANGED
|
@@ -47,6 +47,21 @@ Then visit: `http://localhost:3000/super_auth/visualization`
|
|
|
47
47
|
|
|
48
48
|
See [VISUALIZATION.md](VISUALIZATION.md) for complete documentation.
|
|
49
49
|
|
|
50
|
+
## Configuration
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
# config/initializers/super_auth.rb
|
|
54
|
+
SuperAuth.setup do |config|
|
|
55
|
+
# Raise an error when a query runs without a current user set.
|
|
56
|
+
# Default is :none (returns empty results silently).
|
|
57
|
+
config.missing_user_behavior = :raise
|
|
58
|
+
end
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
| Option | Values | Default | Description |
|
|
62
|
+
|--------|--------|---------|-------------|
|
|
63
|
+
| `missing_user_behavior` | `:none`, `:raise` | `:none` | Controls what happens when `SuperAuth.current_user` is blank. `:none` returns an empty result set. `:raise` raises `SuperAuth::Error`. |
|
|
64
|
+
|
|
50
65
|
## Usage
|
|
51
66
|
|
|
52
67
|
SuperAuth is a rules engine engine that works on 5 different authorization concepts:
|
|
@@ -182,15 +182,8 @@ module SuperAuth
|
|
|
182
182
|
end
|
|
183
183
|
|
|
184
184
|
def compile_authorizations
|
|
185
|
-
# Compile all authorization paths and populate the authorizations table
|
|
186
185
|
begin
|
|
187
|
-
authorization_class.
|
|
188
|
-
|
|
189
|
-
# Call the authorizations method which compiles all paths
|
|
190
|
-
authorizations = edge_class.authorizations
|
|
191
|
-
authorizations.each(&:save!)
|
|
192
|
-
|
|
193
|
-
count = authorizations.count
|
|
186
|
+
count = authorization_class.compile!
|
|
194
187
|
|
|
195
188
|
render json: {
|
|
196
189
|
success: true,
|
|
@@ -3,5 +3,7 @@
|
|
|
3
3
|
# models on boot. Use this file for any additional configuration.
|
|
4
4
|
#
|
|
5
5
|
# SuperAuth.setup do |config|
|
|
6
|
-
# #
|
|
6
|
+
# # Raise an error when a query runs without a current user set.
|
|
7
|
+
# # Default is :none (returns empty results silently).
|
|
8
|
+
# # config.missing_user_behavior = :raise
|
|
7
9
|
# end
|
|
@@ -1,3 +1,20 @@
|
|
|
1
1
|
class SuperAuth::ActiveRecord::Authorization < ActiveRecord::Base
|
|
2
2
|
self.table_name = 'super_auth_authorizations'
|
|
3
|
+
|
|
4
|
+
class << self
|
|
5
|
+
# Returns all computed authorization paths as Authorization AR objects.
|
|
6
|
+
# These can be saved directly to the super_auth_authorizations table.
|
|
7
|
+
def from_graph
|
|
8
|
+
from("(#{SuperAuth::Edge.authorizations.sql}) as super_auth_authorizations".squish)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Clears and repopulates the authorizations table from the current graph.
|
|
12
|
+
def compile!
|
|
13
|
+
transaction do
|
|
14
|
+
delete_all
|
|
15
|
+
from_graph.each { |auth| create!(auth.attributes.except("id")) }
|
|
16
|
+
end
|
|
17
|
+
count
|
|
18
|
+
end
|
|
19
|
+
end
|
|
3
20
|
end
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
module SuperAuth::ActiveRecord::ByCurrentUser
|
|
2
2
|
def self.included(base)
|
|
3
3
|
base.send(:default_scope, **{all_queries: true}) do
|
|
4
|
-
|
|
4
|
+
if SuperAuth.current_user.blank?
|
|
5
|
+
raise SuperAuth::Error, "SuperAuth.current_user not set" if SuperAuth.missing_user_behavior == :raise
|
|
6
|
+
next none
|
|
7
|
+
end
|
|
5
8
|
|
|
6
9
|
if SuperAuth.current_user.respond_to?(:system?) && SuperAuth.current_user.system?
|
|
7
10
|
self
|
data/lib/super_auth/version.rb
CHANGED
data/lib/super_auth.rb
CHANGED
|
@@ -8,6 +8,20 @@ module SuperAuth
|
|
|
8
8
|
yield self if block_given?
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
+
# Controls behavior when SuperAuth.current_user is blank in ByCurrentUser scope.
|
|
12
|
+
# :none (default) — returns an empty result set silently
|
|
13
|
+
# :raise — raises SuperAuth::Error
|
|
14
|
+
def self.missing_user_behavior
|
|
15
|
+
@missing_user_behavior || :none
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.missing_user_behavior=(behavior)
|
|
19
|
+
unless %i[none raise].include?(behavior)
|
|
20
|
+
raise ArgumentError, "missing_user_behavior must be :none or :raise, got #{behavior.inspect}"
|
|
21
|
+
end
|
|
22
|
+
@missing_user_behavior = behavior
|
|
23
|
+
end
|
|
24
|
+
|
|
11
25
|
def self.load
|
|
12
26
|
require "super_auth/authorization"
|
|
13
27
|
require "super_auth/edge"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: super_auth
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jonathan Frias
|
|
@@ -100,7 +100,6 @@ files:
|
|
|
100
100
|
- lib/super_auth/user.rb
|
|
101
101
|
- lib/super_auth/version.rb
|
|
102
102
|
- lib/tasks/super_auth_tasks.rake
|
|
103
|
-
- super_auth.gemspec
|
|
104
103
|
- visualization.html
|
|
105
104
|
homepage: https://github.com/JonathanFrias/super_auth
|
|
106
105
|
licenses:
|
data/super_auth.gemspec
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
require_relative "lib/super_auth/version"
|
|
2
|
-
|
|
3
|
-
Gem::Specification.new do |spec|
|
|
4
|
-
spec.name = "super_auth"
|
|
5
|
-
spec.version = SuperAuth::VERSION
|
|
6
|
-
spec.authors = ["Jonathan Frias"]
|
|
7
|
-
spec.email = ["jonathan@gofrias.com"]
|
|
8
|
-
|
|
9
|
-
spec.summary = "Make Unauthenticated State Unrepresentable"
|
|
10
|
-
spec.description = "Simple, yet super powerful authorization for you application"
|
|
11
|
-
spec.homepage = "https://github.com/JonathanFrias/super_auth"
|
|
12
|
-
spec.license = "MIT"
|
|
13
|
-
spec.required_ruby_version = ">= 2.6.0"
|
|
14
|
-
|
|
15
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
|
16
|
-
spec.metadata["source_code_uri"] = "https://github.com/JonathanFrias/super_auth"
|
|
17
|
-
spec.metadata["changelog_uri"] = "https://github.com/JonathanFrias/super_auth/blob/main/CHANGELOG.md"
|
|
18
|
-
|
|
19
|
-
# Specify which files should be added to the gem when it is released.
|
|
20
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
21
|
-
spec.files = Dir.chdir(__dir__) do
|
|
22
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
|
23
|
-
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
spec.bindir = "bin"
|
|
27
|
-
spec.executables = spec.files.grep(%r{\Abin/}) { |f| File.basename(f) }
|
|
28
|
-
spec.require_paths = ["lib"]
|
|
29
|
-
|
|
30
|
-
# Uncomment to register a new dependency of your gem
|
|
31
|
-
spec.add_dependency "sequel"
|
|
32
|
-
spec.add_development_dependency "sqlite3"
|
|
33
|
-
# For more information and examples about making a new gem, check out our
|
|
34
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
|
35
|
-
end
|