rodauth-model 0.3.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91293093585a6bb8cc89572b0a646e7c467791760d1bb3d042447a88865bdfbe
4
- data.tar.gz: 4660747afb36a135a67d7d3da9018ec4e9d98e9d900e5677713c6cbca76cc36c
3
+ metadata.gz: 239885866a591579de9572aeef88130ee45bebcdd2950b590471d9b2e2de14ad
4
+ data.tar.gz: 4b507ce9b6fe74cda28363956504f60781e0ed2177c0f30aac287f6a4b65fdac
5
5
  SHA512:
6
- metadata.gz: 78e60ba11059f42980909f23b3862bc25d1ac921f34e4124430034d4c61a7d69f79524f1d73447c3310a691819f426a52f51427a398792663b78a70833754979
7
- data.tar.gz: 257afaa7f30a76cdfe633586a70c9dafba41c9653e9b346ba9a839ecaa86f4846854ffa332217bfbee1c859839748e79dc8b1755cbb0ee986be0c0815897c7e7
6
+ metadata.gz: d0ef6938063f04122115959b51d833c8f84441526e721493a5af518c7758dcabcf4022b7a0701e6dc69ba098b4519fd35126952b15b56ac3465d0e18ad31f9fa
7
+ data.tar.gz: bbf525d94b4533f11485428f258fd3963e79b896a2dfeebc9240565ae25e5e12d5c5eeb86fa6e96ad05d4075cb2a8f03b3c289246d1c4569d5f3e11ea7aafabe
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 0.5.0 (2026-06-29)
2
+
3
+ * Don't define the password hash association when no password feature is enabled, which previously failed on `Account#destroy` for setups such as OmniAuth-only authentication (@janko)
4
+
5
+ ## 0.4.0 (2024-12-16)
6
+
7
+ * Add `password?` model method that returns whether a password is set (@janko)
8
+
9
+ * Drop support for Ruby 2.3 and 2.4 (@janko)
10
+
1
11
  ## 0.3.0 (2024-10-12)
2
12
 
3
13
  * Add support for OTP Unlock feature (@janko)
data/README.md CHANGED
@@ -41,8 +41,12 @@ account.password_hash #=> "$2a$12$k/Ub1I2iomi84RacqY89Hu4.M0vK7klRnRtzorDyvOkVI.
41
41
  account.password_hash #=> #<Account::PasswordHash...> (record from `account_password_hashes` table)
42
42
  account.password_hash.password_hash #=> "$2a$12$k/Ub1..." (inaccessible when using database authentication functions)
43
43
 
44
+ # whether a password is set
45
+ account.password? #=> true
46
+
44
47
  account.password = nil # clears password hash
45
48
  account.password_hash #=> nil
49
+ account.password? #=> false
46
50
  ```
47
51
 
48
52
  Note that the password attribute doesn't come with validations, making it unsuitable for forms. It was primarily intended to allow easily creating accounts in development console and in tests.
@@ -112,6 +116,7 @@ Below is a list of all associations defined depending on the features loaded:
112
116
  | lockout | `:lockout` | `has_one` | `Lockout` | `account_lockouts` |
113
117
  | lockout | `:login_failure` | `has_one` | `LoginFailure` | `account_login_failures` |
114
118
  | otp | `:otp_key` | `has_one` | `OtpKey` | `account_otp_keys` |
119
+ | otp_unlock | `:otp_unlock` | `has_one` | `OtpUnlock` | `account_otp_unlocks` |
115
120
  | password_expiration | `:password_change_time` | `has_one` | `PasswordChangeTime` | `account_password_change_times` |
116
121
  | recovery_codes | `:recovery_codes` | `has_many` | `RecoveryCode` | `account_recovery_codes` |
117
122
  | remember | `:remember_key` | `has_one` | `RememberKey` | `account_remember_keys` |
@@ -123,7 +128,8 @@ Below is a list of all associations defined depending on the features loaded:
123
128
  | webauthn | `:webauthn_keys` | `has_many` | `WebauthnKey` | `account_webauthn_keys` |
124
129
  | webauthn | `:webauthn_user_id` | `has_one` | `WebauthnUserId` | `account_webauthn_user_ids` |
125
130
 
126
- Note that some Rodauth tables use composite primary keys, which Active Record doesn't support out of the box. For associations to work properly in Active Record, you might need to add the [composite_primary_keys] gem to your Gemfile. On Sequel, associations will work without any changes, because Sequel supports composite primary keys.
131
+ > [!NOTE]
132
+ > Some Rodauth tables use composite primary keys, which are supported in Active Record 7.1+. If you're on an older version of Active Record, you might need to add the [composite_primary_keys] gem to your Gemfile. Sequel has always natively supported composite primary keys.
127
133
 
128
134
  ## Extending associations
129
135
 
@@ -146,7 +152,7 @@ if defined?(Rodauth::Model)
146
152
  end
147
153
  ```
148
154
 
149
- The `Rodauth::Model.register_association` method receives the feature name and a block, which is evaluted in the context of a Rodauth instance and should return the association definition with the following items:
155
+ The `Rodauth::Model.register_association` method receives the feature name and a block, which is evaluated in the context of a Rodauth instance and should return the association definition with the following items:
150
156
 
151
157
  * `:name` – association name
152
158
  * `:type` – relationship type (`:one` for one-to-one, `:many` for one-to-many)
