예제 #1
0
파일: log.py 프로젝트: Doris1989/osf.io
def _get_logs(node, count, auth, link=None, offset=0):
    """

    :param Node node:
    :param int count:
    :param auth:
    :return list: List of serialized logs,
            boolean: if there are more logs

    """
    logs = []
    has_more_logs = False
    for log in (x for idx, x in enumerate(reversed(node.logs))
                if idx >= offset):
        # A number of errors due to database inconsistency can arise here. The
        # log can be None; its `node__logged` back-ref can be empty, and the
        # 0th logged node can be None. Catch and log these errors and ignore
        # the offending logs.
        log_node = log.resolve_node(node)
        if log.can_view(node, auth):
            anonymous = has_anonymous_link(log_node, auth)
            if len(logs) < count:
                logs.append(serialize_log(log, anonymous))
            else:
                has_more_logs = True
                break
    return logs, has_more_logs
예제 #2
0
def _get_logs(node, count, auth, link=None, page=0):
    """

    :param Node node:
    :param int count:
    :param auth:
    :return list: List of serialized logs,
            boolean: if there are more logs

    """
    logs = []
    total = 0
    for log in reversed(node.logs):
        # A number of errors due to database inconsistency can arise here. The
        # log can be None; its `node__logged` back-ref can be empty, and the
        # 0th logged node can be None. Need to make sure that log is not None
        if log:
            log_node = log.resolve_node(node)
            if log.can_view(node, auth):
                total += 1
                anonymous = has_anonymous_link(log_node, auth)
                logs.append(serialize_log(log, anonymous))
        else:
            logger.warn('Log on node {} is None'.format(node._id))

    paginated_logs, pages = paginate(logs, total, page, count)

    return list(paginated_logs), total, pages
예제 #3
0
파일: log.py 프로젝트: AndrewSallans/osf.io
def _get_logs(node, count, auth, link=None, offset=0):
    """

    :param Node node:
    :param int count:
    :param auth:
    :return list: List of serialized logs,
            boolean: if there are more logs

    """
    logs = []
    has_more_logs = False
    for log in (x for idx, x in enumerate(reversed(node.logs)) if idx >= offset):
        # A number of errors due to database inconsistency can arise here. The
        # log can be None; its `node__logged` back-ref can be empty, and the
        # 0th logged node can be None. Catch and log these errors and ignore
        # the offending logs.
        log_node = log.resolve_node(node)
        if log.can_view(node, auth):
            anonymous = has_anonymous_link(log_node, auth)
            if len(logs) < count:
                logs.append(serialize_log(log, anonymous))
            else:
                has_more_logs = True
                break
    return logs, has_more_logs
예제 #4
0
파일: log.py 프로젝트: KerryKDiehl/osf.io
def _get_logs(node, count, auth, link=None, page=0):
    """

    :param Node node:
    :param int count:
    :param auth:
    :return list: List of serialized logs,
            boolean: if there are more logs

    """
    logs = []
    total = 0
    for log in reversed(node.logs):
        # A number of errors due to database inconsistency can arise here. The
        # log can be None; its `node__logged` back-ref can be empty, and the
        # 0th logged node can be None. Need to make sure that log is not None
        if log:
            log_node = log.resolve_node(node)
            if log.can_view(node, auth):
                total += 1
                anonymous = has_anonymous_link(log_node, auth)
                logs.append(serialize_log(log, anonymous))
        else:
            logger.warn('Log on node {} is None'.format(node._id))

    paginated_logs, pages = paginate(logs, total, page, count)

    return list(paginated_logs), total, pages
예제 #5
0
def get_log(auth, log_id):

    log = NodeLog.load(log_id)
    node_to_use = log.node

    if not node_to_use.can_view(auth):
        raise HTTPError(http.FORBIDDEN)

    return {'log': serialize_log(log)}
예제 #6
0
파일: log.py 프로젝트: erinmayhood/osf.io
def get_log(auth, log_id):

    log = NodeLog.load(log_id)
    node_to_use = log.node

    if not node_to_use.can_view(auth):
        raise HTTPError(http.FORBIDDEN)

    return {'log': serialize_log(log, auth=auth)}
