impersonate fix and change log level for device polling
This commit is contained in:
parent
04c33b0719
commit
2a5622d95a
3 changed files with 37 additions and 2 deletions
|
|
@ -48,7 +48,7 @@ defmodule Towerops.Workers.JobHealthCheckWorker do
|
|||
missing_monitor_devices = Enum.reject(devices_with_monitoring, &MapSet.member?(active_monitor_job_device_ids, &1.id))
|
||||
|
||||
Enum.each(missing_monitor_devices, fn device ->
|
||||
Logger.warning(
|
||||
Logger.debug(
|
||||
"Device '#{device.name}' has monitoring_enabled=true but no active monitor job, creating job",
|
||||
device_id: device.id,
|
||||
device_name: device.name
|
||||
|
|
@ -67,7 +67,7 @@ defmodule Towerops.Workers.JobHealthCheckWorker do
|
|||
missing_poller_devices = Enum.reject(devices_with_snmp, &MapSet.member?(active_poller_job_device_ids, &1.id))
|
||||
|
||||
Enum.each(missing_poller_devices, fn device ->
|
||||
Logger.warning(
|
||||
Logger.debug(
|
||||
"Device '#{device.name}' has snmp_enabled=true but no active poller job, creating job",
|
||||
device_id: device.id,
|
||||
device_name: device.name
|
||||
|
|
|
|||
|
|
@ -828,6 +828,7 @@ defmodule ToweropsWeb.UserAuth do
|
|||
|> delete_session(:target_user_id)
|
||||
|> delete_session(:impersonating)
|
||||
|> assign(:current_scope, Scope.for_user(superuser))
|
||||
|> maybe_set_default_organization(superuser)
|
||||
|> put_flash(:info, "Stopped impersonating")
|
||||
|> redirect(to: redirect_path)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -584,6 +584,40 @@ defmodule ToweropsWeb.UserAuthTest do
|
|||
assert redirected_to(conn) == ~p"/devices"
|
||||
end
|
||||
|
||||
test "restores superuser's organization context after stopping impersonation", %{conn: conn} do
|
||||
# Create superuser with their own organization
|
||||
superuser =
|
||||
user_fixture()
|
||||
|> Ecto.Changeset.change(%{is_superuser: true})
|
||||
|> Towerops.Repo.update!()
|
||||
|
||||
{:ok, superuser_org} =
|
||||
Towerops.Organizations.create_organization(%{name: "Superuser Org"}, superuser.id)
|
||||
|
||||
# Create target user with their own organization
|
||||
target_user = user_fixture()
|
||||
|
||||
{:ok, target_org} =
|
||||
Towerops.Organizations.create_organization(%{name: "Target Org"}, target_user.id)
|
||||
|
||||
# Simulate impersonation with target user's organization in session
|
||||
conn =
|
||||
conn
|
||||
|> Map.put(:remote_ip, {127, 0, 0, 1})
|
||||
|> fetch_flash()
|
||||
|> put_session(:impersonating, true)
|
||||
|> put_session(:superuser_id, superuser.id)
|
||||
|> put_session(:target_user_id, target_user.id)
|
||||
|> put_session(:current_organization_id, target_org.id)
|
||||
|> assign(:current_scope, Scope.for_impersonation(superuser, target_user))
|
||||
|> UserAuth.stop_impersonation()
|
||||
|
||||
# Verify organization context is restored to superuser's org
|
||||
assert get_session(conn, :current_organization_id) == superuser_org.id
|
||||
assert conn.assigns.current_scope.user.id == superuser.id
|
||||
assert redirected_to(conn) == ~p"/devices"
|
||||
end
|
||||
|
||||
test "redirects to /orgs when superuser has no organizations", %{conn: conn} do
|
||||
superuser =
|
||||
user_fixture()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue