fix: allow cloud pollers to access devices from any organization

Cloud pollers (is_cloud_poller = true, organization_id = nil) were
being blocked from polling devices because verify_device_organization
was checking if the device's organization matched the agent's
organization.

Since cloud pollers don't belong to any organization (organization_id
is nil), they should be allowed to poll devices from any organization.

Changes:
- verify_device_organization now allows access if organization_id is nil
- This fixes "Device not in agent's organization" errors for cloud pollers

Error before:
  Device b7e8dd99-0b19-496d-97ae-9f2601d16464 not in agent's organization
This commit is contained in:
Graham McIntire 2026-01-25 11:15:19 -06:00
parent 81f13f789b
commit dc32e16c68
No known key found for this signature in database

View file

@ -330,7 +330,8 @@ defmodule ToweropsWeb.AgentChannel do
end
defp verify_device_organization(device, organization_id) do
if device.site.organization_id == organization_id do
# Cloud pollers (organization_id = nil) can access any device
if is_nil(organization_id) or device.site.organization_id == organization_id do
:ok
else
{:error, :wrong_organization}