Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserSeeder
- PASSWORD = 'Fri3nd0!'
- def puts_indent(indent, str)
- puts((' ' * indent) + str)
- end
- def add_license(student)
- contract = student.institution.institution_contracts.first
- License.where(
- user_id: student.id,
- institution_contract_id: contract.id,
- first_activation_date: contract.first_activation_date
- ).first_or_create!.activate!
- end
- def tenant_content_packages(tenant)
- {
- 'richardson' => [1651, 1953, 1273, 1456, 1455],
- 'cliffsnotes' => [1197, 1141, 1140, 1142, 1133],
- 'ppagu' => [743],
- 'eatright' => [944],
- 'act' => [1099],
- 'naviance' => [1183, 976, 855, 879, 923],
- 'sasb' => [815],
- 'ins' => [1033],
- 'hrci' => [1051, 1624, 1623, 1403, 744],
- 'hrcitests' => [938, 934, 937, 1225, 933],
- 'benchprep' => [1196, 1511],
- 'ocl' => [1506, 1378, 1381, 1619, 1373],
- 'cfainstitute' => [1357, 1358, 1359, 1964, 1962],
- 'gmac' => [1296, 1605, 1618],
- 'comptia' => [1458, 1228, 1305, 1532, 1759],
- 'actworkkeys' => [1336, 1413, 1412, 1451, 1452],
- 'ism' => [1579, 1578, 1526],
- 'aamc' => [1692, 1657, 1658, 1625, 1663],
- 'mhprofessional' => [1340, 1321, 1337, 1339, 1335],
- 'becker' => [1440],
- 'petersons' => [1836, 1824, 1763, 1853, 1832],
- 'aia' => [1991, 2028],
- 'nrp' => [1598, 1599, 1600, 1601],
- 'ascm' => [1782],
- 'hpe' => [1652, 1994, 1995, 1998],
- 'aba' => [1997],
- 'ncbe' => [2094, 2064, 2063, 2057, 2058],
- 'dalton' => [2069, 2079],
- 'abms' => [3157]
- }[tenant.slug]
- end
- def add_enrollments(student)
- tenant_content_packages(student.tenant).each do |course_id|
- Enrollment.where(
- user_id: student.id,
- content_package_id: course_id,
- license: student.licenses.active.last
- ).first_or_create!.activate!
- end
- end
- def add_student(institution, group, number)
- description = [
- 'Good Student',
- 'Bad Student',
- 'Random Student',
- 'Logged-in Student',
- 'Non-logged-in Student'
- ][number - 1]
- group_code = "+grp#{group.name.match(/(\d)/).captures.first}" if group
- institution_code = "+inst#{institution.name.match(/(\d)/).captures.first}"
- district_code = "+dist#{institution.district.name.match(/(\d)/).captures.first}"
- student = User.where(
- name: "Student #{number}: #{description}",
- tenant_id: institution.tenant.id,
- institution_id: institution.id,
- district_id: institution.district.id,
- email: "qa+b#{institution.tenant.slug}+stu#{number}#{district_code}#{institution_code}#{group_code}@benchprep.com"
- ).first_or_initialize
- student.password = PASSWORD
- student.save!
- add_license(student)
- add_enrollments(student)
- group.join_as(student.id, UserGroup::MemberType::Student) if group
- puts_indent (group ? 6 : 3), "- #{student.name} (#{student.email}) [#{student.id}]"
- end
- def add_instructor(institution, instructor_number)
- instructor = User.where(
- name: "QA #{institution.tenant.name} Instructor #{instructor_number}",
- tenant_id: institution.tenant.id,
- institution_id: institution.id,
- district_id: institution.district.id,
- email: "qa+b#{institution.tenant.slug}+instr#{instructor_number}@benchprep.com"
- ).first_or_initialize
- instructor.password = PASSWORD
- instructor.save!
- puts_indent 3, "- #{instructor.name} [#{instructor.id}]"
- instructor
- end
- def add_group(institution, instructor, number)
- group = Group.where(
- name: "Group #{number}",
- tenant_id: institution.tenant.id,
- institution_id: institution.id
- ).first_or_create!
- group.join_as(instructor.id, UserGroup::MemberType::Instructor)
- puts_indent 4, "- #{group.name} [#{group.id}]"
- (1..5).each do |student_number|
- add_student(institution, group, student_number)
- end
- end
- def add_institution_contract(institution)
- start_date = Date.parse('2018-01-01')
- end_date = start_date + 100.years
- contract = InstitutionContract.where(
- institution_id: institution.id,
- contract_type: 'limited_seat',
- start_date: start_date,
- first_activation_date: start_date,
- last_activation_date: end_date,
- end_date: end_date,
- admin_access_expiration_date: end_date,
- name: "#{institution.name} Contract",
- max_loaded_count: 1000,
- ).first_or_initialize
- contract.content_package_ids = tenant_content_packages(institution.tenant)
- contract.save!
- end
- def add_institution_supervisor(institution, institution_number)
- supervisor = User.where(
- name: "#{institution.name} Supervisor",
- tenant_id: institution.tenant.id,
- institution_id: institution.id,
- email: "qa+b#{institution.tenant.slug}+inst+sprvsr#{institution_number}@benchprep.com"
- ).first_or_initialize
- supervisor.password = PASSWORD
- supervisor.save!
- supervisor.add_role(:institution_supervisor, full_access: true)
- puts_indent 3, "- #{supervisor.name} [#{supervisor.id}]"
- end
- def add_institution(district, number)
- institution = Institution.where(
- name: "QA #{district.tenant.name} Institution #{number}",
- tenant_id: district.tenant.id,
- district_id: district.id
- ).first_or_create!
- add_institution_contract(institution)
- puts_indent 2, "- #{institution.name} [#{institution.id}]"
- instructor = add_instructor(institution, number)
- add_institution_supervisor(institution, number)
- (1..2).each do |group_number|
- add_group(institution, instructor, group_number)
- end
- (1..5).each do |student_number|
- add_student(institution, nil, student_number)
- end
- institution.update_counters
- end
- def add_district_supervisor(district, district_number)
- supervisor = User.where(
- name: "#{district.name} Supervisor",
- tenant_id: district.tenant.id,
- district_id: district.id,
- email: "qa+b#{district.tenant.slug}+dst+sprvsr#{district_number}@benchprep.com"
- ).first_or_initialize
- supervisor.password = PASSWORD
- supervisor.save!
- supervisor.add_role(:district_supervisor, full_access: true)
- puts_indent 2, "- #{supervisor.name} [#{supervisor.id}]"
- end
- def add_district(tenant, district_number)
- district = District.where(
- name: "QA #{tenant.name} District #{district_number}",
- tenant_id: tenant.id
- ).first_or_create!
- puts_indent 1, "- #{district.name} [#{district.id}]"
- add_district_supervisor(district, district_number)
- (1..2).each do |institution_number|
- add_institution(district, (district_number - 1) * 2 + institution_number)
- end
- district
- end
- def add_tenant_data(tenant)
- puts_indent 0, "- #{tenant.name}"
- (1..2).map do |district_number|
- add_district(tenant, district_number)
- end
- end
- end
- tenants = %w[
- richardson
- cliffsnotes
- ppagu
- eatright
- act
- naviance
- sasb
- ins
- hrci
- hrcitests
- benchprep
- ocl
- cfainstitute
- gmac
- comptia
- actworkkeys
- ism
- aamc
- mhprofessional
- becker
- petersons
- aia
- nrp
- ascm
- hpe
- aba
- ncbe
- dalton
- abms
- ]
- seeder = UserSeeder.new
- ActiveRecord::Base.transaction do
- tenants.each do |tenant|
- seeder.add_tenant_data(Tenant.find_by_slug(tenant))
- end
- end
Add Comment
Please, Sign In to add comment