discourse/app/jobs/regular/sync_access_control_for_uploads.rb
Alan Guo Xiang Tan b9628ad40a
DEV: Update uploads:sync_access_control rake task to remove ACLs (#33286)
The `uploads:sync_access_control` rake task should reset the access
control
of all s3 objects linked to an upload record. This means that if the
`s3_use_acls` site setting has been disabled, the rake task should
remove the existing ACL that has been set previously.
2025-06-25 15:03:05 +08:00

34 lines
1.1 KiB
Ruby

# frozen_string_literal: true
module Jobs
# Sometimes we need to update the access control metadata for a _lot_ of objects on S3 (such as when secure uploads
# is enabled), this is best spread out over many jobs instead of having to do the whole thing serially.
class SyncAccessControlForUploads < ::Jobs::Base
sidekiq_options queue: "low"
def execute(args)
return if !Discourse.store.external?
return if !args.key?(:upload_ids)
Upload
.includes(:optimized_images)
.where(id: args[:upload_ids])
.find_in_batches do |uploads|
uploads.each do |upload|
begin
Discourse.store.update_upload_access_control(upload, remove_existing_acl: true)
rescue => err
Discourse.warn_exception(
err,
message: "Failed to update upload access control",
env: {
upload_id: upload.id,
filename: upload.original_filename,
},
)
end
end
end
end
end
end