'Block requests based on embargo rules.
This will perform the following checks:
1) If the user\'s IP address is blacklisted, block.
2) If the user\'s IP address is whitelisted, allow.
3) If the user\'s country (inferred from their IP address) is blocked for
a courseware page, block.
4) If the user\'s country (retrieved from the user\'s profile) is blocked
for a courseware page, block.
5) Allow access.'

def process_request(self, request):

    for pattern in self.ALLOW_URL_PATTERNS:
        if (pattern.match(request.path) is not None):
            return None
    ip_address = get_ip(request)
    ip_filter = IPFilter.current()
    if (ip_filter.enabled and (ip_address in ip_filter.blacklist_ips)):
        log.info(u'User    %s    was    blocked    from    accessing    %s    because    IP    address    %s    is    blacklisted.', request.user.id, request.path, ip_address)
        ip_blacklist_url = reverse('embargo:blocked_message', kwargs={'access_point': 'courseware', 'message_key': 'embargo'})
        return redirect(ip_blacklist_url)
    elif (ip_filter.enabled and (ip_address in ip_filter.whitelist_ips)):
        log.info(u'User    %s    was    allowed    access    to    %s    because    IP    address    %s    is    whitelisted.', request.user.id, request.path, ip_address)
        return None
    else:
        return self.country_access_rules(request.user, ip_address, request.path)
