Skip to content

Commit d3ef293

Browse files
committed
Add some debug logs and make test reflect desired value
1 parent f3e6db6 commit d3ef293

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

pydatalab/src/pydatalab/routes/v0_1/graphs.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from flask import Blueprint, jsonify, request
22

3+
from pydatalab.logger import LOGGER
34
from pydatalab.mongo import flask_mongo
45
from pydatalab.permissions import active_users_or_get_only, get_default_permissions
56

@@ -49,21 +50,30 @@ def get_graph_cy_format(
4950
all_documents.rewind()
5051

5152
else:
53+
LOGGER.debug("!!!!!!!!!!")
5254
all_documents = list(
5355
flask_mongo.db.items.find(
5456
{
55-
"$or": [{"item_id": item_id}, {"relationships.item_id": item_id}],
56-
**get_default_permissions(user_only=False),
57+
"$and": [
58+
{"$or": [{"item_id": item_id}, {"relationships.item_id": item_id}]},
59+
{**get_default_permissions(user_only=False)},
60+
],
5761
},
5862
projection={"item_id": 1, "name": 1, "type": 1, "relationships": 1},
5963
)
6064
)
6165

66+
LOGGER.debug("Found %d documents related to item %s", len(all_documents), item_id)
67+
6268
node_ids = {document["item_id"] for document in all_documents} | {
6369
relationship.get("item_id")
6470
for document in all_documents
6571
for relationship in document.get("relationships", [])
6672
}
73+
74+
LOGGER.debug("Found %d unique node IDs related to item %s", len(node_ids), item_id)
75+
LOGGER.debug("Node IDs: %s", node_ids)
76+
6777
if len(node_ids) > 1:
6878
or_query = [{"item_id": id} for id in node_ids if id != item_id]
6979
next_shell = flask_mongo.db.items.find(
@@ -77,6 +87,11 @@ def get_graph_cy_format(
7787
all_documents.extend(next_shell)
7888
node_ids = node_ids | {document["item_id"] for document in all_documents}
7989

90+
LOGGER.debug(
91+
"Found %d unique node IDs related to item %s after filtering", len(node_ids), item_id
92+
)
93+
LOGGER.debug("Node IDs: %s", node_ids)
94+
8095
nodes = []
8196
edges = []
8297

pydatalab/tests/server/test_item_graph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,5 @@ def test_single_starting_material(admin_client, client):
122122

123123
# Current broken behaviour: non-admin users see the full graph, but not the things they don't have permission for
124124
graph = client.get("/item-graph/great-grandchild").json
125-
assert len(graph["nodes"]) == 5
126-
assert len(graph["edges"]) == 4
125+
assert len(graph["nodes"]) == 2
126+
assert len(graph["edges"]) == 1

0 commit comments

Comments
 (0)