Problem/Motivation
When users are canceled any files attached to that user are not updated and lead to orphaned files.
Steps to reproduce
- Create a test user
- Upload a file
- Cancel the test user selecting make content belong to anonymous
- Check the database and verify the file ownership is still to the ID of the deleted user
Proposed resolution
When a user is canceled make any files belong to anonymous.
Remaining tasks
Reroll patch
Review
User interface changes
NA
API changes
NA
Data model changes
NA
Release notes snippet
NA
Original Post
I think I said it in whole in the subject line.
I deleted two users but in the file_managed table the uids are still from the now deleted users. I would have thought the uids would be changed to zero (the anonymous user).
I'm guessing there needs to be a hook in the file module somewhere to pick up the "user reassign" action.
| Comment | File | Size | Author |
|---|
Issue fork drupal-1461042
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
reg commentedI came across this because it affected the media module, here's the issue: http://drupal.org/node/1459822
Comment #2
dave reidBugs have to be fixed in D8 and then backported to D7.
Comment #3
reg commentedAh, thanks for letting me know.
Comment #4
dave reidComment #5
allie mickaThis patch anonymizes files on user_cancel_reassign, and attempts to delete a user's files when the user is deleted. However, the call to entity_delete_multiple for files will not work until #1361226: Make the file entity a classed object is committed.
Comment #6
allie mickaAaaand querying the correct table.
Comment #7
allie mickaErrant case in file_user_cancel
Comment #8
dave reidComment #10
saltednutRerolled patch
Comment #11
eriknewby commented#10: drupal-file-user-orphaned-1461042-10.patch queued for re-testing.
Comment #13
eriknewby commentedAfter applying the patch from #10, I managed to find some things that needed changing in order to get it to work again.
See the interdiff for actual changes to the patch.
Notice I've removed the hook_user_predelete() call because that doesn't seem to fall into this particular issue that was filed. This issue is specifically about "anonymizing" file management. I think we can open a separate issue to deal with the deleting of file entities when a user account is deleted along with its associated content.
Comment #14
star-szrNice work @eriknewby! The only thing I'm seeing is the indent level of the break statement doesn't match coding standards, see https://drupal.org/coding-standards#controlstruct.
Setting to needs work not so much for the indentation but because this will need test coverage as well.
Comment #15
eriknewby commentedupdated indentation. Let me know if I missed anything else.
Comment #17
eriknewby commentedargh. Left out a closing bracket. fixt!
Comment #18
star-szrCode standards look good. Setting to NW for the remaining test coverage.
Comment #19
mgiffordComment #22
slashrsm commentedComment #25
aerozeppelin commentedTests for patch #17.
Comment #37
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge require as a guide.
Confirmed this is still an issue in D10.1
Removing the needs tests tag as they were added in #25.
Looking at patch #25 it will need to be rerolled but also it's got a number of deprecation calls in it that will need to be replaced.
Looking at the test I think
Can be removed and use the users already in the test.
To adhere to ticket templates tagging for IS update using the standard template with proposed solution explicitly written.
Comment #38
smustgrave commentedUpdated issue summary and rerolled patch replacing deprecated calls.
Think this could be major as this leads to orphaned files.
Comment #39
borisson_The approach was already validated before in #14 and I think this looks good as well, this has enough test coverage as well.
I was doubting if the hook was the right place or if we should do it where the user actually gets removed, but I think this is better so that it all sticks in the file module.
Comment #40
larowlanNo longer applies.
Fix looks good though
Why do we create a node and an entity to attach the file to?
Isn't one (the entity test entity) enough?
Comment #44
mohit_aghera commentedI've addressed the feedback in #40
I think node tests aren't required as such.
Fixed a few more things in the PR
- convert it to use OOP hooks
- Fixed a few things in tests.
- Tests seems green now.
Hiding all the patches in favour of MR.
Comment #45
smustgrave commentedNice!
Left 1 item of feedback on the MR.