def post(self):
        args = self.invite_parser.parse_args()
        team_unid = args['team_unid']
        invitee_unid = args['invitee_unid']
        invitee_email = args['invitee_email']

        if not invitee_unid and not invitee_email:
            return {'status': 'false', 'message': 'Must invite by email or unid'}, 400
        
        if invitee_unid:
            user = get_user(invitee_unid)
        else:
            user = User.fetch_user_by_email(invitee_email)
            if not user:
                return {'status': 'false', 'message': 'No user found'}, 404

        team = get_team(team_unid)

        user_team_exist = UserTeam.get_user_team_by_user_and_team(invitee_unid, team.unid)

        if user_team_exist:
            return {'status': 'false', 'message': 'User already on that team'}, 400

        invitation = TeamInvite(team_unid, invitee_unid)

        return {'status': 'true', 'message': 'Invitation sent successfully', 'invitation_unid': invitation.unid}, 201
    def test_get_user_team(self):
        rand_string1 = datetime.datetime.now()
        rand_string2 = datetime.datetime.now()

        user_team = UserTeam(rand_string1, rand_string2, 1)

        found_user_team = UserTeam.get_user_team_by_user_and_team(rand_string1, rand_string2)
        
        self.assertIsNotNone(found_user_team)
        self.assertEqual(user_team.unid, found_user_team.unid)
Example #3
0
    def get(self, user_unid):
        user = get_user(user_unid)
        user_serialized = user.serialize()
        user_team = UserTeam.get_team_by_user(user_unid)
        
        user_serialized['team'] = user_team.team_unid if user_team else None

        return {
            'user': user_serialized
        }
    def get(self, team_unid, user_unid):
        team = get_team(team_unid)

        user = get_user(user_unid)

        user_team = UserTeam.get_user_team_by_user_and_team(user_unid, team_unid)
    
        return {
            'status': 'true',
            'user_type': user_team.member_mappings.get(user_team.member_type, 'Participant'),
        }
Example #5
0
def get_users_from_team(team_unid):
    members = UserTeam.get_users_teams_by_team(team_unid)
    users = [User.fetch_user_by_unid(member.user_unid) for member in members]
    users = [u for u in users if u is not None]
    serialized = []
    for member, user in zip(members, users):
        temp = user.serialize()
        temp['team_unid'] = member.team_unid
        serialized.append(temp)
    
    return serialized
    def delete(self, team_unid, user_unid):
        team = get_team(team_unid)

        user = get_user(user_unid)

        user_team = UserTeam.get_user_team_by_user_and_team(user_unid, team_unid)

        if not user_team:
            return {'status': 'false', 'message': 'The given user is not on that team'}, 400
        
        is_captain = user_team.member_type == 2
        user_team.delete(soft=False)
        new_captain = None
        team.number_participants -= 1

        if is_captain:
            new_captain = UserTeam.get_oldest_team_member(team_unid)

        if new_captain:
            new_captain.member_type = 2
            team.team_captain = new_captain.unid

        return {}, 204
    def post(self, team_unid):
        args = self.create_parser.parse_args()
        user_unid = args['user_unid']
        member_type = args['member_type']

        team = get_team(team_unid)
        
        user = get_user(user_unid)

        user_team = UserTeam.add_user_to_team(user_unid, team_unid, member_type)
        if user_team.member_type == 2:
            team.team_captain = user_team.user_unid
        team.number_participants += 1

        return {'status': 'true', 'user_team_unid': user_team.unid, 'team': team.serialize()}
Example #8
0
    def post(self):
        args = self.parser.parse_args()
        email = args['email']
        password = args['password']

        if email is None or len(email) < 3:
            return {'status': 'false', 'message': 'Invalid email'}, 403

        authed = User.authenticate(email, password)

        if authed:
            user = User.fetch_user_by_email(email)
            user_team = UserTeam.get_team_by_user(user.unid)
            team_unid = user_team.team_unid if user_team else None
            token = Token(user.unid)
            return {'status': 'true', 'token': token.token, 'user_unid': user.unid, 'team_unid':team_unid}, 200
        else:
            return {'status': 'false', 'message': 'Incorrect login credentials'}, 403
Example #9
0
    def get(self):
        args = self.get_users_parser.parse_args()
        email = args['email']

        if email:
            users = UserModel.get_list(email=email.lower())
        else:
            users = UserModel.get_all_users()

        user_teams = [UserTeam.get_team_by_user(user.unid) for user in users]
        serialized = []
        for member, user in zip(user_teams, users):
            temp = user.serialize()
            temp['team_unid'] = member.team_unid if member else None
            serialized.append(temp)

        return {
            'users': serialized
        }
Example #10
0
    def post(self):
        args = self.create_team_parser.parse_args()
        name = args['team_name']
        max_members = args['max_participants']
        captain = args['team_captain']
        num_members = args['number_participants']
        route = args['route_id']
        needs_accessibility = args.get('requires_accessibility', 0)
        public = args.get('public_team', 0)
        public = 0 if public == "0" or public == 0 or public == None else 1

        captain_user = User.fetch_user_by_unid(captain)
        
        if captain_user is None:
            return {'status': 'false', 'message': 'Team captain given does not exist'}, 400

        team = TeamModel.create_team(name, captain, max_members, num_members, public)

        user_team = UserTeam.add_user_to_team(captain, team.unid, 2)

        return {'status': 'true', 'team_id': team.unid, 'user_team': user_team.unid}, 201