Skip to content

Commit 6be8a49

Browse files
committed
Record time that user responds to user research request, and defaults all users to "to_be_asked"
- Adds a db migration and updated schema/seeds to default all users to "to_be_asked" - Adds timestamp to record what time the user opted into user research - sorts the users in the report that have consented by time of opting in to make it easier to keep track of users - updates the tests to reflect the new changes
1 parent c6e61f2 commit 6be8a49

12 files changed

Lines changed: 59 additions & 21 deletions

File tree

app/input_objects/account/contact_for_research_input.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def submit
99
return false if invalid?
1010

1111
user.research_contact_status = research_contact_status
12+
user.user_research_opted_in_at = Time.zone.now
1213
user.save!
1314
end
1415

app/models/user.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class UserAuthenticationException < StandardError; end
2323
enum :research_contact_status, {
2424
consented: "consented",
2525
declined: "declined",
26-
not_asked: "not_asked",
2726
to_be_asked: "to_be_asked",
2827
}, prefix: "research_contact"
2928

app/services/reports/contact_for_research_service.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ def rows
1818
end
1919

2020
def as_data_rows(raw_data)
21-
raw_data.map do |name, email, created_at|
22-
[{ text: name }, { text: email }, { text: created_at.to_date.to_formatted_s }]
21+
raw_data.map do |name, email, user_research_opted_in_at|
22+
[{ text: name }, { text: email }, { text: user_research_opted_in_at.to_formatted_s(:long) }]
2323
end
2424
end
2525

2626
def user_contact_for_research
27-
User.research_contact_consented.order(created_at: :desc).pluck(:name, :email, :created_at)
27+
User.research_contact_consented.order(user_research_opted_in_at: :desc).pluck(:name, :email, :user_research_opted_in_at)
2828
end
2929
end

config/initializers/warden/strategies/user_research.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def prep_user(auth_hash)
1717
provider: Settings.auth_provider,
1818
uid: auth_hash[:uid],
1919
terms_agreed_at: Time.zone.now,
20+
research_contact_status: "declined",
21+
user_research_opted_in_at: Time.zone.now,
2022
)
2123
end
2224

config/locales/en.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,9 +1417,9 @@ en:
14171417
back_link: Back to reports
14181418
back_to_feature_usage: Back to feature and answer type usage
14191419
contact_for_research:
1420-
heading: Users who have agreed to be contacted for user research
1420+
heading: Users who’ve agreed to be contacted about user research
14211421
table_headings:
1422-
date_added: Sign up date
1422+
date_added: Date agreed
14231423
email: Email
14241424
name: Name
14251425
title: Users interested in research

db/migrate/20250403131603_add_contact_for_research_to_users.rb

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class AddContactForResearchToUsers < ActiveRecord::Migration[8.0]
2+
def change
3+
change_table(:users, bulk: true) do |t|
4+
t.column :research_contact_status, :string, default: "to_be_asked"
5+
t.column :user_research_opted_in_at, :datetime
6+
end
7+
end
8+
end

db/schema.rb

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

db/seeds.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
uid: "123456",
2626
provider: :mock_gds_sso,
2727
terms_agreed_at: Time.zone.now,
28-
research_contact_status: :consented })
28+
research_contact_status: :consented,
29+
user_research_opted_in_at: Time.zone.now })
2930

3031
MouSignature.create! user: default_user, organisation: gds
3132

@@ -57,6 +58,7 @@
5758
organisation: test_org,
5859
provider: :seed,
5960
research_contact_status: :consented,
61+
user_research_opted_in_at: Time.zone.now,
6062
)
6163

6264
# create extra super admins
@@ -90,6 +92,7 @@
9092
terms_agreed_at: Time.utc(2024, 4, 22, 9, 30),
9193
provider: :seed,
9294
research_contact_status: :consented,
95+
user_research_opted_in_at: Time.utc(2024, 4, 22, 9, 30),
9396
)
9497

9598
# while we're using Signon it is possible to have users who aren't linked to

spec/factories/models/users.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
updated_at { created_at }
1111
last_signed_in_at { created_at }
1212
terms_agreed_at { Time.zone.now }
13+
research_contact_status { "declined" }
14+
user_research_opted_in_at { Time.zone.now }
1315

1416
factory :basic_auth_user do
1517
provider { "basic_auth" }

0 commit comments

Comments
 (0)