From 8911c8ed65513ea4c1574bc1bb0b5d1a9039ca69 Mon Sep 17 00:00:00 2001
From: Seth Call
Date: Sat, 17 Oct 2020 12:30:42 -0500
Subject: [PATCH] done
---
admin/app/admin/dashboard.rb | 6 +--
admin/app/admin/jam_ruby_users.rb | 12 +++++
admin/app/admin/school_user_uploads.rb | 17 +++++-
.../assets/csvs/Sample_School_User_Upload.csv | 1 +
admin/app/helpers/application_helper.rb | 7 ++-
admin/app/views/admin/users/_form.html.slim | 1 +
admin/config/application.rb | 1 +
admin/config/initializers/jam_ruby_user.rb | 2 +-
ruby/lib/jam_ruby/app/mailers/user_mailer.rb | 22 +++++++-
.../school_welcome_message.html.erb | 46 ++++++++++++++++
.../school_welcome_message.text.erb | 28 ++++++++++
.../user_mailer/welcome_message.html.erb | 14 +++++
.../jam_ruby/constants/validation_messages.rb | 2 +
ruby/lib/jam_ruby/models/connection.rb | 7 +++
ruby/lib/jam_ruby/models/user.rb | 54 +++++++++++++++----
15 files changed, 203 insertions(+), 17 deletions(-)
create mode 100644 admin/app/assets/csvs/Sample_School_User_Upload.csv
create mode 100644 ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/school_welcome_message.html.erb
create mode 100644 ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/school_welcome_message.text.erb
diff --git a/admin/app/admin/dashboard.rb b/admin/app/admin/dashboard.rb
index e4c5ff6db..d5d4af4a9 100644
--- a/admin/app/admin/dashboard.rb
+++ b/admin/app/admin/dashboard.rb
@@ -8,11 +8,9 @@ ActiveAdmin.register_page "Dashboard" do
span "JamKazam Administration Portal"
small ul do
li link_to "Users", admin_users_path
+ li link_to "K12 Users", admin_users_path("q[import_source_equals]": "K12")
li link_to "Teachers", admin_teachers_path
- li link_to "Onboarding Management", admin_onboarder_managements_path
- li link_to "Onboarding Settings", admin_onboarders_path
- li link_to "Lesson Sessions", admin_lesson_sessions_path
- li link_to "Slow Lesson Responses", admin_slow_responses_path
+ li link_to "Upload School Users", admin_schooluseruploads_path
end
end
diff --git a/admin/app/admin/jam_ruby_users.rb b/admin/app/admin/jam_ruby_users.rb
index c6aa726f1..a71f1f13e 100644
--- a/admin/app/admin/jam_ruby_users.rb
+++ b/admin/app/admin/jam_ruby_users.rb
@@ -30,6 +30,10 @@ ActiveAdmin.register JamRuby::User, :as => 'Users' do
redirect_to :back, {notice: "Reset password to #{resetting_to }"}
end
+ member_action :create_reset, :method => :get do
+ reset_url = resource.create_tokened_reset_url
+ redirect_to :back, {notice: "Reset password url created: #{reset_url}"}
+ end
@@ -95,6 +99,13 @@ ActiveAdmin.register JamRuby::User, :as => 'Users' do
end
end
+ row "Password Reset URL" do |user|
+ span do
+ link_to("Create Reset URL", create_reset_admin_user_path(user.id), :data => {:confirm => 'Are you sure?'})
+ end
+ end
+
+
row :jamclass_credits
row :via_amazon
row "Web Profile" do
@@ -289,6 +300,7 @@ ActiveAdmin.register JamRuby::User, :as => 'Users' do
@user.last_name = params[:jam_ruby_user][:last_name]
@user.state = params[:jam_ruby_user][:state]
@user.city = params[:jam_ruby_user][:city]
+ @user.is_platform_instructor = params[:jam_ruby_user][:is_platform_instructor]
@user.gifted_jamtracks = params[:jam_ruby_user][:gifted_jamtracks]
diff --git a/admin/app/admin/school_user_uploads.rb b/admin/app/admin/school_user_uploads.rb
index 2ce09f4cc..30ed6c6c6 100644
--- a/admin/app/admin/school_user_uploads.rb
+++ b/admin/app/admin/school_user_uploads.rb
@@ -9,6 +9,9 @@ ActiveAdmin.register_page "SchoolUserUploads" do
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')
array_of_arrays.each do |row|
school_name = row['School Name']
@@ -43,13 +46,25 @@ ActiveAdmin.register_page "SchoolUserUploads" do
options[:instruments] = instruments
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
+ else
+ puts "User #{user.email} created"
+ created = created + 1
+ end
end
- redirect_to admin_schooluseruploads_path, :notice => "Created #{array_of_arrays.length} school students!"
+ redirect_to admin_schooluseruploads_path, :notice => "Created #{created} school students. Ignored #{already_existing} because already existed."
end
end
content do
+ panel "Help" do
+ link_to "Download Sample CSV", asset_path("Sample_School_User_Upload.csv", target: "_blank", download: "Sample_School_User_Upload.csv")
+ end
+
active_admin_form_for User.new, :url => admin_schooluseruploads_upload_schooluseruploads_path, :builder => ActiveAdmin::FormBuilder do |f|
f.inputs "Upload School Users" do
f.input :csv, as: :file, required: true, :label => "A school user upload"
diff --git a/admin/app/assets/csvs/Sample_School_User_Upload.csv b/admin/app/assets/csvs/Sample_School_User_Upload.csv
new file mode 100644
index 000000000..be9022424
--- /dev/null
+++ b/admin/app/assets/csvs/Sample_School_User_Upload.csv
@@ -0,0 +1 @@
+First Name,Last Name,Email Address,User Type,School ID,School Name,License Start Date,License End Date,Source
Student,Student,seth+student1@jamkazam.com,Student,school_a,School A,1/1/20,1/1/21,K12
Student,Expired,seth+student2@jamkazam.com,Student,school_a,School A,1/2/19,1/1/20,K12
Teacher,Teacher,seth+teacher1@jamkazam.com,Student Instructor,school_a,School A,1/1/20,1/1/21,K12
Platform,Instructor,seth+platform1@jamkazam.com,Platform Instructor,school_a,School A,1/1/20,1/2/21,K12
\ No newline at end of file
diff --git a/admin/app/helpers/application_helper.rb b/admin/app/helpers/application_helper.rb
index 6ca3558ad..c1545e10f 100644
--- a/admin/app/helpers/application_helper.rb
+++ b/admin/app/helpers/application_helper.rb
@@ -26,7 +26,12 @@ module ApplicationHelper
raise JamRuby::JamPermissionError, "date #{date} has no '-' or '/'"
end
- if bits[2].length == '4'
+ if bits[2].length == 4 || (bits[0].length != 4 && bits[2].to_i > 12) # excel likes to do 1/1/20. So if last
+ if bits[2].length == 2
+ # prepend year
+
+ date = [bits[0], bits[1], '20' + bits[2]].join(delimiter)
+ end
Date.strptime(date, "%m#{delimiter}%d#{delimiter}%Y")
else
Date.strptime(date, "%Y#{delimiter}%m#{delimiter}%d")
diff --git a/admin/app/views/admin/users/_form.html.slim b/admin/app/views/admin/users/_form.html.slim
index df29c3115..adae73563 100644
--- a/admin/app/views/admin/users/_form.html.slim
+++ b/admin/app/views/admin/users/_form.html.slim
@@ -4,6 +4,7 @@
= f.input :admin
= f.input :is_onboarder, label: 'Is Support Consultant'
= f.input :subscribe_email, label: 'Subscribed to Emails?'
+ = f.input :is_platform_instructor, label: 'Is Platform Instructor?'
= f.input :gifted_jamtracks, label: 'JamTrack Credits'
= f.input :first_name
= f.input :last_name
diff --git a/admin/config/application.rb b/admin/config/application.rb
index e95a6a7c0..cffb75506 100644
--- a/admin/config/application.rb
+++ b/admin/config/application.rb
@@ -37,6 +37,7 @@ module JamAdmin
# Activate observers that should always be running.
config.active_record.observers = "JamRuby::InvitedUserObserver"
+ config.assets.paths << "#{Rails.root}/app/assets/csvs"
config.assets.prefix = "#{ENV['RAILS_RELATIVE_URL_ROOT']}/assets"
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
diff --git a/admin/config/initializers/jam_ruby_user.rb b/admin/config/initializers/jam_ruby_user.rb
index 8b27e88a8..b6e0ca6e5 100644
--- a/admin/config/initializers/jam_ruby_user.rb
+++ b/admin/config/initializers/jam_ruby_user.rb
@@ -1,6 +1,6 @@
class JamRuby::User
- attr_accessible :admin, :raw_password, :musician, :can_invite, :photo_url, :session_settings, :confirm_url, :teacher_attributes, :email_template # :invite_email
+ attr_accessible :admin, :raw_password, :musician, :can_invite, :photo_url, :session_settings, :confirm_url, :teacher_attributes, :email_template, :is_platform_instructor # :invite_email
accepts_nested_attributes_for :teacher, allow_destroy: true
diff --git a/ruby/lib/jam_ruby/app/mailers/user_mailer.rb b/ruby/lib/jam_ruby/app/mailers/user_mailer.rb
index daa048f00..1d23e2a63 100644
--- a/ruby/lib/jam_ruby/app/mailers/user_mailer.rb
+++ b/ruby/lib/jam_ruby/app/mailers/user_mailer.rb
@@ -35,8 +35,9 @@ module JamRuby
end
end
- def welcome_message(user)
+ def welcome_message(user, reset_url = nil)
@user = user
+ @reset_url = reset_url
sendgrid_category "Welcome"
sendgrid_unique_args :type => "welcome_message"
@@ -218,6 +219,25 @@ module JamRuby
end
end
+ def school_welcome_message(user, reset_url)
+ @user = user
+ @subject= "Set a password on your new JamKazam account for your #{user.school.name} music program"
+ @school = user.school
+ @reset_url = reset_url
+
+ sendgrid_category "Welcome"
+ sendgrid_unique_args :type => "welcome_message"
+
+ sendgrid_recipients([user.email])
+ sendgrid_substitute('@USERID', [user.id])
+ sendgrid_substitute(EmailBatchProgression::VAR_FIRST_NAME, [user.first_name])
+
+ mail(:to => user.email, :subject => @subject) do |format|
+ format.text
+ format.html
+ end
+ end
+
def teacher_welcome_message(user)
@user = user
@subject= "Welcome to JamKazam and JamClass online lessons!"
diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/school_welcome_message.html.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/school_welcome_message.html.erb
new file mode 100644
index 000000000..db1bf29cf
--- /dev/null
+++ b/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/school_welcome_message.html.erb
@@ -0,0 +1,46 @@
+<% provide(:title, @subject) %>
+
+
+<% if !@user.anonymous? %>
+ Hello <%= @vars[EmailBatch::VAR_FIRST_NAME] %> --
+
+<% end %>
+
+
+ Your school <%= @school.name %> has set up a JamKazam account for you,
+ so that you can participate in an online music education program through your school.
+ 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.
+
+
+
+ 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
+
+
+
+
+
+ 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,
+ you can check out our summary setup instructions
+ https://jamkazam.freshdesk.com/support/solutions/articles/66000259828
+ and also learn about the features you can use to create, join, and play in online music sessions
+ https://jamkazam.freshdesk.com/support/solutions/66000073845.
+
+
+ We hope you enjoy playing music on the JamKazam platform! If you run into trouble, please use this page to ask for help
+ https://jamkazam.freshdesk.com/support/tickets/new.
+
+
+
+Best Regards,
+ Team JamKazam
\ No newline at end of file
diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/school_welcome_message.text.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/school_welcome_message.text.erb
new file mode 100644
index 000000000..306724c13
--- /dev/null
+++ b/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/school_welcome_message.text.erb
@@ -0,0 +1,28 @@
+<% if !@user.anonymous? %>
+Hello <%= @vars[EmailBatch::VAR_FIRST_NAME] %> --
+<% end %>
+
+Your school <%= @school.name %> has set up a JamKazam account for you,
+so that you can participate in an online music education program through your school.
+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.
+
+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 %>
+
+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,
+you can check out our summary setup instructions https://jamkazam.freshdesk.com/support/solutions/articles/66000259828
+and also learn about the features you can use to create, join, and play in online music sessions
+
+https://jamkazam.freshdesk.com/support/solutions/66000073845.
+
+We hope you enjoy playing music on the JamKazam platform! If you run into trouble, please use this page to ask for help
+https://jamkazam.freshdesk.com/support/tickets/new.
+
+Best Regards,
+Team JamKazam
\ No newline at end of file
diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/welcome_message.html.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/welcome_message.html.erb
index d1cb98bc4..62c05046c 100644
--- a/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/welcome_message.html.erb
+++ b/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/welcome_message.html.erb
@@ -12,6 +12,20 @@
your inbox so you can refer back to the links if needed.
+<% if @reset_url %>
+
+ Your account was imported for you, so you'll need to set a password.
+ Click the button below to set a password for your JamKazam account.
+
+
+
+
+ Set Password
+
+
+
+ <% end %>
+
For Playing Music Together Live & In Sync From Different Locations
JamKazam's Mac and Windows desktop apps let musicians play together live and in sync with
high-quality audio from different locations over the Internet, with an amazing feature set for
diff --git a/ruby/lib/jam_ruby/constants/validation_messages.rb b/ruby/lib/jam_ruby/constants/validation_messages.rb
index d823c99e1..7dbaf3bb4 100644
--- a/ruby/lib/jam_ruby/constants/validation_messages.rb
+++ b/ruby/lib/jam_ruby/constants/validation_messages.rb
@@ -64,6 +64,8 @@ module ValidationMessages
CANT_JOIN_MULTIPLE_SESSIONS = 'You cannot join more than one music session'
CANT_JOIN_SCHOOL_SESSION = "You can not join school sessions"
CAN_ONLY_JOIN_SAME_SCHOOL_SESSION = "You can only join sessions from your school"
+ LICENSE_EXPIRED = "Your license has expired"
+ LICENSE_NOT_STARTED = "Your license has not started"
# chat
CAN_ONLY_CHAT_SAME_SCHOOL = "You can only message others from your school"
diff --git a/ruby/lib/jam_ruby/models/connection.rb b/ruby/lib/jam_ruby/models/connection.rb
index 3ee8dec1c..3481e99b1 100644
--- a/ruby/lib/jam_ruby/models/connection.rb
+++ b/ruby/lib/jam_ruby/models/connection.rb
@@ -158,6 +158,13 @@ module JamRuby
end
end
+ if self.user.license_expired?
+ errors.add(:music_session, ValidationMessages::LICENSE_EXPIRED)
+ end
+
+ if self.user.license_not_started?
+ errors.add(:music_session, ValidationMessages::LICENSE_NOT_STARTED)
+ end
# unless user.admin?
# num_sessions = Connection.where(:user_id => user_id)
diff --git a/ruby/lib/jam_ruby/models/user.rb b/ruby/lib/jam_ruby/models/user.rb
index b47fa5852..f86bf186b 100644
--- a/ruby/lib/jam_ruby/models/user.rb
+++ b/ruby/lib/jam_ruby/models/user.rb
@@ -718,6 +718,16 @@ module JamRuby
self.birth_date.nil? ? nil : now.year - self.birth_date.year - (self.birth_date.to_date.change(:year => now.year) > now ? 1 : 0)
end
+ # has the user's license started? only valid if they have a license
+ def license_not_started?
+ license_start && Time.now < license_start
+ end
+
+ # has the user's license ended? Only valid if they have a license
+ def license_expired?
+ license_end && Time.now > license_end
+ end
+
def session_count
0
#MusicSession.where("user_id = ? AND started_at IS NOT NULL", self.id).size
@@ -957,8 +967,14 @@ module JamRuby
if user.reset_password_token != token
raise JamRuby::JamArgumentError.new("Invalid reset token", "token")
end
- if Time.now - user.reset_password_token_created > 3.days
- raise JamRuby::JamArgumentError.new("Password reset has expired", "token")
+ if user.import_source
+ if Time.now - user.reset_password_token_created > 180.days
+ raise JamRuby::JamArgumentError.new("Password reset has expired", "token")
+ end
+ else
+ if Time.now - user.reset_password_token_created > 3.days
+ raise JamRuby::JamArgumentError.new("Password reset has expired", "token")
+ end
end
if new_password.nil? || new_password == ""
raise JamRuby::JamArgumentError.new("Password is empty", "password")
@@ -997,6 +1013,13 @@ module JamRuby
user
end
+ def create_tokened_reset_url
+ self.reset_password_token = SecureRandom.urlsafe_base64
+ self.reset_password_token_created = Time.now
+ self.save
+ "#{APP_CONFIG.external_root_url}/reset_password_token?token=#{self.reset_password_token}&email=#{CGI.escape(email)}"
+ end
+
def self.band_index(user_id)
bands = Band.joins(:band_musicians)
.where(:bands_musicians => {:user_id => "#{user_id}"})
@@ -1459,6 +1482,7 @@ module JamRuby
user.last_name = last_name if last_name.present?
user.email = email
user.import_source = import_source
+ user.email_confirmed = !user.import_source.nil?
user.subscribe_email = import_source.nil?
user.license_start = license_start
user.license_end = license_end
@@ -1494,15 +1518,13 @@ module JamRuby
if school_id.present?
if user.is_a_student
- puts "IS A STUDENT"
user.school_id = school_id
user.affiliate_referral = school.affiliate_partner
elsif user.is_a_teacher
school = School.find_by_id(school_id)
- puts "IS A TEACHER"
+ user.school_id = school_id
user.teacher = Teacher.build_teacher(user, validate_introduction: true, biography: "Empty biography", school_id: school_id)
user.affiliate_referral = school.affiliate_partner
- puts "MADE TEACHER"
end
elsif retailer_id.present?
if user.is_a_student
@@ -1636,7 +1658,6 @@ module JamRuby
user.save
- puts "HOPE"
# now that the user is saved, let's
if invited_user && invited_user.autofriend && !invited_user.sender.nil?
# hookup this user with the sender
@@ -1721,6 +1742,11 @@ module JamRuby
user.handle_test_drive_package(test_drive_package, test_drive_package_details) if test_drive_package
+ reset_url = nil
+ if user.import_source
+ reset_url = user.create_tokened_reset_url
+ end
+
if import_source.nil? && user.is_a_student
#if school && school.education
# UserMailer.student_education_welcome_message(user).deliver_now
@@ -1746,9 +1772,20 @@ module JamRuby
#end
+ elsif user.is_a_student
+ if user.import_source
+ UserMailer.school_welcome_message(user, reset_url).deliver_now
+ else
+ UserMailer.student_welcome_message(user).deliver_now
+ end
elsif user.is_a_teacher
- puts "Email teacher"
- UserMailer.teacher_welcome_message(user).deliver_now
+ if user.import_source
+ UserMailer.school_welcome_message(user, reset_url).deliver_now
+ else
+ UserMailer.teacher_welcome_message(user).deliver_now
+ end
+ elsif user.is_platform_instructor
+ UserMailer.welcome_message(user, reset_url).deliver_now
elsif user.education_interest
UserMailer.education_owner_welcome_message(user).deliver_now
elsif user.school_interest
@@ -1756,7 +1793,6 @@ module JamRuby
elsif user.retailer_interest
UserMailer.retailer_owner_welcome_message(user).deliver_now
else
- puts" generic welocem"
UserMailer.welcome_message(user).deliver_now
end