Esempio n. 1
0
def osf_storage_get_metadata_hook(node_addon, payload, **kwargs):
    node = node_addon.owner
    path = payload.get('path', '')

    if path.endswith('/') or not path:
        file_tree = model.OsfStorageFileTree.find_by_path(path, node_addon)
        if file_tree is None:
            if path == '':
                return []
            raise HTTPError(httplib.NOT_FOUND)
        # TODO: Handle nested folders
        return [
            utils.serialize_metadata_hgrid(item, node)
            for item in list(file_tree.children)
            if not item.is_deleted
        ]
    else:
        file_record = model.OsfStorageFileRecord.find_by_path(path, node_addon)
        if not file_record:
            raise HTTPError(httplib.NOT_FOUND)

        if file_record.is_deleted:
            raise HTTPError(httplib.GONE)

        return utils.serialize_metadata_hgrid(file_record, node)
Esempio n. 2
0
def osf_storage_get_metadata_hook(node_addon, payload, **kwargs):
    node = node_addon.owner
    path = payload.get('path', '')

    if path.endswith('/') or not path:
        file_tree = model.OsfStorageFileTree.find_by_path(path, node_addon)
        if file_tree is None:
            if path == '':
                return []
            raise HTTPError(httplib.NOT_FOUND)
        # TODO: Handle nested folders
        return [
            utils.serialize_metadata_hgrid(item, node)
            for item in list(file_tree.children)
            if not item.is_deleted
        ]
    else:
        file_record = model.OsfStorageFileRecord.find_by_path(path, node_addon)
        if not file_record:
            raise HTTPError(httplib.NOT_FOUND)

        if file_record.is_deleted:
            raise HTTPError(httplib.GONE)

        return utils.serialize_metadata_hgrid(file_record, node)
Esempio n. 3
0
 def test_serialize_metadata_file(self):
     file_record = model.OsfStorageFileRecord(
         path='kind/of/<strong>magic.mp3',
         node_settings=self.project.get_addon('osfstorage'),
     )
     permissions = {'edit': False, 'view': True}
     serialized = utils.serialize_metadata_hgrid(
         file_record,
         self.project,
         permissions,
     )
     assert_equal(serialized['addon'], 'osfstorage')
     assert_equal(
         serialized['path'],
         markupsafe.escape('kind/of/<strong>magic.mp3'),
     )
     assert_equal(
         serialized['name'],
         markupsafe.escape('<strong>magic.mp3'),
     )
     assert_equal(serialized['ext'], '.mp3')
     assert_equal(serialized['kind'], 'item')
     assert_equal(
         serialized['urls'],
         utils.build_hgrid_urls(file_record, self.project),
     )
     assert_equal(serialized['permissions'], permissions)
Esempio n. 4
0
 def test_hgrid_contents(self):
     path = u'kind/of/magíc.mp3'
     model.OsfStorageFileRecord.get_or_create(
         path=path,
         node_settings=self.node_settings,
     )
     version = factories.FileVersionFactory()
     record = model.OsfStorageFileRecord.find_by_path(path, self.node_settings)
     record.versions.append(version)
     record.save()
     res = self.app.get(
         self.project.api_url_for(
             'osf_storage_hgrid_contents',
             path='kind/of',
         ),
         auth=self.project.creator.auth,
     )
     assert_equal(len(res.json), 1)
     assert_equal(
         res.json[0],
         utils.serialize_metadata_hgrid(
             record,
             self.project,
             {
                 'edit': True,
                 'view': True,
             }
         )
     )
Esempio n. 5
0
 def test_hgrid_contents(self):
     path = u'kind/of/magíc.mp3'
     model.OsfStorageFileRecord.get_or_create(
         path=path,
         node_settings=self.node_settings,
     )
     version = factories.FileVersionFactory()
     record = model.OsfStorageFileRecord.find_by_path(
         path, self.node_settings)
     record.versions.append(version)
     record.save()
     res = self.app.get(
         self.project.api_url_for(
             'osf_storage_hgrid_contents',
             path='kind/of',
         ),
         auth=self.project.creator.auth,
     )
     assert_equal(len(res.json), 1)
     assert_equal(
         res.json[0],
         utils.serialize_metadata_hgrid(record, self.project, {
             'edit': True,
             'view': True,
         }))
Esempio n. 6
0
 def test_serialize_metadata_folder(self):
     file_tree = model.OsfStorageFileTree(
         path='god/save/the/queen',
         node_settings=self.project.get_addon('osfstorage'),
     )
     serialized = utils.serialize_metadata_hgrid(
         file_tree,
         self.project,
     )
     assert_equal(serialized['path'], 'god/save/the/queen')
     assert_equal(serialized['name'], 'queen')
     assert_equal(serialized['ext'], '')
     assert_equal(serialized['kind'], 'folder')
Esempio n. 7
0
 def test_serialize_metadata_folder(self):
     file_tree = model.OsfStorageFileTree(
         path='god/save/the/queen',
         node_settings=self.project.get_addon('osfstorage'),
     )
     serialized = utils.serialize_metadata_hgrid(
         file_tree,
         self.project,
     )
     assert_equal(serialized['path'], 'god/save/the/queen')
     assert_equal(serialized['name'], 'queen')
     assert_equal(serialized['ext'], '')
     assert_equal(serialized['kind'], 'folder')
Esempio n. 8
0
def osf_storage_hgrid_contents(auth, node_addon, **kwargs):
    path = kwargs.get('path', '')
    file_tree = model.OsfStorageFileTree.find_by_path(path, node_addon)
    if file_tree is None:
        if path == '':
            return []
        raise HTTPError(httplib.NOT_FOUND)
    node = node_addon.owner
    permissions = utils.get_permissions(auth, node)
    return [
        utils.serialize_metadata_hgrid(item, node, permissions)
        for item in list(file_tree.children)
        if item.touch() and not item.is_deleted
    ]
Esempio n. 9
0
def osf_storage_hgrid_contents(auth, node_addon, **kwargs):
    path = kwargs.get('path', '')
    file_tree = model.OsfStorageFileTree.find_by_path(path, node_addon)
    if file_tree is None:
        if path == '':
            return []
        raise HTTPError(httplib.NOT_FOUND)
    node = node_addon.owner
    permissions = utils.get_permissions(auth, node)
    return [
        utils.serialize_metadata_hgrid(item, node, permissions)
        for item in list(file_tree.children)
        if item.touch() and not item.is_deleted
    ]
Esempio n. 10
0
def osf_storage_get_metadata_hook(node_addon, payload, **kwargs):
    path = payload.get('path', '')
    file_tree = model.OsfStorageFileTree.find_by_path(path, node_addon)
    if file_tree is None:
        if path == '':
            return []
        raise HTTPError(httplib.NOT_FOUND)
    node = node_addon.owner
    # TODO: Handle nested folders
    return [
        utils.serialize_metadata_hgrid(item, node)
        for item in list(file_tree.children)
        if not item.is_deleted
    ]
Esempio n. 11
0
 def test_serialize_metadata_file(self):
     file_record = model.OsfStorageFileRecord(
         path='kind/of/<strong>magic.mp3',
         node_settings=self.project.get_addon('osfstorage'),
     )
     serialized = utils.serialize_metadata_hgrid(
         file_record,
         self.project,
     )
     assert_equal(
         serialized['path'],
         'kind/of/<strong>magic.mp3',
     )
     assert_equal(
         serialized['name'],
         '<strong>magic.mp3',
     )
     assert_equal(serialized['ext'], '.mp3')
     assert_equal(serialized['kind'], 'file')
Esempio n. 12
0
 def test_hgrid_contents(self):
     path = u'kind/of/magíc.mp3'
     record, _ = model.OsfStorageFileRecord.get_or_create(
         path=path,
         node_settings=self.node_settings,
     )
     version = factories.FileVersionFactory()
     record.versions.append(version)
     record.save()
     res = self.send_hook(
         'osf_storage_get_metadata_hook',
         {'path': 'kind/of'},
     )
     assert_equal(len(res.json), 1)
     assert_equal(res.json[0],
                  utils.serialize_metadata_hgrid(
                      record,
                      self.project,
                  ))
Esempio n. 13
0
 def test_serialize_metadata_file(self):
     file_record = model.OsfStorageFileRecord(
         path='kind/of/<strong>magic.mp3',
         node_settings=self.project.get_addon('osfstorage'),
     )
     serialized = utils.serialize_metadata_hgrid(
         file_record,
         self.project,
     )
     assert_equal(
         serialized['path'],
         'kind/of/<strong>magic.mp3',
     )
     assert_equal(
         serialized['name'],
         '<strong>magic.mp3',
     )
     assert_equal(serialized['ext'], '.mp3')
     assert_equal(serialized['kind'], 'file')
Esempio n. 14
0
 def test_serialize_metadata_folder(self):
     file_tree = model.OsfStorageFileTree(
         path='god/save/the/queen',
         node_settings=self.project.get_addon('osfstorage'),
     )
     permissions = {'edit': False, 'view': True}
     serialized = utils.serialize_metadata_hgrid(
         file_tree,
         self.project,
         permissions,
     )
     assert_equal(serialized['addon'], 'osfstorage')
     assert_equal(serialized['path'], 'god/save/the/queen')
     assert_equal(serialized['name'], 'queen')
     assert_equal(serialized['ext'], '')
     assert_equal(serialized['kind'], 'folder')
     assert_equal(
         serialized['urls'],
         utils.build_hgrid_urls(file_tree, self.project),
     )
     assert_equal(serialized['permissions'], permissions)
Esempio n. 15
0
 def test_hgrid_contents(self):
     path = u'kind/of/magíc.mp3'
     record, _ = model.OsfStorageFileRecord.get_or_create(
         path=path,
         node_settings=self.node_settings,
     )
     version = factories.FileVersionFactory()
     record.versions.append(version)
     record.save()
     res = self.send_hook(
         'osf_storage_get_metadata_hook',
         {'path': 'kind/of/'},
     )
     assert_equal(len(res.json), 1)
     assert_equal(
         res.json[0],
         utils.serialize_metadata_hgrid(
             record,
             self.project,
         )
     )