コード例 #1
0
ファイル: __init__.py プロジェクト: abondis/simple-share
def api_delete_path(path='.'):
    """Return a list of files in a path if permitted
    """
    real_path = protect_path(path)
    try:
        delete_path(real_path)
        return relist_parent_folder(real_path)
    except OSError:
        abort(404)
コード例 #2
0
ファイル: test_tools.py プロジェクト: abondis/simple-share
def test_relist_parent_folder(aaa):
    """Get a list of files and folders in the parent of the specified path"""
    t.root_dir = "/tmp/test"
    aaa.current_user = "******"
    prep_folder()
    r = t.relist_parent_folder("/tmp/test/blah")
    del_folder()
    assert r["dirs"][0]["name"] == "folder"
    assert r["files"][0]["name"] == "file"
コード例 #3
0
ファイル: __init__.py プロジェクト: abondis/simple-share
def _delete_shared_path(path='.'):
    """
    We delete .../user/shares/<uid>
    and .../user/config/<path>/<uid>
    """
    uid = basename(path)
    folder = dirname(path)
    abs_folder_path = protect_path(folder)
    config_folder_path = protect_path(path, 'config')
    config_uid_path = protect_path(uid, 'config')
    try:
        delete_path(config_folder_path)
        delete_path(config_uid_path)
        return relist_parent_folder(abs_folder_path)
    except OSError:
        abort(404)
コード例 #4
0
ファイル: __init__.py プロジェクト: abondis/simple-share
def share(path="."):
    """Share a file or a folder"""
    reuse = post_get('reuse') or None
    # print(reuse)
    public = post_get('public')
    users = post_get('users')
    # .../user/config
    path_config = permitted_config_path()
    # .../user/shares
    uidshares_config = permitted_shares_path()
    # /.../user/files/....
    real_path = protect_path(path)
    try:
        # /.../user/files
        # get relative path, to use in configuration path
        rel_shared_path = relpath(real_path, permitted_files_path())
    except IOError:
        abort(403, PATH_ERROR)
    if reuse is not None:
        try:
            shared_path = get_config(reuse, 'path', 'shares')
        except IOError:
            abort(400, "This sharing ID is invalid")
        if shared_path != rel_shared_path:
            abort(400, "This sharing ID is invalid")
    else:
        uid, uid_path = create_random_folder()
    # create .../user/config/rel/path/UID
    print('uid {} Uid_path {}'.format(reuse or uid, uid_path))
    print('*' * 80)
    print((uidshares_config, rel_shared_path, reuse or uid, rel_shared_path))
    print('*' * 80)
    configure(
        path_config,
        rel_shared_path,
        reuse or uid,
        rel_shared_path)
    # configure .../user/shares/UID/
    configure(uidshares_config, uid_path, 'path', real_path)
    configure(uidshares_config, uid_path, 'public', public)
    configure(uidshares_config, uid_path, 'users', users)
    return relist_parent_folder(real_path)