mirror of
https://github.com/discourse/discourse.git
synced 2025-04-19 15:49:05 +08:00
DEV: Pass topic to TopicView.add_post_custom_fields_allowlister
(#14678)
Allows custom fields to be loaded based on the attributes of a topic.
This commit is contained in:
parent
c7703cec2f
commit
d1201d6188
@ -326,8 +326,8 @@ class Plugin::Instance
|
|||||||
# Add a post_custom_fields_allowlister block to the TopicView, respecting if the plugin is enabled
|
# Add a post_custom_fields_allowlister block to the TopicView, respecting if the plugin is enabled
|
||||||
def topic_view_post_custom_fields_allowlister(&block)
|
def topic_view_post_custom_fields_allowlister(&block)
|
||||||
reloadable_patch do |plugin|
|
reloadable_patch do |plugin|
|
||||||
::TopicView.add_post_custom_fields_allowlister do |user|
|
::TopicView.add_post_custom_fields_allowlister do |user, topic|
|
||||||
plugin.enabled? ? block.call(user) : []
|
plugin.enabled? ? block.call(user, topic) : []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -65,8 +65,8 @@ class TopicView
|
|||||||
post_custom_fields_allowlisters << block
|
post_custom_fields_allowlisters << block
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.allowed_post_custom_fields(user)
|
def self.allowed_post_custom_fields(user, topic)
|
||||||
wpcf = default_post_custom_fields + post_custom_fields_allowlisters.map { |w| w.call(user) }
|
wpcf = default_post_custom_fields + post_custom_fields_allowlisters.map { |w| w.call(user, topic) }
|
||||||
wpcf.flatten.uniq
|
wpcf.flatten.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ class TopicView
|
|||||||
@user_custom_fields = User.custom_fields_for_ids(@posts.pluck(:user_id), added_fields)
|
@user_custom_fields = User.custom_fields_for_ids(@posts.pluck(:user_id), added_fields)
|
||||||
end
|
end
|
||||||
|
|
||||||
if (allowed_fields = TopicView.allowed_post_custom_fields(@user)).present?
|
if (allowed_fields = TopicView.allowed_post_custom_fields(@user, @topic)).present?
|
||||||
@post_custom_fields = Post.custom_fields_for_ids(@posts.pluck(:id), allowed_fields)
|
@post_custom_fields = Post.custom_fields_for_ids(@posts.pluck(:id), allowed_fields)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user