예제 #7
0
파일: log.py 프로젝트: AndrewSallans/osf.io
def get_log(log_id):

    log = NodeLog.load(log_id)
    node_to_use = log.node

    auth = Auth(
        user=get_current_user(),
        api_key=get_api_key(),
        api_node=get_current_node(),
    )

    if not node_to_use.can_view(auth):
        raise HTTPError(http.FORBIDDEN)

    return {'log': serialize_log(log)}
예제 #8
0
파일: log.py 프로젝트: Doris1989/osf.io
def get_log(log_id):

    log = NodeLog.load(log_id)
    node_to_use = log.node

    auth = Auth(
        user=get_current_user(),
        api_key=get_api_key(),
        api_node=get_current_node(),
    )

    if not node_to_use.can_view(auth):
        raise HTTPError(http.FORBIDDEN)

    return {'log': serialize_log(log)}
예제 #9
0
    def test_serialize_log(self):
        node = NodeFactory(category="hypothesis")
        node.save()
        log = NodeLogFactory(params={"node": node._id}, node=node, original_node=node)
        d = serialize_log(log)
        assert_equal(d["action"], log.action)
        assert_equal(d["node"]["node_type"], "component")
        assert_equal(d["node"]["category"], "Hypothesis")

        assert_equal(d["node"]["url"], log.node.url)
        assert_equal(d["date"], framework_utils.iso8601format(log.date))
        assert_in("contributors", d)
        assert_equal(d["user"]["fullname"], log.user.fullname)
        assert_equal(d["user"]["url"], log.user.url)
        assert_equal(d["params"], log.params)
        assert_equal(d["node"]["title"], log.node.title)
예제 #10
0
    def test_serialize_log(self):
        node = NodeFactory(category='hypothesis')
        log = NodeLogFactory(params={'node': node._primary_key})
        node.logs.append(log)
        node.save()
        d = serialize_log(log)
        assert_equal(d['action'], log.action)
        assert_equal(d['node']['node_type'], 'component')
        assert_equal(d['node']['category'], 'Hypothesis')

        assert_equal(d['node']['url'], log.node.url)
        assert_equal(d['date'], framework_utils.iso8601format(log.date))
        assert_in('contributors', d)
        assert_equal(d['user']['fullname'], log.user.fullname)
        assert_equal(d['user']['url'], log.user.url)
        assert_equal(d['params'], log.params)
        assert_equal(d['node']['title'], log.node.title)
예제 #11
0
    def test_serialize_log(self):
        node = NodeFactory(category='hypothesis')
        log = NodeLogFactory(params={'node': node._primary_key})
        node.logs.append(log)
        node.save()
        d = serialize_log(log)
        assert_equal(d['action'], log.action)
        assert_equal(d['node']['node_type'], 'component')
        assert_equal(d['node']['category'], 'Hypothesis')

        assert_equal(d['node']['url'], log.node.url)
        assert_equal(d['date'], framework_utils.iso8601format(log.date))
        assert_in('contributors', d)
        assert_equal(d['user']['fullname'], log.user.fullname)
        assert_equal(d['user']['url'], log.user.url)
        assert_equal(d['params'], log.params)
        assert_equal(d['node']['title'], log.node.title)
예제 #12
0
파일: log.py 프로젝트: erinmayhood/osf.io
def _get_logs(node, count, auth, link=None, page=0):
    """

    :param Node node:
    :param int count:
    :param auth:
    :return list: List of serialized logs,
            boolean: if there are more logs

    """
    logs_set = node.get_aggregate_logs_queryset(auth)
    total = len(logs_set)
    start = page * count
    stop = start + count
    logs = [
        serialize_log(log, auth=auth, anonymous=has_anonymous_link(node, auth))
        for log in logs_set[start:stop]
    ]
    pages = math.ceil(total / float(count))
    return logs, total, pages
예제 #13
0
def _get_logs(node, count, auth, link=None, page=0):
    """

    :param Node node:
    :param int count:
    :param auth:
    :return list: List of serialized logs,
            boolean: if there are more logs

    """
    logs_set = node.get_aggregate_logs_queryset(auth)
    total = len(logs_set)
    start = page * count
    stop = start + count
    logs = [
        serialize_log(log, auth=auth, anonymous=has_anonymous_link(node, auth))
        for log in logs_set[start:stop]
    ]
    pages = math.ceil(total / float(count))
    return logs, total, pages