update existing users
This commit is contained in:
parent
1eaaf8d4bf
commit
ad1e784adb
|
|
@ -7,22 +7,25 @@ ActiveAdmin.register_page "SchoolUserUploads" do
|
||||||
|
|
||||||
puts params
|
puts params
|
||||||
|
|
||||||
|
@client = RecurlyClient.new
|
||||||
|
|
||||||
file = params[:jam_ruby_user][:csv]
|
file = params[:jam_ruby_user][:csv]
|
||||||
|
|
||||||
|
|
||||||
created = 0
|
created = 0
|
||||||
already_existing = 0
|
errors = 0
|
||||||
array_of_arrays = CSV.read(file.tempfile.path, headers:true, encoding: 'bom|utf-8')
|
updated = 0
|
||||||
|
skipped = 0
|
||||||
|
array_of_arrays = CSV.read(file.tempfile.path, headers: true, encoding: 'bom|utf-8')
|
||||||
array_of_arrays.each do |row|
|
array_of_arrays.each do |row|
|
||||||
school_name = row['School Name']
|
school_name = row['School Name'].strip
|
||||||
school_tag = row['School ID']
|
school_tag = row['School ID'].strip
|
||||||
school = School.autocreate_find_from_upload(school_name, school_tag)
|
school = School.autocreate_find_from_upload(school_name, school_tag)
|
||||||
first_name = row['First Name']
|
first_name = row['First Name'].strip
|
||||||
last_name = row['Last Name']
|
last_name = row['Last Name'].strip
|
||||||
email_address = row['Email Address']
|
email_address = row['Email Address'].strip
|
||||||
license_start = parse_date(row['License Start Date'])
|
license_start = parse_date(row['License Start Date'].strip)
|
||||||
license_end = parse_date(row['License End Date'])
|
license_end = parse_date(row['License End Date'].strip)
|
||||||
source = row['Source']
|
source = row['Source'].strip
|
||||||
password = SecureRandom.uuid
|
password = SecureRandom.uuid
|
||||||
options = {
|
options = {
|
||||||
first_name: first_name,
|
first_name: first_name,
|
||||||
|
|
@ -39,30 +42,80 @@ ActiveAdmin.register_page "SchoolUserUploads" do
|
||||||
password_confirmation: password
|
password_confirmation: password
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_user_type(row['User Type'], options)
|
parse_user_type(row['User Type'].strip, options)
|
||||||
|
|
||||||
instrument = Instrument.find('electric guitar')
|
instrument = Instrument.find('electric guitar')
|
||||||
instruments= [{instrument_id: instrument.id, proficiency_level: 3, priority: 1}]
|
instruments= [{instrument_id: instrument.id, proficiency_level: 3, priority: 1}]
|
||||||
options[:instruments] = instruments
|
options[:instruments] = instruments
|
||||||
user = User.signup(options)
|
|
||||||
|
|
||||||
if user.errors.any?
|
existing = User.find_by_email(options[:email])
|
||||||
puts "User #{user.name} #{user.email} had errors"
|
|
||||||
puts user.errors.inspect
|
if existing
|
||||||
already_existing = already_existing + 1
|
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
|
else
|
||||||
puts "User #{user.email} created"
|
user = User.signup(options)
|
||||||
created = created + 1
|
|
||||||
|
if user.errors.any?
|
||||||
|
puts "User #{user.name} #{user.email} had errors"
|
||||||
|
puts user.errors.inspect
|
||||||
|
errors = errors + 1
|
||||||
|
else
|
||||||
|
@client.sync_subscription(user)
|
||||||
|
puts "User #{user.email} created"
|
||||||
|
created = created + 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to admin_schooluseruploads_path, :notice => "Created #{created} school students. Ignored #{already_existing} because already existed."
|
redirect_to admin_schooluseruploads_path, :notice => "Created #{created}. Updated #{updated}. Errors #{errors}. Skipped #{skipped}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
content do
|
content do
|
||||||
panel "Help" do
|
panel "Help" do
|
||||||
link_to "Download Sample CSV", asset_path("Sample_School_User_Upload.csv", target: "_blank", download: "Sample_School_User_Upload.csv")
|
link_to "Download Sample CSV", asset_path("Sample_School_User_Upload.csv", target: "_blank", download: "Sample_School_User_Upload.csv")
|
||||||
end
|
end
|
||||||
|
|
||||||
active_admin_form_for User.new, :url => admin_schooluseruploads_upload_schooluseruploads_path, :builder => ActiveAdmin::FormBuilder do |f|
|
active_admin_form_for User.new, :url => admin_schooluseruploads_upload_schooluseruploads_path, :builder => ActiveAdmin::FormBuilder do |f|
|
||||||
|
|
|
||||||
|
|
@ -244,7 +244,12 @@ module JamRuby
|
||||||
|
|
||||||
def school_welcome_message(user, reset_url)
|
def school_welcome_message(user, reset_url)
|
||||||
@user = user
|
@user = user
|
||||||
@subject= "Set a password on your new JamKazam account for your #{user.school.name} music program"
|
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
|
@school = user.school
|
||||||
@reset_url = reset_url
|
@reset_url = reset_url
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
You can also use JamKazam to play and record yourself on your own.
|
You can also use JamKazam to play and record yourself on your own.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<% if @reset_url %>
|
||||||
<p>
|
<p>
|
||||||
To use the JamKazam app, you will need to sign in to the app using an email address and a password.
|
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.
|
The email address is the one to which this email was sent.
|
||||||
|
|
@ -26,6 +27,14 @@
|
||||||
Set Password
|
Set Password
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</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>
|
<br>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
|
||||||
|
|
@ -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.
|
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.
|
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.
|
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.
|
The email address is the one to which this email was sent.
|
||||||
Click the button below to set a password for your JamKazam account.
|
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.
|
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 %>
|
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.
|
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,
|
If you already have your gear and want to set it up and start playing around with it,
|
||||||
|
|
|
||||||
|
|
@ -596,8 +596,6 @@ module JamRuby
|
||||||
user.subscription_sync_code = 'good_standing_ignored'
|
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"
|
user.subscription_sync_msg = "user is in good standing but the desired plan is less than subscription plan; plan_code not touched"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
else
|
else
|
||||||
puts "good standing user #{user.email} had no changes"
|
puts "good standing user #{user.email} had no changes"
|
||||||
user.subscription_sync_code = 'good_standing_unchanged'
|
user.subscription_sync_code = 'good_standing_unchanged'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue