Skip to content

Commit

Permalink
Delete PossibleIndexSubmission when anonymizing the case (#1899)
Browse files Browse the repository at this point in the history
  • Loading branch information
maennchen authored Mar 10, 2023
1 parent 6fa7f97 commit 717638c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/hygeia/case_context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2485,7 +2485,8 @@ defmodule Hygeia.CaseContext do
:auto_tracing,
:received_transmissions,
:propagated_transmissions,
:tests
:tests,
:possible_index_submissions
])

attrs = %{
Expand All @@ -2501,6 +2502,7 @@ defmodule Hygeia.CaseContext do
tests: Anonymization.anonymize_test_params(case.tests),
anonymized: true,
anonymization_date: Date.utc_today(),
possible_index_submissions: [],
monitoring: Anonymization.anonymize_monitoring_params(case.monitoring)
}

Expand Down
6 changes: 5 additions & 1 deletion lib/hygeia/case_context/case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ defmodule Hygeia.CaseContext.Case do
foreign_key: :propagator_case_uuid,
on_replace: :delete

has_many :possible_index_submissions, PossibleIndexSubmission, foreign_key: :case_uuid
has_many :possible_index_submissions, PossibleIndexSubmission,
foreign_key: :case_uuid,
on_replace: :delete

has_many :emails, Email, foreign_key: :case_uuid, on_replace: :delete
has_many :sms, SMS, foreign_key: :case_uuid, on_replace: :delete
has_many :notes, Note, foreign_key: :case_uuid, on_replace: :delete
Expand Down Expand Up @@ -207,6 +210,7 @@ defmodule Hygeia.CaseContext.Case do
|> cast_assoc(:propagated_transmissions)
|> cast_assoc(:sms)
|> cast_assoc(:tests)
|> cast_assoc(:possible_index_submissions)
|> validate_monitoring()
|> cast_assoc(:notes)
|> cast_embed(:phases, required: true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# credo:disable-for-this-file Credo.Check.Readability.Specs
defmodule Hygeia.Repo.Migrations.AnonymizationDeletePossibleIndexSubmissions do
@moduledoc false

use Hygeia, :migration

def up do
execute(fn ->
:ok = run_authentication(repo(), origin: :anonymization_job, originator: :noone)
end)

execute("""
DELETE
FROM possible_index_submissions
WHERE case_uuid IN (
SELECT
uuid
FROM cases
WHERE anonymized
)
""")
end

def down do
end
end
10 changes: 8 additions & 2 deletions test/hygeia/case_context_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,8 @@ defmodule Hygeia.CaseContextTest do
}
})

possible_index_submission_fixture(case_main, %{})

assert %Case{
uuid: ^case_main_uuid,
notes: [%Note{}],
Expand Down Expand Up @@ -877,6 +879,7 @@ defmodule Hygeia.CaseContextTest do
}
}
],
possible_index_submissions: [_submission],
anonymized: false,
anonymization_date: nil
} =
Expand All @@ -888,7 +891,8 @@ defmodule Hygeia.CaseContextTest do
:auto_tracing,
:received_transmissions,
:propagated_transmissions,
:tests
:tests,
:possible_index_submissions
])

assert {:ok, anonymized_case} = CaseContext.anonymize_case(case_main)
Expand Down Expand Up @@ -936,6 +940,7 @@ defmodule Hygeia.CaseContextTest do
}
}
],
possible_index_submissions: [],
anonymized: true,
anonymization_date: ^today
} =
Expand All @@ -947,7 +952,8 @@ defmodule Hygeia.CaseContextTest do
:auto_tracing,
:received_transmissions,
:propagated_transmissions,
:tests
:tests,
:possible_index_submissions
])
end

Expand Down

0 comments on commit 717638c

Please sign in to comment.