Fix #4990: Allow admins to delete uploads.

Allow admins to delete media asset files.

This only deletes the image file itself, not the upload or media asset record. The upload will still
be in the user's upload list, but the image will be gone. The media asset page will still exist, but
it will only show the file's metadata, not the image itself. We don't delete the metadata so we have
a record of what the file's MD5 was and who uploaded it, to prevent the file from being uploaded
again and to take action against the user if necessary.
This commit is contained in:
evazion
2022-11-29 18:09:25 -06:00
parent 695568e08b
commit 756362f89e
11 changed files with 83 additions and 13 deletions

View File

@@ -392,17 +392,23 @@ class MediaAsset < ApplicationRecord
end
end
def expunge!
delete_files!
update!(status: :expunged)
def expunge!(current_user, log: true)
with_lock do
delete_files!
update!(status: :expunged)
ModAction.log("expunged media asset ##{id} (md5=#{md5})", :media_asset_expunge, subject: self, user: current_user) if log
end
rescue
update!(status: :failed)
raise
end
def trash!
variants.each(&:trash_file!)
update!(status: :deleted)
def trash!(current_user, log: true)
with_lock do
variants.each(&:trash_file!)
update!(status: :deleted)
ModAction.log("deleted media asset ##{id} (md5=#{md5})", :media_asset_delete, subject: self, user: current_user) if log
end
rescue
update!(status: :failed)
raise

View File

@@ -42,6 +42,8 @@ class ModAction < ApplicationRecord
post_vote_undelete: 233,
pool_delete: 62,
pool_undelete: 63,
media_asset_delete: 72,
media_asset_expunge: 76,
artist_ban: 184,
artist_unban: 185,
comment_update: 81,

View File

@@ -780,7 +780,7 @@ class Post < ApplicationRecord
decrement_tag_post_counts
remove_from_all_pools
remove_from_fav_groups
media_asset.trash!
media_asset.trash!(current_user, log: false)
destroy
update_parent_on_destroy
end