Skip to content

Commit 71194a2

Browse files
committed
update authz for user password resets
1 parent 7bb5191 commit 71194a2

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

app/models/concerns/password_resettable.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ def generate_password_reset_token
1515
end
1616

1717
def send_password_reset_email(token:)
18+
return if
19+
managed? # managed users aren't allowed to reset password
20+
1821
UserMailer.password_reset(user: self, token: token).deliver_later
1922
end
2023
end

app/models/user.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,11 @@ def free_or_disposable_email?
456456
def single_sign_on_enabled? = !role.user? && account.sso?
457457
alias :sso_enabled? :single_sign_on_enabled?
458458

459-
def password?
460-
password_digest?
461-
end
459+
def password? = password_digest?
460+
def passwordless? = !password?
461+
462+
# NOTE(ezekg) a "managed user" is a passwordless user with the "user" role
463+
def managed? = has_role?(:user) && passwordless? && account.protected?
462464

463465
def active?(t = 90.days.ago)
464466
created_at >= t || any_active_licenses.any?

app/policies/users/password_policy.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ def reset?
1717
verify_permissions!('user.password.reset')
1818
verify_environment!
1919

20-
# User's without a password set cannot reset their password if account is protected
20+
# users without a password set cannot reset their password
2121
deny! if
22-
user.has_role?(:user) && account.protected? && !user.password?
22+
user.managed?
2323

2424
bearer.nil? || user == bearer
2525
end

app/views/user_mailer/password_reset.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-# frozen_string_literal: true
2-
- if @user.user? || @user.password?
2+
- if @user.managed? || @user.password?
33
%p
44
A password reset request was issued for a user profile signed up under this
55
email address for <strong>#{@account.name}</strong>. To reset your password,

0 commit comments

Comments
 (0)