Beispiel #1
0
 def get_leader_teams(self, empty):
     """ Gets all of the teams you are leader of """
     user_email = get_user_email()
     response = Teams()
     query = RoseboticsTeam.query(RoseboticsTeam.leader == user_email)
     response.teams = [to_team_from_rosebotics(team) for team in query]
     return response
Beispiel #2
0
 def get_leader_teams(self, empty):
     """ Gets all of the teams you are leader of """
     user_email = get_user_email()
     response = Teams()
     query = RoseboticsTeam.query(RoseboticsTeam.leader == user_email)
     response.teams = [to_team_from_rosebotics(team) for team in query]
     return response
Beispiel #3
0
 def get_teams(self, empty):
     """ Gets the teams that you are a member or leader of """
     user_email = get_user_email()
     response = Teams()
     query = RoseboticsTeamMember.query(RoseboticsTeamMember.email == user_email)
     teams = [m.key.parent().get() for m in query if m.visibility != TeamVisibility.NOT_CHOSEN]
     query = RoseboticsTeam.query(RoseboticsTeam.leader == user_email)
     teams += [team for team in query]
     teams = remove_model_duplicates(teams)
     response.teams = [to_team_from_rosebotics(team_key, get_members=False) for team_key in teams]
     return response
Beispiel #4
0
 def get_teams(self, empty):
     """ Gets the teams that you are a member or leader of """
     user_email = get_user_email()
     response = Teams()
     query = RoseboticsTeamMember.query(
         RoseboticsTeamMember.email == user_email)
     teams = [
         m.key.parent().get() for m in query
         if m.visibility != TeamVisibility.NOT_CHOSEN
     ]
     query = RoseboticsTeam.query(RoseboticsTeam.leader == user_email)
     teams += [team for team in query]
     teams = remove_model_duplicates(teams)
     response.teams = [
         to_team_from_rosebotics(team_key, get_members=False)
         for team_key in teams
     ]
     return response
Beispiel #5
0
 def insert_team(self, team):
     """ Creates or updates a team that you own """
     user_email = get_user_email()
     if team.team_key:
         old_team = team.team_key.get()
     else:
         old_team = None
     if old_team is not None:
         old_team.name = team.name
         old_team.courses = team.courses
         old_team.put()
         old_members = RoseboticsTeamMember.query(ancestor=team.team_key)
         new_emails = []
         old_emails = [member.email for member in old_members]
         # if new email is NOT in old_members: add new email
         for member in team.members:
             if "@rose-hulman.edu" in member.email:
                 username = member.email.split("@")[0]
                 student = RoseboticsStudent.query(
                     RoseboticsStudent.username == username).get()
                 if student is not None:
                     member.email = student.key.string_id()
                 else:
                     send_rose_invite_email(member.email)
             new_emails.append(member.email)
             if member.email not in old_emails:
                 member_key = get_member_key(team.team_key, member.email)
                 new_member = RoseboticsTeamMember(key=member_key)
                 new_member.email = member.email
                 if new_member.email == user_email:
                     new_member.visibility = TeamVisibility.ALL_MEMBERS
                 elif is_admin_user(
                         user_email
                 ) and "@rose-hulman.edu" not in new_member.email:
                     new_member.visibility = TeamVisibility.TEAM_LEADER
                 else:
                     send_invite_email(member.email)
                 new_member.put()
         # if old username is NOT in new_members remove old member
         for old_member in old_members:
             if old_member.email not in new_emails:
                 old_member.key.delete()
     else:
         new_team = RoseboticsTeam(leader=user_email,
                                   name=team.name,
                                   courses=team.courses)
         team.team_key = new_team.put()
         emails = [member.email for member in team.members]
         for email in emails:
             student_email = email
             if "@rose-hulman.edu" in student_email:
                 username = student_email.split("@")[0]
                 student = RoseboticsStudent.query(
                     RoseboticsStudent.username == username).get()
                 if student is not None:
                     student_email = student.key.string_id()
                 else:
                     send_rose_invite_email(student_email)
             member_key = get_member_key(team.team_key, student_email)
             new_member = RoseboticsTeamMember(key=member_key)
             new_member.email = student_email
             if new_member.email == user_email:
                 new_member.visibility = TeamVisibility.ALL_MEMBERS
             elif is_admin_user(
                     user_email
             ) and "@rose-hulman.edu" not in student_email:
                 new_member.visibility = TeamVisibility.TEAM_LEADER
             else:
                 send_invite_email(email)
             new_member.put()
     return team
Beispiel #6
0
 def insert_team(self, team):
     """ Creates or updates a team that you own """
     user_email = get_user_email()
     if team.team_key:
         old_team = team.team_key.get()
     else:
         old_team = None
     if old_team is not None:
         old_team.name = team.name
         old_team.courses = team.courses
         old_team.put()
         old_members = RoseboticsTeamMember.query(ancestor=team.team_key)
         new_emails = []
         old_emails = [member.email for member in old_members]
         # if new email is NOT in old_members: add new email
         for member in team.members:
             if "@rose-hulman.edu" in member.email:
                 username = member.email.split("@")[0]
                 student = RoseboticsStudent.query(RoseboticsStudent.username == username).get()
                 if student is not None:
                     member.email = student.key.string_id()
                 else:
                     send_rose_invite_email(member.email)
             new_emails.append(member.email)
             if member.email not in old_emails:
                 member_key = get_member_key(team.team_key, member.email)
                 new_member = RoseboticsTeamMember(key=member_key)
                 new_member.email = member.email
                 if new_member.email == user_email:
                     new_member.visibility = TeamVisibility.ALL_MEMBERS
                 elif is_admin_user(user_email) and "@rose-hulman.edu" not in new_member.email:
                     new_member.visibility = TeamVisibility.TEAM_LEADER
                 else:
                     send_invite_email(member.email)
                 new_member.put()
         # if old username is NOT in new_members remove old member
         for old_member in old_members:
             if old_member.email not in new_emails:
                 old_member.key.delete()
     else:
         new_team = RoseboticsTeam(leader=user_email, name=team.name, courses=team.courses)
         team.team_key = new_team.put()
         emails = [member.email for member in team.members]
         for email in emails:
             student_email = email
             if "@rose-hulman.edu" in student_email:
                 username = student_email.split("@")[0]
                 student = RoseboticsStudent.query(RoseboticsStudent.username == username).get()
                 if student is not None:
                     student_email = student.key.string_id()
                 else:
                     send_rose_invite_email(student_email)
             member_key = get_member_key(team.team_key, student_email)
             new_member = RoseboticsTeamMember(key=member_key)
             new_member.email = student_email
             if new_member.email == user_email:
                 new_member.visibility = TeamVisibility.ALL_MEMBERS
             elif is_admin_user(user_email) and "@rose-hulman.edu" not in student_email:
                 new_member.visibility = TeamVisibility.TEAM_LEADER
             else:
                 send_invite_email(email)
             new_member.put()
     return team