super_auth 0.3.1 → 0.3.3
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 +10 -0
- data/Gemfile.lock +1 -1
- data/README.md +15 -0
- data/lib/generators/super_auth/install/templates/super_auth.rb +3 -1
- 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 +20 -4
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1a2db33b2e48f7e542d54f3b5cef127f51c09fe19896b4ec6644a65ffa424c91
|
|
4
|
+
data.tar.gz: 87a7b993edea7bab1ca6c3298805f17e62ce0cd8b67de9114167cdb868316d7d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 62f14629c43e5dae082d3884803dae6559a91c58118479fc1fc6e4496dec27036c35cf8011e859b16f0e5a30d9c977244d2c39d005936a015796ddd1845b87ee
|
|
7
|
+
data.tar.gz: ee2cfaa0d1d3d4b8e3ba56130bc47cdbcb491982fac339bcde956a555b267dc8b39c82da284427f4b7e0baeb6382a5532766135d96922ecd1170079a0333c2f5
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.3.3] - 2026-04-29
|
|
4
|
+
|
|
5
|
+
- Fix: detect PostgreSQL/SQLite/Mysql2 adapter subclasses (e.g. PostGIS, Makara) when bootstrapping the Sequel connection from ActiveRecord. Previously only the exact stock adapter classes were recognized, leaving `SuperAuth.db` unset for apps using a subclassed adapter.
|
|
6
|
+
|
|
7
|
+
## [0.3.2] - 2026-03-10
|
|
8
|
+
|
|
9
|
+
- Feature: Add `SuperAuth.missing_user_behavior` configuration option
|
|
10
|
+
- `:none` (default) — returns empty result set when `current_user` is blank (existing behavior)
|
|
11
|
+
- `:raise` — raises `SuperAuth::Error` when `current_user` is blank (fail-fast for apps that always require authentication)
|
|
12
|
+
|
|
3
13
|
## [0.3.1] - 2026-03-10
|
|
4
14
|
|
|
5
15
|
- Refactor: move authorization compilation logic into Authorization model (`compile!` and `from_graph` class methods)
|
data/Gemfile.lock
CHANGED
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:
|
|
@@ -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,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"
|
|
@@ -72,12 +86,14 @@ module SuperAuth
|
|
|
72
86
|
::ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
|
|
73
87
|
end
|
|
74
88
|
|
|
75
|
-
|
|
76
|
-
|
|
89
|
+
# Walk the ancestor chain so adapter subclasses (e.g. PostGIS, Makara)
|
|
90
|
+
# are recognized as their parent adapter type.
|
|
91
|
+
adapter_ancestors = ::ActiveRecord::Base.adapter_class.ancestors.map(&:to_s)
|
|
92
|
+
if adapter_ancestors.include?("ActiveRecord::ConnectionAdapters::SQLite3Adapter")
|
|
77
93
|
SuperAuth.db = Sequel.sqlite(**extensions)
|
|
78
|
-
|
|
94
|
+
elsif adapter_ancestors.include?("ActiveRecord::ConnectionAdapters::PostgreSQLAdapter")
|
|
79
95
|
SuperAuth.db = Sequel.postgres(**extensions)
|
|
80
|
-
|
|
96
|
+
elsif adapter_ancestors.include?("ActiveRecord::ConnectionAdapters::Mysql2Adapter")
|
|
81
97
|
SuperAuth.db = Sequel.mysql2(**extensions)
|
|
82
98
|
else
|
|
83
99
|
warn "[SuperAuth] WARNING: Unknown adapter: #{::ActiveRecord::Base.adapter_class}"
|