Merged in VRFS-5146-school_user_form (pull request #16)
new admin form to quickly add school user * new admin form to quickly add school user * add required: true to all form fields in quick add school user
This commit is contained in:
parent
3a248df971
commit
316cbdab83
|
|
@ -23,6 +23,112 @@ ActiveAdmin.register JamRuby::User, :as => 'Users' do
|
|||
|
||||
form :partial => "form"
|
||||
|
||||
action_item :school_user, only: :index do
|
||||
link_to "Quick Add School User", add_school_user_admin_users_path
|
||||
end
|
||||
|
||||
collection_action :add_school_user, method: [:get, :post] do
|
||||
if request.post?
|
||||
@client = RecurlyClient.new
|
||||
errors = []
|
||||
user_params = params[:jam_ruby_user]
|
||||
|
||||
user_type = user_params[:user_type].strip
|
||||
school_id = user_params[:school_id].strip
|
||||
|
||||
return (render text: "Please select school") if school_id.blank?
|
||||
|
||||
first_name = user_params[:first_name].strip
|
||||
last_name = user_params[:last_name].strip
|
||||
email = user_params[:email].strip.downcase
|
||||
license_start = user_params[:license_start].strip
|
||||
license_end = user_params[:license_end].strip
|
||||
import_source = user_params[:import_source].strip
|
||||
password = SecureRandom.uuid
|
||||
|
||||
options = {
|
||||
first_name: first_name,
|
||||
last_name: last_name,
|
||||
email: email,
|
||||
license_start: license_start,
|
||||
license_end: license_end,
|
||||
import_source: import_source,
|
||||
terms_of_service: true,
|
||||
musician: true,
|
||||
skip_recaptcha: true,
|
||||
password: password,
|
||||
password_confirmation: password
|
||||
}
|
||||
options.merge!({ school_id: school_id }) if school_id.present?
|
||||
|
||||
instrument = Instrument.find('electric guitar')
|
||||
instruments = [{instrument_id: instrument.id, proficiency_level: 3, priority: 1}]
|
||||
options[:instruments] = instruments
|
||||
|
||||
parse_user_type(user_type, options)
|
||||
|
||||
@user = User.find_by_email(options[:email])
|
||||
|
||||
unless @user.nil?
|
||||
@user.user_type = user_type
|
||||
#if @user.import_source.nil?
|
||||
#TODO: do we need to have following 3 lines for an existing user?
|
||||
@user.import_source = options[:import_source]
|
||||
@user.license_start = options[:license_start]
|
||||
@user.license_end = options[:license_end]
|
||||
|
||||
if options[:student]
|
||||
@user.school_id = options[:school_id]
|
||||
@user.is_a_student = true
|
||||
elsif options[:teacher]
|
||||
@user.school = school
|
||||
if @user.teacher.nil?
|
||||
@user.teacher = Teacher.build_teacher(@user, validate_introduction: true, biography: "Empty biography", school_id: school.id)
|
||||
end
|
||||
elsif options[:platform_instructor]
|
||||
@user.is_platform_instructor = true
|
||||
end
|
||||
|
||||
if @user.save
|
||||
@client.sync_subscription(@user)
|
||||
if options[:student]
|
||||
UserMailer.school_welcome_message(@user, nil).deliver_now
|
||||
elsif options[:teacher]
|
||||
UserMailer.school_welcome_message(@user, nil).deliver_now
|
||||
elsif options[:platform_instructor]
|
||||
end
|
||||
end
|
||||
if @user.errors.any?
|
||||
flash[:error] = "Error updating User #{@user.name} #{@user.email}"
|
||||
render :add_school_user
|
||||
else
|
||||
flash[:notice] = "User #{@user.name} #{@user.email} updated successfully"
|
||||
redirect_to admin_users_path
|
||||
end
|
||||
#end
|
||||
else
|
||||
@user = User.signup(options)
|
||||
|
||||
if @user.errors.none?
|
||||
@client.sync_subscription(@user)
|
||||
puts "User #{@user.email} created"
|
||||
flash[:notice] = "User #{@user.name} #{@user.email} added successfully"
|
||||
redirect_to admin_users_path
|
||||
else
|
||||
flash[:error] = "Error adding school user"
|
||||
render :add_school_user
|
||||
end
|
||||
end
|
||||
else
|
||||
@user = User.new
|
||||
@user.import_source = 'Manual'
|
||||
end
|
||||
end
|
||||
|
||||
member_action :update_school_user, method: [:get, :put] do
|
||||
|
||||
end
|
||||
|
||||
member_action :delete_forever, :method => :get do
|
||||
resource.permanently_delete
|
||||
redirect_to :back, {notice: 'User email and login credentials have been permanently changed'}
|
||||
|
|
@ -120,6 +226,7 @@ ActiveAdmin.register JamRuby::User, :as => 'Users' do
|
|||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
show do |user|
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
= semantic_form_for([:admin_users, @user], builder: ActiveAdmin::FormBuilder, :url => @user.new_record? ? add_school_user_admin_users_path : "/admin/users/#{@user.id}/add_school_user") do |f|
|
||||
= f.inputs "Details" do
|
||||
= f.input :email, label: 'Email', required: true
|
||||
= f.input :first_name, required: true
|
||||
= f.input :last_name, required: true
|
||||
= f.input :license_start, as: :datepicker, required: true
|
||||
= f.input :license_end, as: :datepicker, required: true
|
||||
= f.input :import_source, required: true
|
||||
= f.input :school_id, as: :select, collection: School.all, required: true
|
||||
= f.input :user_type, as: :select, collection: ['Student', 'Student Instructor', 'Platform Instructor'], include_blank: false, required: true
|
||||
= f.actions
|
||||
|
|
@ -14,6 +14,9 @@ JamAdmin::Application.routes.draw do
|
|||
namespace :admin do
|
||||
resources :users do
|
||||
get :autocomplete_user_email, :on => :collection
|
||||
get :add_school_user, on: :collection
|
||||
post :add_school_user, on: :collection
|
||||
patch :add_school_user, on: :member
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ module JamRuby
|
|||
attr_accessible :first_name, :last_name, :email, :city, :password, :password_confirmation, :state, :country, :birth_date, :subscribe_email, :terms_of_service, :original_fpfile, :cropped_fpfile, :cropped_large_fpfile, :cropped_s3_path, :cropped_large_s3_path, :photo_url, :large_photo_url, :crop_selection, :used_current_month, :used_month_play_time
|
||||
|
||||
# updating_password corresponds to a lost_password
|
||||
attr_accessor :test_drive_packaging, :validate_instruments, :updating_password, :updating_email, :updated_email, :update_email_confirmation_url, :administratively_created, :current_password, :setting_password, :confirm_current_password, :updating_avatar, :updating_progression_field, :mods_json, :expecting_gift_card, :purchase_required
|
||||
attr_accessor :test_drive_packaging, :validate_instruments, :updating_password, :updating_email, :updated_email, :update_email_confirmation_url, :administratively_created, :current_password, :setting_password, :confirm_current_password, :updating_avatar, :updating_progression_field, :mods_json, :expecting_gift_card, :purchase_required, :user_type
|
||||
belongs_to :icecast_server_group, class_name: "JamRuby::IcecastServerGroup", inverse_of: :users, foreign_key: 'icecast_server_group_id'
|
||||
|
||||
has_many :controlled_sessions, :class_name => "JamRuby::MusicSession", inverse_of: :session_controller, foreign_key: :session_controller_id
|
||||
|
|
|
|||
Loading…
Reference in New Issue