def decline_join_request(team_id, token): data = get_json_from_request() if 'reason' not in data or not data['reason']: abort('Must provide reason for decline') try: team = team_business.get_team(team_id) except NotFoundError as e: return not_found(e.message) except UnauthorisedError as e: return forbidden(e.message) join_request = team_business.get_join_request(token) if not join_request or int(join_request.data['team_id']) != team_id: return not_found( 'The token is invalid, or this request has already been declined or accepted' ) if ('user_id' in join_request.data and (team_member_service.get_team_members_by_user_id( team_id, [int(join_request.data['user_id'])]) or team_member_service.get_team_leads_by_user_id( team_id, [int(join_request.data['user_id'])]))): abort('This user is already a member of the team') team_business.decline_join_request(join_request, data['reason'], team_id) return jsonify(success=True)
def get_team(team_id): team = None try: team = team_business.get_team(team_id) except NotFoundError as e: return not_found(e.message) except UnauthorisedError as e: return forbidden(e.message) return jsonify(team)
def get_join_request(team_id, token): try: team = team_business.get_team(team_id) except NotFoundError as e: return not_found(e.message) except UnauthorisedError as e: return forbidden(e.message) join_request = team_business.get_join_request(token) if not join_request or int(join_request.data['team_id']) != team_id: return not_found( 'The token is invalid, or this request has already been declined or accepted' ) return jsonify(join_request=join_request)
def get_team(team_id): team = team_business.get_team(team_id, True) briefs = team_business.get_team_briefs(team_id) return jsonify(team=team, briefs=briefs)