Skip to content

Commit

Permalink
fixes for i3 worker
Browse files Browse the repository at this point in the history
  • Loading branch information
ciur committed Dec 10, 2024
1 parent 6925d10 commit 45927a3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
31 changes: 31 additions & 0 deletions papermerge/core/features/nodes/db/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,37 @@ def str2colexpr(keys: list[str]):
return result


def get_nodes(
db_session: Session, user_id: UUID, node_ids: list[UUID] | None = None
) -> list[schema.Document | schema.Folder]:
items = []
if node_ids is None:
node_ids = []

if len(node_ids) > 0:
stmt = (
select(orm.Node)
.options(selectinload(orm.Node.tags))
.filter(orm.Node.id.in_(node_ids), orm.Node.user_id == user_id)
)
else:
stmt = (
select(orm.Node)
.options(selectinload(orm.Node.tags))
.filter(orm.Node.user_id == user_id)
)

nodes = db_session.scalars(stmt).all()

for node in nodes:
if node.ctype == "folder":
items.append(schema.Folder.model_validate(node))
else:
items.append(schema.Document.model_validate(node))

return items


def get_folder_by_id(db_session: Session, id: uuid.UUID) -> schema.Folder:
stmt = select(Folder).where(Folder.id == id)
db_folder = db_session.scalars(stmt).one_or_none()
Expand Down
3 changes: 2 additions & 1 deletion papermerge/core/features/nodes/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ def get_nodes_details(
if len(node_ids) == 0:
return []

nodes = db.get_nodes(db_session, node_ids)
with Session() as db_session:
nodes = nodes_dbapi.get_nodes(db_session, node_ids=node_ids, user_id=user.id)

return nodes

Expand Down
12 changes: 12 additions & 0 deletions papermerge/core/features/nodes/tests/test_nodes_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
from papermerge.core.tests.types import AuthTestClient


def test_get_node_details(auth_api_client: AuthTestClient, make_document, db_session):
# Arrange
user = auth_api_client.user
doc = make_document(title="letter.pdf", user=user, parent=user.home_folder)

# Act
response = auth_api_client.get(f"/nodes/?node_ids={doc.id}")

# Assert
assert response.status_code == 200


def test_nodes_move_basic(
auth_api_client: AuthTestClient, make_folder, make_document, db_session
):
Expand Down

0 comments on commit 45927a3

Please sign in to comment.