The discussion revolves around an issue where custom fields are not being preserved in the :approved_post event for reviewable posts. fzngagan reports that custom fields are available in the NewPostManager handler but not in the :approved_post callback, citing the polls plugin as an example where this should work. zogstrip requests code to reproduce the issue. eviltrout identifies a potential bug, noting that NewPostManager arguments aren’t automatically stored in the reviewable’s payload. Roman confirms the bug and provides a fix in a PR, adding a new interface to extend allowed attributes. fzngagan thanks the team, and merefield praises the effort. fzngagan asks about backporting, but merefield notes the fix is already on tests-passed.
I am trying to save custom fields for a post that needs review. When I approve the post, the custom fields don’t get saved.
I checked the :approved_post event and the custom fields aren’t getting set in the payload.
How to preserve custom fields for reviewable posts.
Also, I used NewPostManager, and there in the handler, the custom fields are available, but ofcourse it gets triggered before saving the data to reviewables.
I’m fixing an issue with events plugin where the events data in the post_custom_field doesn’t get saved if the category is set to require approval for topics.
I reffered to the polls plugin and there it seems that the custom fields are being set on :appoved_post.
this is the snippet from polls.
NewPostManager.add_handler(1) do |manager|
post = Post.new(raw: manager.args[:raw])
if !DiscoursePoll::PollsValidator.new(post).validate_polls
result = NewPostResult.new(:poll, false)
post.errors.full_messages.each do |message|
result.errors[:base] << message
end
result
else
manager.args["is_poll"] = true
nil
end
end
on(:approved_post) do |queued_post, created_post|
if queued_post.payload["is_poll"]
created_post.validate_polls(true)
end
end
In my attempt, the custom fields data is available at, NewPostManager, but the ReviewableQueuedPost instance in the callback of :approved_post (which ideally should have the custom field in its payload) doesn’t have it.
I tried
NewPostManager.add_handler do |manager|
if manager.args['event'] && NewPostManager.post_needs_approval?(manager) # this condition stands true
manager.args['is_event'] = true
end
then
on(:approved_post) do |reviewable, post|
p reviewable.payload['is_event'] #data isn't available here
end
This is interesting because I would not expect the polls to work here either. The args passed to manager are not automatically put into the reviewable’s payload.
I suspect there’s a bug here with polls and queued posts. I suspect validate_polls is never called after approval. @Roman can you look into it?
@Roman, Do you think this feature needs to be backported?
I think it should be so that people on tests-passed and release branches can also benifit. I think some if not most plugins that use `post_custom_fields’ need to handle this edge case.