Beispiel #1
0
def update_file_guid_referent(self, node, event_type, payload, user=None):
    if event_type == 'addon_file_moved' or event_type == 'addon_file_renamed':
        source = payload['source']
        destination = payload['destination']
        source_node = Node.load(source['node']['_id'])
        destination_node = node
        file_guids = FileNode.resolve_class(source['provider'], FileNode.ANY).get_file_guids(
            materialized_path=source['materialized'] if source['provider'] != 'osfstorage' else source['path'],
            provider=source['provider'],
            node=source_node)

        if event_type == 'addon_file_renamed' and source['provider'] in settings.ADDONS_BASED_ON_IDS:
            return
        if event_type == 'addon_file_moved' and (source['provider'] == destination['provider'] and
                                                 source['provider'] in settings.ADDONS_BASED_ON_IDS) and source_node == destination_node:
            return

        for guid in file_guids:
            obj = Guid.load(guid)
            if source_node != destination_node and Comment.find(Q('root_target', 'eq', guid)).count() != 0:
                update_comment_node(guid, source_node, destination_node)

            if source['provider'] != destination['provider'] or source['provider'] != 'osfstorage':
                old_file = FileNode.load(obj.referent._id)
                obj.referent = create_new_file(obj, source, destination, destination_node)
                obj.save()
                if old_file and not TrashedFileNode.load(old_file._id):
                    old_file.delete()
Beispiel #2
0
def update_comment_root_target_file(self, node, event_type, payload, user=None):
    if event_type == 'addon_file_moved':
        source = payload['source']
        destination = payload['destination']
        source_node = Node.load(source['node']['_id'])
        destination_node = node

        if (source.get('provider') == destination.get('provider') == 'osfstorage') and source_node._id != destination_node._id:
            obj = FileNode.load(source.get('path').strip('/'))
            update_folder_contents([obj], source_node, destination_node)
Beispiel #3
0
def update_comment_root_target_file(self,
                                    node,
                                    event_type,
                                    payload,
                                    user=None):
    if event_type == 'addon_file_moved':
        source = payload['source']
        destination = payload['destination']
        source_node = Node.load(source['node']['_id'])
        destination_node = node

        if (source.get('provider') == destination.get('provider') ==
                'osfstorage') and source_node._id != destination_node._id:
            obj = FileNode.load(source.get('path').strip('/'))
            update_folder_contents([obj], source_node, destination_node)
def migrate_file_representation(bad_file):
    logger.info('Migrating file representation of File: {0}'.format(bad_file))
    view_url = bad_file['viewUrl'].rstrip('/')
    fid = view_url.split('/')[-1]
    fnode = FileNode.load(fid)
    if fnode is None:
        fnode = TrashedFileNode.load(fid)
    assert fnode is not None, 'Could not load FileNode or TrashedFileNode with id {}'.format(fid)
    data = {
        'data': {
            'kind': 'file',
            'name': bad_file['selectedFileName'],
            'path': fnode.path,
            'extra': {},
            'sha256': fnode.versions[-1].metadata['sha256']
        }
    }
    bad_file.update(data)
Beispiel #5
0
def update_comment_root_target_file(self, node, event_type, payload, user=None):
    if event_type == 'addon_file_moved':
        source = payload['source']
        destination = payload['destination']
        source_node = Node.load(source['node']['_id'])
        destination_node = node

        if (source.get('provider') == destination.get('provider') == 'osfstorage') and source_node._id != destination_node._id:
            old_file = FileNode.load(source.get('path').strip('/'))
            new_file = FileNode.resolve_class(destination.get('provider'), FileNode.FILE).get_or_create(destination_node, destination.get('path'))

            Comment.update(Q('root_target', 'eq', old_file._id), data={'node': destination_node})

            # update node record of commented files
            if old_file._id in source_node.commented_files:
                destination_node.commented_files[new_file._id] = source_node.commented_files[old_file._id]
                del source_node.commented_files[old_file._id]
                source_node.save()
                destination_node.save()
Beispiel #6
0
def update_file_guid_referent(self, node, event_type, payload, user=None):
    if event_type == 'addon_file_moved' or event_type == 'addon_file_renamed':
        source = payload['source']
        destination = payload['destination']
        source_node = Node.load(source['node']['_id'])
        destination_node = node
        file_guids = FileNode.resolve_class(
            source['provider'], FileNode.ANY).get_file_guids(
                materialized_path=source['materialized']
                if source['provider'] != 'osfstorage' else source['path'],
                provider=source['provider'],
                node=source_node)

        if event_type == 'addon_file_renamed' and source[
                'provider'] in settings.ADDONS_BASED_ON_IDS:
            return
        if event_type == 'addon_file_moved' and (
                source['provider'] == destination['provider']
                and source['provider'] in settings.ADDONS_BASED_ON_IDS
        ) and source_node == destination_node:
            return

        for guid in file_guids:
            obj = Guid.load(guid)
            if source_node != destination_node and Comment.find(
                    Q('root_target', 'eq', guid)).count() != 0:
                update_comment_node(guid, source_node, destination_node)

            if source['provider'] != destination['provider'] or source[
                    'provider'] != 'osfstorage':
                old_file = FileNode.load(obj.referent._id)
                obj.referent = create_new_file(obj, source, destination,
                                               destination_node)
                obj.save()
                if old_file and not TrashedFileNode.load(old_file._id):
                    old_file.delete()
Beispiel #7
0
def view_file(request, node_id, provider, file_id):
    file = FileNode.load(file_id)
    wb_url = file.generate_waterbutler_url()
    return redirect(wb_url)
Beispiel #8
0
def view_file(request, node_id, provider, file_id):
    file = FileNode.load(file_id)
    wb_url = file.generate_waterbutler_url()
    return redirect(wb_url)