mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Apply syntax_tree formatting to lib/*
This commit is contained in:
@@ -27,14 +27,17 @@ class TopicUploadSecurityManager
|
||||
Rails.logger.debug("Updating upload security in topic #{@topic.id} - post #{post.id}")
|
||||
post.topic = @topic
|
||||
|
||||
secure_status_did_change = post.owned_uploads_via_access_control.any? do |upload|
|
||||
# we have already got the post preloaded so we may as well
|
||||
# attach it here to avoid another load in UploadSecurity
|
||||
upload.access_control_post = post
|
||||
upload.update_secure_status(source: "topic upload security")
|
||||
end
|
||||
secure_status_did_change =
|
||||
post.owned_uploads_via_access_control.any? do |upload|
|
||||
# we have already got the post preloaded so we may as well
|
||||
# attach it here to avoid another load in UploadSecurity
|
||||
upload.access_control_post = post
|
||||
upload.update_secure_status(source: "topic upload security")
|
||||
end
|
||||
post.rebake! if secure_status_did_change
|
||||
Rails.logger.debug("Security updated & rebake complete in topic #{@topic.id} - post #{post.id}")
|
||||
Rails.logger.debug(
|
||||
"Security updated & rebake complete in topic #{@topic.id} - post #{post.id}",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -55,21 +58,27 @@ class TopicUploadSecurityManager
|
||||
# -> a topic is moved from a private to a public category
|
||||
posts_with_unowned_uploads.each do |post|
|
||||
Post.transaction do
|
||||
Rails.logger.debug("Setting upload access control posts in topic #{@topic.id} - post #{post.id}")
|
||||
Rails.logger.debug(
|
||||
"Setting upload access control posts in topic #{@topic.id} - post #{post.id}",
|
||||
)
|
||||
post.topic = @topic
|
||||
|
||||
secure_status_did_change = post.uploads.any? do |upload|
|
||||
first_post_upload_appeared_in = upload.upload_references.where(target_type: 'Post').first.target
|
||||
if first_post_upload_appeared_in == post
|
||||
upload.update(access_control_post: post)
|
||||
upload.update_secure_status(source: "topic upload security")
|
||||
else
|
||||
false
|
||||
secure_status_did_change =
|
||||
post.uploads.any? do |upload|
|
||||
first_post_upload_appeared_in =
|
||||
upload.upload_references.where(target_type: "Post").first.target
|
||||
if first_post_upload_appeared_in == post
|
||||
upload.update(access_control_post: post)
|
||||
upload.update_secure_status(source: "topic upload security")
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
post.rebake! if secure_status_did_change
|
||||
Rails.logger.debug("Completed changing access control posts #{secure_status_did_change ? 'and rebaking' : ''} in topic #{@topic.id} - post #{post.id}")
|
||||
Rails.logger.debug(
|
||||
"Completed changing access control posts #{secure_status_did_change ? "and rebaking" : ""} in topic #{@topic.id} - post #{post.id}",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -79,15 +88,17 @@ class TopicUploadSecurityManager
|
||||
private
|
||||
|
||||
def posts_owning_uploads
|
||||
Post.where(topic_id: @topic.id).joins('INNER JOIN uploads ON access_control_post_id = posts.id')
|
||||
Post.where(topic_id: @topic.id).joins("INNER JOIN uploads ON access_control_post_id = posts.id")
|
||||
end
|
||||
|
||||
def posts_with_unowned_uploads
|
||||
Post
|
||||
.where(topic_id: @topic.id)
|
||||
.joins("INNER JOIN upload_references ON upload_references.target_type = 'Post' AND upload_references.target_id = posts.id")
|
||||
.joins('INNER JOIN uploads ON upload_references.upload_id = uploads.id')
|
||||
.where('uploads.access_control_post_id IS NULL')
|
||||
.joins(
|
||||
"INNER JOIN upload_references ON upload_references.target_type = 'Post' AND upload_references.target_id = posts.id",
|
||||
)
|
||||
.joins("INNER JOIN uploads ON upload_references.upload_id = uploads.id")
|
||||
.where("uploads.access_control_post_id IS NULL")
|
||||
.includes(:uploads)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user