Skip to content

Commit

Permalink
feat(user): block login when .. blocked
Browse files Browse the repository at this point in the history
  • Loading branch information
LeSim committed Jul 18, 2023
1 parent c130f80 commit 60f1c12
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def merge(old_user)
old_user.targeted_user_links.update_all(user_id: id)

# Move or merge old user's roles to the user
[
[
[old_user.instructeur, instructeur],
[old_user.expert, expert],
[old_user.administrateur, administrateur]
Expand Down Expand Up @@ -267,6 +267,10 @@ def send_devise_notification(notification, *args)
devise_mailer.send(notification, self, *args).deliver_later
end

def active_for_authentication?
super && blocked_at.nil?
end

private

def does_not_merge_on_self
Expand Down
13 changes: 13 additions & 0 deletions spec/system/users/sign_up_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,17 @@
expect(page).to have_current_path new_user_session_path
end
end

context 'when the user already has a confirmed account but is blocked' do
before do
create(:user, email: user_email, password: user_password, blocked_at: Time.current)
end

scenario 'they cannot signed in' do
visit new_user_session_path
sign_in_with user_email, user_password

expect(page).to have_current_path new_user_session_path
end
end
end

0 comments on commit 60f1c12

Please sign in to comment.