Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teacher opt-in to share email information with regional partners #42034

Merged
merged 14 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ let schoolData = {
countryCode: usIp ? 'US' : ''
};

// Keep track of whether the current user is in the U.S. or not (for regional partner email sharing)
let isInUnitedStates = schoolData.countryCode === 'US';

$(document).ready(() => {
const schoolInfoMountPoint = document.getElementById('school-info-inputs');
init();
Expand Down Expand Up @@ -179,11 +182,13 @@ $(document).ready(() => {
function switchToTeacher() {
fadeInFields(TEACHER_ONLY_FIELDS);
hideFields(STUDENT_ONLY_FIELDS);
toggleVisShareEmailRegPartner(isInUnitedStates);
}

function switchToStudent() {
fadeInFields(STUDENT_ONLY_FIELDS);
hideFields(TEACHER_ONLY_FIELDS);
toggleVisShareEmailRegPartner(false);
}

function trackUserType(type) {
Expand All @@ -203,6 +208,16 @@ $(document).ready(() => {
$(fields.join(', ')).hide();
}

// Show opt-in for teachers in the U.S. for sharing their email with
// Code.org regional partners.
function toggleVisShareEmailRegPartner(isTeacherInUnitedStates) {
if (isTeacherInUnitedStates) {
$('#share-email-reg-part-preference-radio').fadeIn();
} else {
$('#share-email-reg-part-preference-radio').hide();
}
}

function renderSchoolInfo() {
if (schoolInfoMountPoint) {
ReactDOM.render(
Expand Down Expand Up @@ -237,6 +252,8 @@ $(document).ready(() => {
schoolData.country = event.value;
schoolData.countryCode = event.label;
}
isInUnitedStates = schoolData.countryCode === 'US';
toggleVisShareEmailRegPartner(isInUnitedStates);
renderSchoolInfo();
}

Expand Down
2 changes: 1 addition & 1 deletion dashboard/app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1991,7 +1991,7 @@ a.download-video {
}
}

#email-preference-radio {
#email-preference-radio, #share-email-reg-part-preference-radio {
p {
margin: 0;
}
Expand Down
1 change: 1 addition & 0 deletions dashboard/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def prevent_caching
:hashed_email,
:terms_of_service_version,
:email_preference_opt_in,
:share_teacher_email_reg_partner_opt_in_radio_choice,
:data_transfer_agreement_accepted,
:data_transfer_agreement_required,
:parent_email_preference_opt_in_required,
Expand Down
14 changes: 14 additions & 0 deletions dashboard/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class User < ApplicationRecord
parent_email_banner_dismissed
section_attempts
section_attempts_last_reset
share_teacher_email_regional_partner_opt_in
)

# Include default devise modules. Others available are:
Expand Down Expand Up @@ -218,6 +219,8 @@ class User < ApplicationRecord

after_save :save_parent_email_preference, if: :parent_email_preference_opt_in_required?

after_save :save_email_reg_partner_preference, if: -> {share_teacher_email_reg_partner_opt_in_radio_choice.present?}

before_destroy :soft_delete_channels

def save_email_preference
Expand Down Expand Up @@ -245,6 +248,15 @@ def save_parent_email_preference
end
end

# Enables/disables sharing of emails of teachers in the U.S. to Code.org regional partners based on user's choice.
def save_email_reg_partner_preference
TurnerRiley marked this conversation as resolved.
Show resolved Hide resolved
user = User.find_by_email_or_hashed_email(email)
if teacher? && share_teacher_email_reg_partner_opt_in_radio_choice.downcase == "yes"
user.share_teacher_email_regional_partner_opt_in = DateTime.now
user.save!
end
end

# after_create :send_new_teacher_email
# def send_new_teacher_email
# TODO: it's not easy to pass cookies into an after_create call, so for now while this is behind a page mode
Expand Down Expand Up @@ -396,6 +408,8 @@ def self.find_or_create_facilitator(params, invited_by_user)
attr_accessor :parent_email_preference_request_ip
attr_accessor :parent_email_preference_source

attr_accessor :share_teacher_email_reg_partner_opt_in_radio_choice

attr_accessor :data_transfer_agreement_required

has_many :plc_enrollments, class_name: '::Plc::UserCourseEnrollment', dependent: :destroy
Expand Down
14 changes: 14 additions & 0 deletions dashboard/app/views/devise/registrations/_finish_sign_up.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,20 @@
= f.radio_button :email_preference_opt_in, 'no'
= f.label :email_preference_opt_in, t('signup_form.email_preference_no'), value: 'no'

.row#share-email-reg-part-preference-radio{style: "display: none;"}
.span10.signup-field-label
%p
= t('signup_form.share_teacher_email_reg_partner_question', cdo_regional_partner_desc: CDO.code_org_url('/educate/regional-partner'), markdown: true).html_safe
- if @user.errors[:share_teacher_email_reg_partner_opt_in_radio_choice].present?
%p.error= t('signup_form.share_teacher_email_reg_partner_preference_required')
.span2{style:"display:block"}
.radio
= f.radio_button :share_teacher_email_reg_partner_opt_in_radio_choice, 'yes'
= f.label :share_teacher_email_reg_partner_opt_in_radio_choice, t('signup_form.share_teacher_email_reg_partner_preference_yes'), value: 'yes'
.radio
= f.radio_button :share_teacher_email_reg_partner_opt_in_radio_choice, 'no'
= f.label :share_teacher_email_reg_partner_opt_in_radio_choice, t('signup_form.share_teacher_email_reg_partner_preference_no'), value: 'no'

.row
.span10.tos
= f.hidden_field :terms_of_service_version, value: User::TERMS_OF_SERVICE_VERSIONS.last
Expand Down
4 changes: 4 additions & 0 deletions dashboard/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ en:
email_preference_yes: "Yes"
email_preference_no: "No"
email_preference_required: "You must specify an email preference."
share_teacher_email_reg_partner_question: "Would you like us to share your contact information with the [Code.org regional partner](%{cdo_regional_partner_desc}) in your state so that they may notify you about local professional development, resources, and events?"
share_teacher_email_reg_partner_preference_yes: "Yes"
share_teacher_email_reg_partner_preference_no: "No"
share_teacher_email_reg_partner_preference_required: "You must specify an email preference."
parent_account_checkbox: "I am a parent/guardian signing up on behalf of my child"
parent_account_email_progress_permission: "Can we email you with occasional updates on your child’s progress and projects, and updates about their course and computer science? [(See our privacy policy)](%{privacy_policy_url})"
parent_account_email_label: "Parent/Guardian Email"
Expand Down
54 changes: 54 additions & 0 deletions dashboard/test/controllers/registrations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,60 @@ class RegistrationsControllerTest < ActionController::TestCase
assert_equal EmailPreference::ACCOUNT_SIGN_UP, email_preference[:source]
end

test "create new teacher with us ip with opt-in to sharing email with regional partners set share_teacher_email_regional_partner_opt_in value to DateTime value" do
teacher_params = @default_params.update(user_type: 'teacher', email_preference_opt_in: 'no', share_teacher_email_reg_partner_opt_in_radio_choice: 'yes')
Geocoder.stubs(:search).returns([OpenStruct.new(country_code: 'US')])
assert_creates(User) do
post :create, params: {user: teacher_params}
end

teacher = User.last
assert_not_nil teacher.share_teacher_email_regional_partner_opt_in
end

test "create new teacher with us ip with opt-out to sharing email with regional partners ensure share_teacher_email_regional_partner_opt_in value is nil" do
teacher_params = @default_params.update(user_type: 'teacher', email_preference_opt_in: 'no', share_teacher_email_reg_partner_opt_in_radio_choice: 'no')
Geocoder.stubs(:search).returns([OpenStruct.new(country_code: 'US')])
assert_creates(User) do
post :create, params: {user: teacher_params}
end

teacher = User.last
assert_nil teacher.share_teacher_email_regional_partner_opt_in
end

test "create new teacher with us ip with no selection on sharing email with regional partners ensure share_teacher_email_regional_partner_opt_in value is nil" do
teacher_params = @default_params.update(user_type: 'teacher', email_preference_opt_in: 'no')
Geocoder.stubs(:search).returns([OpenStruct.new(country_code: 'US')])
assert_creates(User) do
post :create, params: {user: teacher_params}
end

teacher = User.last
assert_nil teacher.share_teacher_email_regional_partner_opt_in
end

test "create new teacher with non-us ip ensure share_teacher_email_regional_partner_opt_in value is nil" do
teacher_params = @default_params.update(user_type: 'teacher', email_preference_opt_in: 'no')
Geocoder.stubs(:search).returns([OpenStruct.new(country_code: 'CA')])
assert_creates(User) do
post :create, params: {user: teacher_params}
end

teacher = User.last
assert_nil teacher.share_teacher_email_regional_partner_opt_in
end

test "create new student ensure share_teacher_email_regional_partner_opt_in value is nil" do
student_params = @default_params
assert_creates(User) do
post :create, params: {user: student_params}
end

student = User.last
assert_nil student.share_teacher_email_regional_partner_opt_in
end

test "create new student in eu fails when missing value" do
eu_student_params = @default_params.update(
data_transfer_agreement_required: "1"
Expand Down