Prune login_activities older than 13 months (stored IPs and typed emails are kept forever)
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start with app/models/metrics_report.rb (active_users_by_type, ALLOWED_RANGES) to confirm the 12-month window, then look at lib/tasks/expire_case_contact_drafts.rake for the rake task style. Add app/services/prune_login_activities_service.rb using in_batches.delete_all on LoginActivity with a configurable window of at least 13 months. Done when the specs in spec/models/metrics_report_spec.rb and the new service spec pass and the rake task prints the deleted count.
Written by the indexing model from the issue text.
Description
Problem
login_activities (written by the authtrail gem on every Devise sign-in attempt) is never pruned. It's the second-largest table in production (~8 MB, behind only case_contacts), and every row holds personal data:
identity: the email that was typed, including failed attempts, which can be mistyped emails or other people's addressesip,user_agent,referreruser_id,success,failure_reason,created_at
(Geocoding is off in config/initializers/authtrail.rb, so city/region/country/latitude/longitude are empty.)
Keeping this forever adds privacy risk without benefit. The only reader in the app is the all-CASA-admin Metrics page: "Monthly active users", MetricsReport#active_users_by_type in app/models/metrics_report.rb. Its widest range is 12 months (ALLOWED_RANGES = [3, 6, 12]).
Related: #7263 (PII in logs and Bugsnag).
Proposal
Keep 13 months of login activity (the 12-month metrics window plus the partial current month) and delete older rows daily.
- A service, e.g.
app/services/prune_login_activities_service.rb, that deletesLoginActivity.where(created_at: ...13.months.ago)within_batches.delete_allso a large first run doesn't hold one long transaction. It returns the count deleted. Make the window configurable (LOGIN_ACTIVITY_RETENTION_MONTHS, default 13, minimum 13) so it can never cut into the metrics window. - A rake task
rake prune_login_activitiesthat calls it and prints the count. Follow the style oflib/tasks/expire_case_contact_drafts.rake. - Specs:
- deletes rows older than the window
- keeps rows inside it
- refuses a window under 13 months
- the Metrics page's 12-month monthly-active-users numbers are unchanged after pruning (
spec/models/metrics_report_spec.rb)
- Note in the PR description that a maintainer must add the task to Heroku Scheduler (daily).
Out of scope
Changing what authtrail records, e.g. not storing identity for failed attempts. That's worth a separate discussion under #7263.
Difficulty: beginner. One service, one rake task, specs.
- Dominant language
- Ruby
- Stars
- 384
- Forks
- 558
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 63
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rubyforgood/casa
-
⛓️ Security Difficulty: Easy Good First Issue Help Wanted ruby Type: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
rubyforgood/casa#7404 ·
Maintainers usually reply within 1 day
-
Difficulty: Easy Good First Issue Help Wanted ruby Type: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
rubyforgood/casa#7402 ·
Maintainers usually reply within 1 day
-
Remove the bin/bundle binstub (Heroku warns it can break Bundler on deploy)Possibly taken @Akash-Dhanwate claimed this 8 days ago. Opendependencies Difficulty: Easy Good First Issue
Difficulty 1/5 Under an hour Newbie friendliness 82/100
rubyforgood/casa#7325 · 2 comments ·
Maintainers usually reply within 1 day
-
Reports page: move export-button disable/re-enable into a Stimulus controllerMay be free again @Akash-Dhanwate claimed this 9 days ago, and no pull request is open. OpenDifficulty: Easy Good First Issue Help Wanted javascript
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
rubyforgood/casa#7311 · 2 comments ·
Maintainers usually reply within 1 day
-
New case: use Stimulus for the "I don't know the court date yet" toggleMay be free again @Aryankn29 claimed this 9 days ago, and no pull request is open. OpenDifficulty: Easy Good First Issue Help Wanted javascript
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
rubyforgood/casa#7310 · 1 comment ·
Maintainers usually reply within 1 day
All issues in rubyforgood/casa
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
internetee/registry#2984 ·
Maintainers usually reply within 6 days
-
Redis Lua error `@user_script:52: ERR value is not an integer or out of range` when `window_size` is configuredPossibly taken @mimosa claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
riscv/riscv-unified-db#2829 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
docker-library/ruby#534 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100