-
Notifications
You must be signed in to change notification settings - Fork 687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean up orphaned submissions/replies no longer associated with sources #4672
Conversation
da9e3c0
to
f052f02
Compare
This is accomplished by an alembic migration that removes any orphaned submissions from the database.
if a source has been deleted, we no longer have its filesystem_id in the database. as such, we will need to find the file, being careful to guard against potential duplicates due to the journalist_designations not necessarily being unique (this is a very rare case)
two situations _could_ potentially arise trying to think of the edge cases here: - Admin has been deleting files manually by digging around for files that consume a lot of disk in the securedrop data directory - A very rare situation can occur where there is a colliding journalist_designation
invalid objects being those which do not have a matching source_id in the sources table
easiest to do with a custom exception, but for files that were manually deleted by a curious admin who e.g. removed large files that were not properly deleted due to this bug, we should also remove the corresponding row in the database.
bandit flags this because the table name is passed in as a variable. It's not user controlled so this does not introduce a security problem (function is in the migration only). I could suppress the alert by removing the function but in the spirit of not making this alembic migration even more repetitive I'm adding `# nosec`.
one of the quirks of SecureDrop is that config.py might not yet exist until the app Ansible role has ran this means for fresh installs, the database must be created via alembic upgrade head without any errors raising, else the securedrop-app-code package install will fail
f052f02
to
08cfcd8
Compare
OK this one I just rebased on top of develop, updates from the latest deletion code changes you can see in 08cfcd8. Ready for review! |
the staging CI failure here is legit, investigating |
so it won't import on existing installs
[still failing so re-provisioning staging on this branch so I can reproduce the fresh install scenario from CI] |
Looks good to me. Got through the test plan, and problems were cleaned up. So as soon as we appease CI.... |
OK kewl, pretty sure I have a fix, testing locally. It's just fixing more import paths due to the changes introduced on |
OK latest commit should fix the staging CI job (did for me locally - just moving imports under that try/except) - if it does, @conorsch please stamp this one (heads up that we will also test this scenario during QA for 1.0.0). |
Codecov Report
@@ Coverage Diff @@
## develop #4672 +/- ##
============================================
+ Coverage 68.08% 81.61% +13.52%
============================================
Files 48 49 +1
Lines 3350 3416 +66
Branches 380 391 +11
============================================
+ Hits 2281 2788 +507
+ Misses 966 535 -431
+ Partials 103 93 -10
Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## develop #4672 +/- ##
============================================
+ Coverage 68.08% 81.61% +13.52%
============================================
Files 48 49 +1
Lines 3350 3416 +66
Branches 380 391 +11
============================================
+ Hits 2281 2788 +507
+ Misses 966 535 -431
+ Partials 103 93 -10
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving based on visual review.
Status
Ready for review
Description of Changes
Fixes #1189
Changes proposed in this pull request:
Testing
Other than reviewing the diff (see commit messages for details):
develop
www-data
user (sudo su www-data -s /bin/bash
)make build-debs
andvagrant provision /staging/
). The migration should run as the app code package is installed.Deployment
This will run in postinst of
securedrop-app-code
packageChecklist
If you made changes to the server application code:
make lint
) and tests (make -C securedrop test
) pass in the development containerIf you made non-trivial code changes: