hubbado-policy 1.2.1 → 1.3.0
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 +7 -1
- data/README.md +21 -0
- data/hubbado-policy.gemspec +1 -1
- data/lib/hubbado/policy/base.rb +5 -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: 85715105fb8d91ba36116e0fe32fc87806a48960898d9e5b9802af20bba64e67
|
4
|
+
data.tar.gz: 532065ab325a09f66d6f2dc18e89db1b77f2c2032f45ee424f6dc196dde99c8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff8d518316ca3e959685b16f9b76afc893686ff02d237de6ccc9573e14b2ac2114bc20bb0a69af9bb5af3bb8105732123b3d486ae1da3ba24e6fbb0054adac1a
|
7
|
+
data.tar.gz: 793021cd69698ace3607c10d68cab0811032f2c93e1d2b71c497e5405ebd2f4b6141eabb023b2b2bb34b4eae7155fff0caa1f62912a35dad3267445aab2d515e
|
data/CHANGELOG.md
CHANGED
@@ -2,9 +2,15 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [1.3.0] - 2025-06-03
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Ability to configure the i18n_scope for a non-generic denied reason
|
13
|
+
|
8
14
|
## [1.2.1] - 2025-06-02
|
9
15
|
|
10
16
|
### Fixed
|
data/README.md
CHANGED
@@ -131,6 +131,27 @@ en:
|
|
131
131
|
denied: "Access denied"
|
132
132
|
```
|
133
133
|
|
134
|
+
You can also specify a custom i18n scope when returning denied results:
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
define_policy :edit do
|
138
|
+
# Use a different i18n scope for this specific denial
|
139
|
+
return denied(:not_authorized, i18n_scope: "custom_errors.article")
|
140
|
+
|
141
|
+
permitted
|
142
|
+
end
|
143
|
+
```
|
144
|
+
|
145
|
+
Both the class method and instance method versions of `denied` support the `i18n_scope` parameter:
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
# Class method
|
149
|
+
ArticlePolicy.denied(:custom_reason, i18n_scope: "errors.custom")
|
150
|
+
|
151
|
+
# Instance method
|
152
|
+
policy.denied(:custom_reason, i18n_scope: "errors.custom")
|
153
|
+
```
|
154
|
+
|
134
155
|
### Testing
|
135
156
|
|
136
157
|
Policies can be mimiced using a built-in control
|
data/hubbado-policy.gemspec
CHANGED
data/lib/hubbado/policy/base.rb
CHANGED
@@ -48,13 +48,14 @@ module Hubbado
|
|
48
48
|
# Define this in a subclass if there are dependencies to be configure
|
49
49
|
template_method :configure
|
50
50
|
|
51
|
-
def self.denied(reason = nil, data: nil)
|
51
|
+
def self.denied(reason = nil, data: nil, i18n_scope: nil)
|
52
|
+
i18n_scope ||= self.i18n_scope
|
52
53
|
reason ||= :denied
|
53
54
|
Result.new(false, reason, i18n_scope: i18n_scope, data: data)
|
54
55
|
end
|
55
56
|
|
56
57
|
def self.permitted
|
57
|
-
Result.new(true, :permitted
|
58
|
+
Result.new(true, :permitted)
|
58
59
|
end
|
59
60
|
|
60
61
|
def self.i18n_scope
|
@@ -72,8 +73,8 @@ module Hubbado
|
|
72
73
|
self.class == other.class && user == other.user && record == other.record
|
73
74
|
end
|
74
75
|
|
75
|
-
def denied(reason = nil, data: nil)
|
76
|
-
self.class.denied(reason, data: data)
|
76
|
+
def denied(reason = nil, data: nil, i18n_scope: nil)
|
77
|
+
self.class.denied(reason, data: data, i18n_scope: i18n_scope)
|
77
78
|
end
|
78
79
|
|
79
80
|
def permitted
|