Skip to content

Fix notification & audit trail for dataclip retention policy changes - #5089

Open
taylordowns2000 wants to merge 4 commits into
mainfrom
data-retention-policy-notification
Open

taylordowns2000 wants to merge 4 commits into
mainfrom
data-retention-policy-notification

Conversation

@taylordowns2000

@taylordowns2000 taylordowns2000 commented Aug 22, 2026

Copy link
Copy Markdown
Member

Description

This PR fixes #5088 by checking for a change in the retention_policy when deciding whether to send the policy change alert. The new functionality in this PR:

  1. should properly send the email (not stay silent on critical changes!)
  2. should not send misleading information about i/o retention periods when the i/o policy is set to :erase_all

The PR also fixes #5090 (the audit trial) in exactly the same fashion.

Validation steps

  1. Change only the retention policy, don't touch the retention periods.
  2. See the email.
  3. Log in as a super user.
  4. Check the audit trail.
  5. See the appended audit trail entry.

AI Usage

Please disclose whether you've used AI anywhere in this PR (it's cool, we just
want to know!):

  • I have used Claude Code
  • I have used another model
  • I have not used AI

You can read more details in our
Responsible AI Policy

Pre-submission checklist

  • I have performed an AI review of my code (we recommend using /review
    with Claude Code)
  • I have implemented and tested all related authorization policies.
    (e.g., :owner, :admin, :editor, :viewer)
  • I have updated the changelog.
  • I have ticked a box in "AI usage" in this PR

@github-project-automation github-project-automation Bot moved this to New Issues in Core Aug 22, 2026
@github-actions

Copy link
Copy Markdown

Security Review ✅

  • S0 (project scoping): N/A — the change only extends which changeset keys (:retention_policy) trigger an existing notification helper inside Projects.update_project; no new queries or web-layer entrypoints.
  • S1 (authorization): N/A — no new controllers, LiveView events, or policy-gated actions; caller authorization for update_project is unchanged.
  • S2 (audit trail): PASS — retention-policy changes are still audited via the pre-existing Audit.derive_events(changeset, user) step at lib/lightning/projects.ex:617; this PR only affects email notifications.

Comment thread lib/lightning/projects.ex

defp retention_setting_updated?(changeset) do
Map.has_key?(changeset.changes, :history_retention_period) or
Map.has_key?(changeset.changes, :retention_policy) or

@taylordowns2000 taylordowns2000 Aug 22, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we didn't count changing the policy as part of the retention_setting_updated? function

@taylordowns2000 taylordowns2000 changed the title Fix notification when dataclip retention policy changes Fix notification & audit trail for dataclip retention policy changes Aug 22, 2026
if get_change(changeset, :history_retention_period) ||
get_change(changeset, :dataclip_retention_period) do
get_change(changeset, :dataclip_retention_period) ||
get_change(changeset, :retention_policy) do

@elias-ba elias-ba Aug 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick question about this line. I was poking at what happens when someone changes only the policy and leaves the periods alone, and noticed the dataclip retention period gets cleared. That got me wondering what the nightly wipe does afterwards, since that period is the only thing it keys off.

So I set up a project with a month of history and a week of dataclip retention, dropped in a record from ten days ago, and flipped just the policy to erase_all. On main the record gets blanked, as you'd expect. On this branch it's still sitting there with its body intact.

Then I went looking to see whether this was new, and mostly it isn't. If you change the policy at the same time as a period, or if a sandbox inherits erase_all from its parent, the old data already stays put on main. So I think this line is really just making things consistent, which I'd guess was the point. It happens to be the one route where the wipe still ran.

Which makes me wonder whether we could leave it out of this PR and deal with the underlying thing on its own in a follow up issue, maybe having erase_all actually clear what's already stored rather than leaning on that period at all. The email side doesn't seem to need it, since the bullets already key off the policy.

Could easily be missing something though, let me know what you think.

@@ -147,6 +147,21 @@ defmodule Lightning.Accounts.UserNotifier do

io_data_saved = updated_project.retention_policy != :erase_all

@elias-ba elias-ba Aug 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This treats retain_with_errors the same as retain_all, so now that a policy-only change sends the email, someone switching to retain_with_errors would get a mail reading exactly like the retain_all one. Nothing to act on today, since that option is still commented out in the settings radio group.

The reason I mention it at all is that the same gap shows up in the save_dataclips? check in projects.ex, which has no clause for retain_with_errors and would raise on it. The TODO next to the commented-out option points at #1694, which is closed, so I'm not sure if that option is still on the cards. Either way it seemed worth knowing before anyone switches it on.

@taylordowns2000

taylordowns2000 commented Aug 24, 2026 via email

Copy link
Copy Markdown
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New Issues

Development

Successfully merging this pull request may close these issues.

Audit trail not updated when I/O retention policy changes Email not sent when I/O data retention policy changes

2 participants