def get(self): user_data = UserData.current() user_data_override = self.request_user_data("coach_email") if user_util.is_current_user_developer() and user_data_override: user_data = user_data_override invalid_student = self.request_bool("invalid_student", default=False) coach_requests = [req.student_requested_identifier for req in CoachRequest.get_for_coach(user_data) if req.student_requested_data] student_lists_models = StudentList.get_for_coach(user_data.key()) student_lists_list = [] for student_list in student_lists_models: student_lists_list.append({ 'key': str(student_list.key()), 'name': student_list.name, }) student_lists_dict = dict((g['key'], g) for g in student_lists_list) def student_to_dict(s): """Convert the UserData s to a dictionary for rendering.""" return { 'key': str(s.key()), 'email': s.email, 'username': s.username, # Note that child users don't have an email. 'identifier': s.username or s.email, 'nickname': s.nickname, 'profile_root': s.profile_root, 'can_modify_coaches': s.can_modify_coaches(), 'studentLists': [l for l in [student_lists_dict.get(str(list_id)) for list_id in s.student_lists] if l], } students_data = user_data.get_students_data() students = map(student_to_dict, students_data) students.sort(key=lambda s: s['nickname']) child_accounts = map(student_to_dict, user_data.get_child_users()) template_values = { 'students': students, 'child_accounts': child_accounts, 'child_account_keyset': set([c['key'] for c in child_accounts]), 'students_json': json.dumps(students), 'student_lists': student_lists_list, 'student_lists_json': json.dumps(student_lists_list), 'invalid_student': invalid_student, 'coach_requests': coach_requests, 'coach_requests_json': json.dumps(coach_requests), 'selected_nav_link': 'coach', 'email': user_data.email, } self.render_jinja2_template('viewstudentlists.html', template_values)
def test_clear_request_on_update_requests_with_no_email(self): bella = self.make_user('*****@*****.**') edward = self.make_user('*****@*****.**') CoachRequest.get_or_insert_for(edward, bella) coaches.update_requests(bella, []) requests_for_bella = CoachRequest.get_for_student(bella).fetch(1000) self.assertEqual(0, len(requests_for_bella)) requests_by_edward = CoachRequest.get_for_coach(edward).fetch(1000) self.assertEqual(0, len(requests_by_edward))
def test_clear_request_on_update_requests_with_no_email(self): bella = self.make_user('*****@*****.**') edward = self.make_user('*****@*****.**') CoachRequest.get_or_insert_for(edward, bella) coaches.update_requests(bella, []) requests_for_bella = CoachRequest.get_for_student(bella).fetch(1000) self.assertEqual(0, len(requests_for_bella)) requests_by_edward = CoachRequest.get_for_coach(edward).fetch(1000) self.assertEqual(0, len(requests_by_edward))
def test_noop_on_update_requests_with_email(self): bella = self.make_user('*****@*****.**') jacob = self.make_user('*****@*****.**') CoachRequest.get_or_insert_for(jacob, bella) coaches.update_requests(bella, [jacob.key_email]) requests_for_bella = CoachRequest.get_for_student(bella).fetch(1000) self.assertEqual(1, len(requests_for_bella)) requests_by_jacob = CoachRequest.get_for_coach(jacob).fetch(1000) self.assertEqual(1, len(requests_by_jacob))
def test_noop_on_update_requests_with_email(self): bella = self.make_user('*****@*****.**') jacob = self.make_user('*****@*****.**') CoachRequest.get_or_insert_for(jacob, bella) coaches.update_requests(bella, [jacob.key_email]) requests_for_bella = CoachRequest.get_for_student(bella).fetch(1000) self.assertEqual(1, len(requests_for_bella)) requests_by_jacob = CoachRequest.get_for_coach(jacob).fetch(1000) self.assertEqual(1, len(requests_by_jacob))
def test_requesting_by_username_doesnt_leak_email(self): bella = self.make_user('*****@*****.**') self.assertTrue(bella.claim_username('bella')) jacob = self.make_user('*****@*****.**') # Request is made using username. CoachRequest.get_or_insert_for(jacob, bella, 'bella') requests_for_bella = CoachRequest.get_for_student(bella).fetch(1000) self.assertEqual(1, len(requests_for_bella)) self.assertEqual(bella.username, requests_for_bella[0].student_requested_identifier) requests_by_jacob = CoachRequest.get_for_coach(jacob).fetch(1000) self.assertEqual(1, len(requests_by_jacob)) self.assertEqual(bella.username, requests_by_jacob[0].student_requested_identifier)
def get(self): user_data = UserData.current() user_data_override = self.request_user_data("coach_email") if user_util.is_current_user_developer() and user_data_override: user_data = user_data_override invalid_student = self.request_bool("invalid_student", default = False) coach_requests = [x.student_requested_data.email for x in CoachRequest.get_for_coach(user_data) if x.student_requested_data] student_lists_models = StudentList.get_for_coach(user_data.key()) student_lists_list = []; for student_list in student_lists_models: student_lists_list.append({ 'key': str(student_list.key()), 'name': student_list.name, }) student_lists_dict = dict((g['key'], g) for g in student_lists_list) students_data = user_data.get_students_data() students = map(lambda s: { 'key': str(s.key()), 'email': s.email, 'nickname': s.nickname, 'profile_root': s.profile_root, 'studentLists': [l for l in [student_lists_dict.get(str(list_id)) for list_id in s.student_lists] if l], }, students_data) students.sort(key=lambda s: s['nickname']) template_values = { 'students': students, 'students_json': json.dumps(students), 'student_lists': student_lists_list, 'student_lists_json': json.dumps(student_lists_list), 'invalid_student': invalid_student, 'coach_requests': coach_requests, 'coach_requests_json': json.dumps(coach_requests), 'selected_nav_link': 'coach', 'email': user_data.email, } self.render_jinja2_template('viewstudentlists.html', template_values)
def get(self): user_data = UserData.current() user_data_override = self.request_user_data("coach_email") if user_util.is_current_user_developer() and user_data_override: user_data = user_data_override invalid_student = self.request_bool("invalid_student", default=False) coach_requests = [ req.student_requested_identifier for req in CoachRequest.get_for_coach(user_data) if req.student_requested_data ] student_lists_models = StudentList.get_for_coach(user_data.key()) student_lists_list = [] for student_list in student_lists_models: student_lists_list.append({ 'key': str(student_list.key()), 'name': student_list.name, }) student_lists_dict = dict((g['key'], g) for g in student_lists_list) def student_to_dict(s): """Convert the UserData s to a dictionary for rendering.""" return { 'key': str(s.key()), 'email': s.email, 'username': s.username, # Note that child users don't have an email. 'identifier': s.username or s.email, 'nickname': s.nickname, 'profile_root': s.profile_root, 'can_modify_coaches': s.can_modify_coaches(), 'studentLists': [ l for l in [ student_lists_dict.get(str(list_id)) for list_id in s.student_lists ] if l ], } students_data = user_data.get_students_data() students = map(student_to_dict, students_data) students.sort(key=lambda s: s['nickname']) child_accounts = map(student_to_dict, user_data.get_child_users()) template_values = { 'students': students, 'child_accounts': child_accounts, 'child_account_keyset': set([c['key'] for c in child_accounts]), 'students_json': json.dumps(students), 'student_lists': student_lists_list, 'student_lists_json': json.dumps(student_lists_list), 'invalid_student': invalid_student, 'coach_requests': coach_requests, 'coach_requests_json': json.dumps(coach_requests), 'selected_nav_link': 'coach', 'email': user_data.email, } self.render_jinja2_template('viewstudentlists.html', template_values)