@@ -32,10 +32,18 @@ module Rodauth
32
32
  end
33
33
  end
34
34
  end
35
+
36
+ define_method(:password?) do
37
+ if rodauth.account_password_hash_column
38
+ !!public_send(rodauth.account_password_hash_column)
39
+ else
40
+ !!password_hash
41
+ end
42
+ end
35
43
  end
36
44
 
37
45
  def define_associations(model)
38
- define_password_hash_association(model) unless rodauth.account_password_hash_column
46
+ define_password_hash_association(model) if password_hash_association?
39
47
 
40
48
  feature_associations.each do |association|
41
49
  association[:type] = ASSOCIATION_TYPES.fetch(association[:type])
@@ -14,7 +14,7 @@ module Rodauth
14
14
  def define_methods(model)
15
15
  rodauth = @auth_class.allocate.freeze
16
16
 
17
- unless rodauth.account_password_hash_column
17
+ if password_hash_association?
18
18
  model.plugin :nested_attributes
19
19
  model.nested_attributes :password_hash, destroy: true
20
20
  end
@@ -42,12 +42,20 @@ module Rodauth
42
42
  self.password_hash_attributes = attributes
43
43
  end
44
44
  end
45
+
46
+ define_method(:password?) do
47
+ if rodauth.account_password_hash_column
48
+ !!public_send(rodauth.account_password_hash_column)
49
+ else
50
+ !!password_hash
51
+ end
52
+ end
45
53
  end
46
54
 
47
55
  def define_associations(model)
48
56
  model.plugin :association_dependencies
49
57
 
50
- define_password_hash_association(model) unless rodauth.account_password_hash_column
58
+ define_password_hash_association(model) if password_hash_association?
51
59
 
52
60
  feature_associations.each do |association|
53
61
  association[:type] = ASSOCIATION_TYPES.fetch(association[:type])
data/lib/rodauth/model.rb CHANGED
@@ -52,6 +52,15 @@ module Rodauth
52
52
  .map { |block| rodauth.instance_exec(&block) }
53
53
  end
54
54
 
55
+ # The password hash is stored in a separate table only when Rodauth is
56
+ # configured to manage passwords (i.e. when a password-handling feature is
57
+ # enabled). Without this check we'd define an association against a table
58
+ # that doesn't exist, which would fail on Account#destroy.
59
+ def password_hash_association?
60
+ !rodauth.account_password_hash_column &&
61
+ rodauth.features.include?(:login_password_requirements_base)
62
+ end
63
+
55
64
  def rodauth
56
65
  @auth_class.allocate
57
66
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "rodauth-model"
5
- spec.version = "0.3.0"
5
+ spec.version = "0.5.0"
6
6
  spec.authors = ["Janko Marohnić"]
7
7
  spec.email = ["janko@hey.com"]
8
8
 
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.summary = spec.description
11
11
  spec.homepage = "https://github.com/janko/rodauth-model"
12
12
  spec.license = "MIT"
13
- spec.required_ruby_version = ">= 2.3"
13
+ spec.required_ruby_version = ">= 2.5"
14
14
 
15
15
  spec.metadata["source_code_uri"] = "https://github.com/janko/rodauth-model"
16
16
 
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "minitest"
23
23
  spec.add_development_dependency "minitest-hooks"
24
24
  spec.add_development_dependency "bcrypt"
25
- spec.add_development_dependency "jwt"
25
+ spec.add_development_dependency "jwt", "< 2.10"
26
26
  spec.add_development_dependency "rotp"
27
27
  spec.add_development_dependency "rqrcode"
28
28
  spec.add_development_dependency "webauthn" unless RUBY_ENGINE == "jruby"
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodauth-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-10-12 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rodauth
@@ -70,16 +69,16 @@ dependencies:
70
69
  name: jwt
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
- - - ">="
72
+ - - "<"
74
73
  - !ruby/object:Gem::Version
75
- version: '0'
74
+ version: '2.10'
76
75
  type: :development
77
76
  prerelease: false
78
77
  version_requirements: !ruby/object:Gem::Requirement
79
78
  requirements:
80
- - - ">="
79
+ - - "<"
81
80
  - !ruby/object:Gem::Version
82
- version: '0'
81
+ version: '2.10'
83
82
  - !ruby/object:Gem::Dependency
84
83
  name: rotp
85
84
  requirement: !ruby/object:Gem::Requirement
@@ -144,7 +143,6 @@ licenses:
144
143
  - MIT
145
144
  metadata:
146
145
  source_code_uri: https://github.com/janko/rodauth-model
147
- post_install_message:
148
146
  rdoc_options: []
149
147
  require_paths:
150
148
  - lib
@@ -152,15 +150,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
150
  requirements:
153
151
  - - ">="
154
152
  - !ruby/object:Gem::Version
155
- version: '2.3'
153
+ version: '2.5'
156
154
  required_rubygems_version: !ruby/object:Gem::Requirement
157
155
  requirements:
158
156
  - - ">="
159
157
  - !ruby/object:Gem::Version
160
158
  version: '0'
161
159
  requirements: []
162
- rubygems_version: 3.5.11
163
- signing_key:
160
+ rubygems_version: 4.0.13
164
161
  specification_version: 4
165
162
  summary: Provides model mixin for Active Record and Sequel that defines password attribute
166
163
  and associations based on Rodauth configuration.