fix: handle cloud pollers in agent show page and fix NoResultsError
Two issues fixed: 1. Cloud pollers (organization_id = nil) were causing access denied errors when superadmins tried to view them. Now allows access if user is superadmin and agent is a cloud poller. 2. Ecto.NoResultsError was being raised without required :queryable option, causing KeyError crash. Now properly raises with queryable parameter. Error was: KeyError: key :queryable not found in [] (ecto 3.13.5) lib/ecto/exceptions.ex:203: Ecto.NoResultsError.exception/1 (towerops) lib/towerops_web/live/agent_live/show.ex:16: mount/3
This commit is contained in:
parent
8f87d4bbab
commit
97cdb8e46c
1 changed files with 8 additions and 3 deletions
|
|
@ -10,10 +10,15 @@ defmodule ToweropsWeb.AgentLive.Show do
|
|||
def mount(%{"id" => id}, _session, socket) do
|
||||
organization = socket.assigns.current_organization
|
||||
agent_token = Agents.get_agent_token!(id)
|
||||
current_user = socket.assigns.current_scope.user
|
||||
|
||||
# Verify the agent belongs to this organization
|
||||
if agent_token.organization_id != organization.id do
|
||||
raise Ecto.NoResultsError
|
||||
# Verify access: agent must belong to this org OR be a cloud poller (visible to superadmin)
|
||||
has_access =
|
||||
agent_token.organization_id == organization.id ||
|
||||
(agent_token.is_cloud_poller && current_user.is_superuser)
|
||||
|
||||
if !has_access do
|
||||
raise Ecto.NoResultsError, queryable: Towerops.Agents.AgentToken
|
||||
end
|
||||
|
||||
# device this agent is responsible for)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue