FIX: Update upload security on post rebake from UI (#23861)

When a user creates or edits a post, we already were updating
the security of uploads in the post based on site settings and
their access control post, which is important since these uploads
may be switched from secure/not secure based on configuration.
The `with_secure_uploads?` method on a post is used to determine
whether to use the secure-uploads URL for all uploads in the post,
regardless of their individual security, so if this is false and
some of the posts are still secure when rebaking, we end up with
broken URLs.

This commit just makes it so rebaking via the UI also re-evaluates
upload security so that when the post is loaded again after processing,
all of the uploads have the correct security.
This commit is contained in:
Martin Brennan
2023-10-10 11:15:51 +10:00
committed by GitHub
parent bb342bafe9
commit 542f77181a
3 changed files with 46 additions and 2 deletions

View File

@@ -748,7 +748,12 @@ class Post < ActiveRecord::Base
problems
end
def rebake!(invalidate_broken_images: false, invalidate_oneboxes: false, priority: nil)
def rebake!(
invalidate_broken_images: false,
invalidate_oneboxes: false,
priority: nil,
update_upload_security: false
)
new_cooked = cook(raw, topic_id: topic_id, invalidate_oneboxes: invalidate_oneboxes)
old_cooked = cooked
@@ -765,6 +770,10 @@ class Post < ActiveRecord::Base
TopicLink.extract_from(self)
QuotedPost.extract_from(self)
# Settings may have changed before rebake, so any uploads linked to the post
# should have their secure status reexamined.
update_uploads_secure_status(source: "post rebake") if update_upload_security
# make sure we trigger the post process
trigger_post_process(bypass_bump: true, priority: priority)