Skip to content

Commit b3c9213

Browse files
authored
Do not return nodes with private sensors only (#121)
1 parent 2504aff commit b3c9213

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

sensorsafrica/api/v2/views.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,12 @@ def list(self, request):
143143
nodes = []
144144
# Loop through the last active nodes
145145
for last_active in LastActiveNodes.objects.iterator():
146-
# Get the current node
146+
# Get the current node only if it has public sensors
147147
node = Node.objects.filter(
148-
Q(id=last_active.node.id), ~Q(sensors=None)
149-
).get()
148+
Q(id=last_active.node.id), Q(sensors__public=True)
149+
).first()
150+
if node is None:
151+
continue
150152

151153
# The last acive date
152154
last_data_received_at = last_active.last_data_received_at
@@ -161,7 +163,7 @@ def list(self, request):
161163
SensorDataValue.objects.filter(
162164
Q(sensordata__sensor__node=last_active.node.id),
163165
# Open endpoints should return data from public sensors
164-
# only.
166+
# only in case a node has both public & private sensors
165167
Q(sensordata__sensor__public=True),
166168
Q(sensordata__location=last_active.location.id),
167169
Q(sensordata__timestamp__gte=last_5_mins),
@@ -214,6 +216,7 @@ def list(self, request):
214216
"stats": stats,
215217
}
216218
)
219+
217220
return Response(nodes)
218221

219222
def create(self, request):

0 commit comments

Comments
 (0)