Skip to content

Commit 67978a7

Browse files
committed
Rename primary email to verified
1 parent 6e4db1f commit 67978a7

7 files changed

Lines changed: 40 additions & 40 deletions

File tree

dpc-portal/app/controllers/login_dot_gov_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ def update_email(csp_user, new_emails, verified_email)
8787
add_or_activate_new_email(csp_user, new_emails, existing_emails)
8888
deactivate_old_email(new_emails, existing_emails)
8989

90-
# Set their primary email, which should now exist in the user_emails table
90+
# Set their verified email, which should now exist in the user_emails table
9191
verified_email = csp_user.user_emails.find_by(email: verified_email)
92-
verified_email.update(primary: true) if verified_email && !verified_email.primary?
92+
verified_email.update(verified: true) if verified_email && !verified_email.verified?
9393
end
9494
end
9595

dpc-portal/app/models/user_email.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ class UserEmail < ApplicationRecord
55
belongs_to :csp_user
66
has_one :user, through: :csp_users
77

8-
# If we update this email to primary, make sure the others aren't.
9-
before_save :ensure_only_one_primary, if: -> { primary? && primary_changed? }
8+
# If we update this email to verified, make sure the others aren't.
9+
before_save :ensure_only_one_verified, if: -> { verified? && verified_changed? }
1010

1111
private
1212

13-
# Sets all of the user's other emails to not primary.
14-
def ensure_only_one_primary
13+
# Sets all of the user's other emails to not verified.
14+
def ensure_only_one_verified
1515
UserEmail.where(csp_user_id: csp_user_id)
16-
.where(primary: true)
16+
.where(verified: true)
1717
.where.not(id: id)
18-
.update_all(primary: false)
18+
.update_all(verified: false)
1919
end
2020
end

dpc-portal/db/migrate/20260527181236_add_primary_to_user_emails.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class AddVerifiedToUserEmails < ActiveRecord::Migration[8.0]
2+
def change
3+
add_column :user_emails, :verified, :boolean, default: false, null: false
4+
5+
# Make sure each csp_user can only have one verified email.
6+
add_index :user_emails, :csp_user_id,
7+
unique: true,
8+
where: '"verified" = true',
9+
name: 'index_unique_verified_email_per_csp_user'
10+
end
11+
end

dpc-portal/db/schema.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@
252252
t.datetime "reactivated_at"
253253
t.datetime "created_at", null: false
254254
t.datetime "updated_at", null: false
255-
t.boolean "primary", default: false, null: false
255+
t.boolean "verified", default: false, null: false
256256
t.index ["csp_user_id", "email"], name: "index_user_emails_on_csp_user_id_and_email", unique: true
257-
t.index ["csp_user_id"], name: "index_unique_primary_email_per_csp_user", unique: true, where: "(\"primary\" = true)"
257+
t.index ["csp_user_id"], name: "index_unique_verified_email_per_csp_user", unique: true, where: "(verified = true)"
258258
t.index ["csp_user_id"], name: "index_user_emails_on_csp_user_id"
259259
end
260260

dpc-portal/spec/models/user_email_spec.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@
1111
expect(user_email.csp_user).to eq csp_user
1212
end
1313

14-
it 'ensures that creating a new primary email unsets others' do
14+
it 'ensures that creating a new verified email unsets others' do
1515
user = create(:user)
1616
csp = create(:csp)
1717
csp_user = create(:csp_user, user:, csp:)
1818

19-
email_old_primary = create(:user_email, csp_user:, primary: true, email: 'old@email.com')
20-
email_new_primary = create(:user_email, csp_user:, primary: true, email: 'new@email.com')
19+
email_old_verified = create(:user_email, csp_user:, verified: true, email: 'old@email.com')
20+
email_new_verified = create(:user_email, csp_user:, verified: true, email: 'new@email.com')
2121

22-
expect(email_old_primary.reload.primary).to eq false
23-
expect(email_new_primary.reload.primary).to eq true
22+
expect(email_old_verified.reload.verified).to eq false
23+
expect(email_new_verified.reload.verified).to eq true
2424
end
2525

26-
it 'ensures that setting an email to primary unsets others' do
26+
it 'ensures that setting an email to verified unsets others' do
2727
user = create(:user)
2828
csp = create(:csp)
2929
csp_user = create(:csp_user, user:, csp:)
3030

31-
email_old_primary = create(:user_email, csp_user:, primary: true, email: 'old@email.com')
32-
email_new_primary = create(:user_email, csp_user:, primary: false, email: 'new@email.com')
33-
expect(email_old_primary.primary).to eq true
34-
expect(email_new_primary.primary).to eq false
31+
email_old_verified = create(:user_email, csp_user:, verified: true, email: 'old@email.com')
32+
email_new_verified = create(:user_email, csp_user:, verified: false, email: 'new@email.com')
33+
expect(email_old_verified.verified).to eq true
34+
expect(email_new_verified.verified).to eq false
3535

36-
# Should set email1 to not primary
37-
email_new_primary.update!(primary: true)
38-
email_old_primary.reload
39-
email_new_primary.reload
36+
# Should set email1 to not verified
37+
email_new_verified.update!(verified: true)
38+
email_old_verified.reload
39+
email_new_verified.reload
4040

41-
expect(email_old_primary.primary).to eq false
42-
expect(email_new_primary.primary).to eq true
41+
expect(email_old_verified.verified).to eq false
42+
expect(email_new_verified.verified).to eq true
4343
end
4444
end

dpc-portal/spec/requests/login_dot_gov_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@
204204
emails = UserEmail.last(2).pluck(:email)
205205
expect(emails).to match_array(%w[email1@example.com email2@example.com])
206206
expect(UserEmail.pluck(:active)).to all(be true)
207-
expect(UserEmail.find(&:primary?).email).to eq 'email1@example.com'
208-
expect(UserEmail.count(&:primary?)).to eq 1
207+
expect(UserEmail.find(&:verified?).email).to eq 'email1@example.com'
208+
expect(UserEmail.count(&:verified?)).to eq 1
209209
end
210210
end
211211

@@ -267,7 +267,7 @@
267267
expect(email.active).to eq true
268268
expect(email.deactivated_at).to be_nil
269269
expect(email.reactivated_at).to_not be_nil
270-
expect(email.primary).to eq true
270+
expect(email.verified).to eq true
271271
end
272272
end
273273
end

0 commit comments

Comments
 (0)