Exemplo n.º 1
0
def document() -> Response:
    """Download a document."""
    filename = request.args.get("filename")
    if filename is None:
        return abort(404)
    if is_document_or_import_file(filename, g.ledger):
        return send_file_inline(filename)
    return abort(404)
Exemplo n.º 2
0
def delete_document(filename: str) -> str:
    """Delete a document."""
    if not is_document_or_import_file(filename, g.ledger):
        raise FavaAPIException("No valid document or import file.")

    if not path.exists(filename):
        raise FavaAPIException(f"{filename} does not exist.")

    remove(filename)
    return f"Deleted {filename}."
Exemplo n.º 3
0
def delete_document() -> str:
    """Delete a document."""
    filename = request.args.get("filename")
    if not filename:
        raise FavaAPIException("No filename specified.")

    if not is_document_or_import_file(filename, g.ledger):
        raise FavaAPIException("No valid document or import file.")

    if not path.exists(filename):
        raise FavaAPIException(f"{filename} does not exist.")

    remove(filename)
    return f"Deleted {filename}."
Exemplo n.º 4
0
def test_is_document_or_import_file(example_ledger):
    example_ledger.fava_options["import-dirs"] = ["/test/"]
    assert not is_document_or_import_file("/asdfasdf", example_ledger)
    assert not is_document_or_import_file("/test/../../err", example_ledger)
    assert is_document_or_import_file("/test/err/../err", example_ledger)
    assert is_document_or_import_file("/test/err/../err", example_ledger)
Exemplo n.º 5
0
def test_is_document_or_import_file(example_ledger, monkeypatch):
    monkeypatch.setitem(example_ledger.fava_options, "import-dirs", ["/test/"])
    assert not is_document_or_import_file("/asdfasdf", example_ledger)
    assert not is_document_or_import_file("/test/../../err", example_ledger)
    assert is_document_or_import_file("/test/err/../err", example_ledger)
    assert is_document_or_import_file("/test/err/../err", example_ledger)