diff --git a/app/handlers/signup_start.rb b/app/handlers/signup_start.rb deleted file mode 100644 index b1bb0e085..000000000 --- a/app/handlers/signup_start.rb +++ /dev/null @@ -1,88 +0,0 @@ -class SignupStart - - lev_handler - - paramify :signup do - attribute :email, type: String - validates :email, presence: true - attribute :role, type: String - validates :role, presence: true - end - - def authorized? - true - end - - def handle - if !User.known_roles.include?(signup_params.role) - fatal_error(code: :unknown_role, offending_inputs: [:signup, :role]) - end - outputs.role = signup_params.role - - # If email in use, want users to login with that email, not create another account - fatal_error(code: :email_in_use, offending_inputs: [:signup, :email]) if email_in_use? - - fatal_error(code: :invalid, offending_inputs: [:signup, :email]) if invalid_email? - - # is there a pre_auth_state and it's email is unchanged - if existing_pre_auth_state.try(:contact_info_value) == email - existing_pre_auth_state.update(role: signup_params.role) - outputs.pre_auth_state = existing_pre_auth_state - # pre_auth_state may have been created in session start - # and the the confirmation email will not yet have been sent - deliver_validation_email if existing_pre_auth_state.confirmation_sent_at.nil? - return - end - - # Create a new one - new_pre_auth_state = PreAuthState.email_address.create( - is_partial_info_allowed: false, - contact_info_value: email, - role: signup_params.role, - signed_data: existing_pre_auth_state.try!(:signed_data), - return_to: options[:return_to] - ) - - # Blow away the user's existing signup email, if it exists - existing_pre_auth_state.try(:destroy) - - transfer_errors_from(new_pre_auth_state, - { map: { contact_info_value: :email }, - scope: :signup }, - true) - - - outputs.pre_auth_state = new_pre_auth_state - deliver_validation_email # Send the pin - end - - def deliver_validation_email - SignupConfirmationMailer.instructions( - pre_auth_state: outputs.pre_auth_state - ).deliver_later - end - - def email - signup_params.email.strip - end - - def email_in_use? - ContactInfo.verified.where('lower(value) = ?', email.downcase).any? - end - - def invalid_email? - e = EmailAddress.new(value: email) - - begin - e.mx_domain_validation - return e.errors.any? - rescue Mail::Field::IncompleteParseError - return true - end - end - - def existing_pre_auth_state - options[:existing_pre_auth_state] - end - -end diff --git a/app/handlers/signup_verify_by_token.rb b/app/handlers/signup_verify_by_token.rb deleted file mode 100644 index d715a58e7..000000000 --- a/app/handlers/signup_verify_by_token.rb +++ /dev/null @@ -1,25 +0,0 @@ -class SignupVerifyByToken - - lev_handler - - uses_routine ConfirmByCode, - translations: { outputs: { map: { contact_info: :pre_auth_state } }, - inputs: { type: :verbatim } } - uses_routine SignupExternalStudent, translations: { outputs: { type: :verbatim } } - - protected - - def authorized? - true - end - - def handle - run(ConfirmByCode, params[:code]) - - if outputs[:pre_auth_state].try!(:signed_student?) - run(SignupExternalStudent, pre_auth_state: outputs[:pre_auth_state], already_verified: true) - options[:session].sign_in!(outputs.user) - end - end - -end diff --git a/app/handlers/signup_verify_email.rb b/app/handlers/signup_verify_email.rb deleted file mode 100644 index 366cab5d3..000000000 --- a/app/handlers/signup_verify_email.rb +++ /dev/null @@ -1,26 +0,0 @@ -class SignupVerifyEmail - - lev_handler - - uses_routine ConfirmByPin - uses_routine SignupExternalStudent, translations: { outputs: { type: :verbatim } } - - paramify :pin do - attribute :pin, type: String - validates :pin, presence: true - end - - def authorized? - true - end - - def handle - run(ConfirmByPin, contact_info: options[:pre_auth_state], pin: pin_params.pin) - # lms students do not receive passwords so the account needs to be created now - if options[:pre_auth_state].signed_student? - run(SignupExternalStudent, pre_auth_state: options[:pre_auth_state], already_verified: true) - options[:session].sign_in!(outputs.user) - end - end - -end diff --git a/app/routines/destroy_when_association_empty.rb b/app/routines/destroy_when_association_empty.rb deleted file mode 100644 index 6ea014532..000000000 --- a/app/routines/destroy_when_association_empty.rb +++ /dev/null @@ -1,13 +0,0 @@ -class DestroyWhenAssociationEmpty - - lev_routine - - protected - - def exec(record, association) - return if record.nil? - relations = record.send(association) - record.destroy if relations.empty? - end - -end \ No newline at end of file diff --git a/app/routines/update_user_lead_info.rb b/app/routines/update_user_lead_info.rb deleted file mode 100644 index b0f4e7b33..000000000 --- a/app/routines/update_user_lead_info.rb +++ /dev/null @@ -1,75 +0,0 @@ -class UpdateUserLeadInfo - - def self.call - new.call - end - def call - # TODO: we do want to limit this, but we need to update all the leads and schedule this first - # we are only using this to check users created in the last month - # start_date = Time.zone.now - 1.day - # end_date = Time.zone.now - 30.day - # for the query below when this is re-added - # .where("created_at <= ? AND created_at >= ?", start_date, end_date) - - users = User.where(salesforce_contact_id: nil) - .where.not(salesforce_lead_id: nil, role: :student, faculty_status: :rejected_faculty) - - leads = OpenStax::Salesforce::Remote::Lead.select(:id, :accounts_uuid, :verification_status) - .where(accounts_uuid: users.map(&:uuid)) - .to_a - .index_by(&:accounts_uuid) - - users.map do |user| - lead = leads[user.uuid] - - unless lead.nil? - previous_lead_id = user.salesforce_lead_id - user.salesforce_lead_id = lead.id # it might change in SF lead merging - - if lead.id != previous_lead_id - SecurityLog.create!( - user: user, - event_type: :user_lead_id_updated_from_salesforce, - event_data: { previous_lead_id: previous_lead_id, new_lead_id: lead.id } - ) - end - - old_fv_status = user.faculty_status - user.faculty_status = case lead.verification_status - when "confirmed_faculty" - :confirmed_faculty - when "pending_faculty" - :pending_faculty - when "rejected_faculty" - :rejected_faculty - when "rejected_by_sheerid" - :rejected_by_sheerid - when "incomplete_signup" - :incomplete_signup - when "no_faculty_info" - :no_faculty_info - when NilClass - :no_faculty_info - else - Sentry.capture_message("Unknown faculty_verified field: '#{ - lead.verification_status}'' on lead #{lead.id}") - end - - if user.faculty_status_changed? - SecurityLog.create!( - user: user, - event_type: :salesforce_updated_faculty_status, - event_data: { - user_id: user.id, - salesforce_lead_id: lead.id, - old_status: old_fv_status, - new_status: user.faculty_status - } - ) - end - - user.save if user.changed? - end - end - end -end diff --git a/db/migrate/20191204193412_drop_openstax_salesforce_users.openstax_salesforce.rb b/db/migrate/20191204193412_drop_openstax_salesforce_users.openstax_salesforce.rb deleted file mode 100644 index 4197a83cc..000000000 --- a/db/migrate/20191204193412_drop_openstax_salesforce_users.openstax_salesforce.rb +++ /dev/null @@ -1,15 +0,0 @@ -# This migration comes from openstax_salesforce (originally 1) -# TODO: Remove after all servers have been migrated -class DropOpenStaxSalesforceUsers < ActiveRecord::Migration[4.2] - def change - drop_table :openstax_salesforce_users do |t| - t.string :name - t.string :uid, null: false - t.string :oauth_token, null: false - t.string :refresh_token, null: false - t.string :instance_url, null: false - - t.timestamps null: false - end - end -end diff --git a/lib/tasks/accounts/create_leads_for_instructors_not_sent_to_sf.rake b/lib/tasks/accounts/create_leads_for_instructors_not_sent_to_sf.rake index ac1a7eed9..7b220e47a 100644 --- a/lib/tasks/accounts/create_leads_for_instructors_not_sent_to_sf.rake +++ b/lib/tasks/accounts/create_leads_for_instructors_not_sent_to_sf.rake @@ -21,7 +21,6 @@ namespace :accounts do if lead.nil? Newflow::CreateOrUpdateSalesforceLead.call(user: user) else - # set the lead id, this will update their status in UpdateUserLeadInfo user.salesforce_lead_id = lead.id user.save end