def check_permission(request, permission):
    """
    Checks whether the current request has access to the given permission.
    If the ``permission`` argument is ``None``, and the request is of a logged in user, we return ``True``.

    :param request HttpRequest: The current request
    :param permission str: The permission as a string of '<app name>.<permission codename>'.
    :return bool: True if the request has access to the given permission.
    """
    if not request.user.is_authenticated():
        return False
    if permission is None:
        return True
    return request.user.has_perm(permission)