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 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'),
        }
示例#3
0
    def post(self, team_unid):
        args = self.parser.parse_args()
        team = get_team(team_unid)
        route_unid = args['route_unid']
        route = get_route(route_unid)

        found = RouteTeam.get_team_route(team_unid)
        if found:
            found.delete(soft=False)

        route_team = RouteTeam(route_unid, team_unid)

        return {'status': 'true', 'route_team_unid': route_team.unid}, 201
    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()}
    def get(self):
        args = self.get_invites_parser.parse_args()
        user_unid = args['user_unid']
        team_unid = args['team_unid']
        
        if team_unid:
            team = get_team(team_unid)
            result = TeamInvite.get_by_team_unid(team_unid)
        else:
            result = TeamInvite.get_invites()

        if user_unid:
            user = get_user(user_unid)
            team_invites = result.filter_by(invite_user_unid=user_unid)
        else:
            team_invites = result
        
        invites_serialized = [invite.serialize() for invite in team_invites]
        return {
            'invites': invites_serialized
        }, 200
    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 get(self, team_unid):
        team = get_team(team_unid)

        return {'users': get_users_from_team(team_unid)}
示例#8
0
 def get(self, team_unid):
     team = get_team(team_unid)
     
     route = RouteTeam.get_team_route(team_unid)
     return {'status': 'true', 'route': route.serialize() if route else None}