One liners - compsy/u-can-act GitHub Wiki
Welcome to the vsv wiki!
Create test user on staging?
stud = Student.create(first_name: 'Name',
last_name: 'Lastname',
mobile_phone: 'phonenumber')
prot_sub = stud.protocol_subscriptions.create(
protocol: Protocol.find_by_name('pilot - studenten 2x per week'),
state: ProtocolSubscription::ACTIVE_STATE,
start_date: Time.zone.now.beginning_of_week
)
# second because we want thursday questionnaire
responseobj = prot_sub.responses.second
prot_sub.responses.select{|x| x.id != responseobj.id}.each{|x| x.destroy!}
responseobj.update_attributes!(
open_from: 4.weeks.from_now.in_time_zone,
invited_state: Response::SENT_STATE)
responseobj.initialize_invitation_token!
responseobj.invitation_token.token
Change mentor of a user (Mentor has to exist)
def change_students(mentor_nr, student_nrs)
mentor_pid = Person.find_by_mobile_phone(mentor_nr)&.id
if mentor_pid.blank?
puts "ERROR: Mentor pid is blank for mentor: #{mentor_nr}"
return
end
student_nrs.each do |student_nr|
student = Person.find_by_mobile_phone(student_nr)
if student.blank?
puts "ERROR: Student is blank for phone number: #{student_nr}"
next
end
if student.protocol_subscriptions.count != 1
puts "ERROR: Not 1 protocol subscription for student: #{student_nr}"
next
end
protsub = ProtocolSubscription.where(filling_out_for_id: student.id).where.not(person_id: student.id)
if protsub.count != 1
puts "ERROR: protsub count is not 1 for filling out for #{student_nr}"
next
end
protsub = protsub.first
if protsub.person_id == mentor_pid
puts "WARNING: person id for student #{student_nr} protsub will not change"
end
protsub.update_attributes(person_id: mentor_pid)
end
end
change_students('0612345678',%w(061244444444 062493732 0629348732))
Create mentor manually (for transferring to this new mentor which was created without students so not through the import)
q = Person.create!(first_name: 'Haha', last_name: 'Hoho', gender: 'female', mobile_phone: '0623432433', role_id: 5)
ProtocolSubscription.create!(person: q, protocol_id: 7, state: 'active', start_date: Time.zone.parse("19-2-2018 0:00"), end_date: Time.zone.parse("9-7-2018 0:00"))
Resetting the data base
Person.destroy_all;nil
puts "These should all be zero: #{Person.count} #{AuthUser.count} #{Response.count} #{ResponseContent.count} #{ProtocolSubscription.count} #{InvitationSet.count}"
RedisService.del(RedisService.keys("distribution_*"))
RedisService.keys("distribution_*")
Questionnaire.all.each(&:recalculate_scores!);nil