def format_data(user, node_ids):
    items = []

    for node_id in node_ids:
        node = Node.load(node_id)
        assert node, '{} is not a valid Node.'.format(node_id)

        can_read = node.has_permission(user, 'read')
        can_read_children = node.has_permission_on_children(user, 'read')

        if not can_read and not can_read_children:
            continue

        children = []
        # List project/node if user has at least 'read' permissions (contributor or admin viewer) or if
        # user is contributor on a component of the project/node

        if can_read:
            node_sub_available = list(constants.NODE_SUBSCRIPTIONS_AVAILABLE.keys())
            subscriptions = [subscription for subscription in get_all_node_subscriptions(user, node)
                             if getattr(subscription, 'event_name') in node_sub_available]
            for subscription in subscriptions:
                index = node_sub_available.index(getattr(subscription, 'event_name'))
                children.append(serialize_event(user, subscription=subscription,
                                                node=node, event_description=node_sub_available.pop(index)))
            for node_sub in node_sub_available:
                    children.append(serialize_event(user, node=node, event_description=node_sub))
            children.sort(key=lambda s: s['event']['title'])

        children.extend(format_data(
            user,
            [
                n._id
                for n in node.nodes
                if n.primary and
                not n.is_deleted
            ]
        ))

        item = {
            'node': {
                'id': node_id,
                'url': node.url if can_read else '',
                'title': node.title if can_read else 'Private Project',
            },
            'children': children,
            'kind': 'folder' if not node.node__parent or not node.parent_node.has_permission(user, 'read') else 'node',
            'nodeType': node.project_or_component,
            'category': node.category,
            'permissions': {
                'view': can_read,
            },
        }

        items.append(item)

    return items
Format subscriptions data for project settings page
dataset/ETHPy150Open CenterForOpenScience/osf.io/website/notifications/utils.py/format_data