mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
Do not show deleted resources in the client and cleanup connections table
This commit is contained in:
@@ -64,7 +64,7 @@ defmodule Domain.Resources do
|
||||
{preload, _opts} = Keyword.pop(opts, :preload, [])
|
||||
|
||||
{:ok, resources} =
|
||||
Resource.Query.all()
|
||||
Resource.Query.not_deleted()
|
||||
|> Resource.Query.by_account_id(subject.account.id)
|
||||
|> Resource.Query.by_authorized_actor_id(subject.actor.id)
|
||||
|> Resource.Query.with_at_least_one_gateway_group()
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
defmodule Domain.Repo.Migrations.DeleteConnectionsForDeletedResources do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
execute("""
|
||||
DELETE FROM resource_connections
|
||||
WHERE resource_id IN (SELECT id FROM resources WHERE deleted_at IS NOT NULL)
|
||||
""")
|
||||
|
||||
execute("""
|
||||
DELETE FROM resource_connections
|
||||
WHERE gateway_group_id IN (SELECT id FROM gateway_groups WHERE deleted_at IS NOT NULL)
|
||||
""")
|
||||
end
|
||||
end
|
||||
@@ -336,7 +336,14 @@ defmodule Domain.ResourcesTest do
|
||||
actor: actor,
|
||||
subject: subject
|
||||
} do
|
||||
resource = Fixtures.Resources.create_resource(account: account)
|
||||
gateway_group = Fixtures.Gateways.create_group(account: account)
|
||||
|
||||
resource =
|
||||
Fixtures.Resources.create_resource(
|
||||
account: account,
|
||||
connections: [%{gateway_group_id: gateway_group.id}]
|
||||
)
|
||||
|
||||
actor_group = Fixtures.Actors.create_group(account: account)
|
||||
Fixtures.Actors.create_membership(account: account, actor: actor, group: actor_group)
|
||||
|
||||
@@ -346,7 +353,7 @@ defmodule Domain.ResourcesTest do
|
||||
resource: resource
|
||||
)
|
||||
|
||||
{:ok, _resource} = delete_resource(resource, subject)
|
||||
resource |> Ecto.Changeset.change(deleted_at: DateTime.utc_now()) |> Repo.update!()
|
||||
|
||||
assert list_authorized_resources(subject) == {:ok, []}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user