update existing users

This commit is contained in:
Seth Call 2021-01-11 17:51:06 -06:00
parent 1eaaf8d4bf
commit ad1e784adb
5 changed files with 95 additions and 24 deletions

View File

@ -7,22 +7,25 @@ ActiveAdmin.register_page "SchoolUserUploads" do
puts params
@client = RecurlyClient.new
file = params[:jam_ruby_user][:csv]
created = 0
already_existing = 0
array_of_arrays = CSV.read(file.tempfile.path, headers:true, encoding: 'bom|utf-8')
errors = 0
updated = 0
skipped = 0
array_of_arrays = CSV.read(file.tempfile.path, headers: true, encoding: 'bom|utf-8')
array_of_arrays.each do |row|
school_name = row['School Name']
school_tag = row['School ID']
school_name = row['School Name'].strip
school_tag = row['School ID'].strip
school = School.autocreate_find_from_upload(school_name, school_tag)
first_name = row['First Name']
last_name = row['Last Name']
email_address = row['Email Address']
license_start = parse_date(row['License Start Date'])
license_end = parse_date(row['License End Date'])
source = row['Source']
first_name = row['First Name'].strip
last_name = row['Last Name'].strip
email_address = row['Email Address'].strip
license_start = parse_date(row['License Start Date'].strip)
license_end = parse_date(row['License End Date'].strip)
source = row['Source'].strip
password = SecureRandom.uuid
options = {
first_name: first_name,
@ -39,24 +42,74 @@ ActiveAdmin.register_page "SchoolUserUploads" do
password_confirmation: password
}
parse_user_type(row['User Type'], options)
parse_user_type(row['User Type'].strip, options)
instrument = Instrument.find('electric guitar')
instruments= [{instrument_id: instrument.id, proficiency_level: 3, priority: 1}]
options[:instruments] = instruments
existing = User.find_by_email(options[:email])
if existing
if existing.import_source.nil?
if options[:student]
existing.school = school
existing.is_a_student = true
existing.import_source = options[:import_source]
existing.license_start = options[:license_start]
existing.license_end = options[:license_end]
elsif options[:teacher]
existing.school = school
existing.import_source = options[:import_source]
existing.license_start = options[:license_start]
existing.license_end = options[:license_end]
if existing.teacher.nil?
existing.teacher = Teacher.build_teacher(existing, validate_introduction: true, biography: "Empty biography", school_id: school.id)
end
elsif options[:platform_instructor]
existing.import_source = options[:import_source]
existing.is_platform_instructor = true
existing.license_start = options[:license_start]
existing.license_end = options[:license_end]
end
existing.save
if existing.errors.any?
puts "User #{user.name} #{user.email} had errors"
puts user.errors.inspect
errors = errors + 1
else
@client.sync_subscription(existing)
updated = updated + 1
if options[:student]
UserMailer.school_welcome_message(existing, nil).deliver_now
elsif options[:teacher]
UserMailer.school_welcome_message(existing, nil).deliver_now
elsif options[:platform_instructor]
end
end
else
skipped = skipped + 1
end
else
user = User.signup(options)
if user.errors.any?
puts "User #{user.name} #{user.email} had errors"
puts user.errors.inspect
already_existing = already_existing + 1
errors = errors + 1
else
@client.sync_subscription(user)
puts "User #{user.email} created"
created = created + 1
end
end
redirect_to admin_schooluseruploads_path, :notice => "Created #{created} school students. Ignored #{already_existing} because already existed."
end
redirect_to admin_schooluseruploads_path, :notice => "Created #{created}. Updated #{updated}. Errors #{errors}. Skipped #{skipped}"
end
end

View File

@ -244,7 +244,12 @@ module JamRuby
def school_welcome_message(user, reset_url)
@user = user
if reset_url
@subject= "Set a password on your new JamKazam account for your #{user.school.name} music program"
else
@subject= "Your JamKazam account has been linked to your #{user.school.name} music program"
end
@school = user.school
@reset_url = reset_url

View File

@ -13,6 +13,7 @@
You can also use JamKazam to play and record yourself on your own.
</p>
<% if @reset_url %>
<p>
To use the JamKazam app, you will need to sign in to the app using an email address and a password.
The email address is the one to which this email was sent.
@ -26,6 +27,14 @@
Set Password
</a>
</p>
<% else %>
<p>
We noticed you already have an account at JamKazam, under the email address to which this email was sent.
Next time you log into the application, your account will have been associated with your school and has a subscription license from your school.
If you're worried this is a scam, please check with your school or music program instructor to verify that this is a legitimate email.
</p>
<% end %>
<br>
<p>

View File

@ -7,12 +7,18 @@ so that you can participate in an online music education program through your sc
JamKazam is an application and a platform that lets you play music with other students over the Internet, live and in sync.
You can also use JamKazam to play and record yourself on your own.
<% if @reset_url %>
To use the JamKazam app, you will need to sign in to the app using an email address and a password.
The email address is the one to which this email was sent.
Click the button below to set a password for your JamKazam account.
If you're worried this is a scam, please check with your school or music program instructor to verify that this is a legitimate email.
Set Password: <%= @reset_url %>
<% else %>
We noticed you already have an account at JamKazam, under the email address to which this email was sent.
Next time you log into the application, your account will have been associated with your school and has a subscription license from your school.
If you're worried this is a scam, please check with your school or music program instructor to verify that this is a legitimate email.
<% end %>
Your instructor will help you to start using the JamKazam app in your music program with other students.
If you already have your gear and want to set it up and start playing around with it,

View File

@ -596,8 +596,6 @@ module JamRuby
user.subscription_sync_code = 'good_standing_ignored'
user.subscription_sync_msg = "user is in good standing but the desired plan is less than subscription plan; plan_code not touched"
end
else
puts "good standing user #{user.email} had no changes"
user.subscription_sync_code = 'good_standing_unchanged'