j127
7 Agosto, 2019 08:48
1
Does anyone know how to query staff notes notices from the database? I’ve been looking around in the code but haven’t been able to find where they are stored.
My main goal is to find a specific staff notice that was written in the past week, so I’m looking for a way to skim through the recent custom ones.
Edit: I was having trouble, because I was looking for “staff notes”. I’ve just found a custom_field that might be what I’m looking for, but I’m not sure how to list all the staff notices with custom text.
pry(main)> p.custom_fields
=> {"notice_type"=>"new_user"}
tgxworld
(Alan Tan)
7 Agosto, 2019 08:53
2
PlugintStoreRow.where(plugin_name: "user_notes") is probably what you’re looking for
2 Me gusta
j127
7 Agosto, 2019 08:56
3
Thanks, I’m looking for “staff notices” (core feature), which I think is different from “user notes” (separate plugin). I might be confused though.
The item named “Add Staff Notice”:
2 Me gusta
tgxworld
(Alan Tan)
7 Agosto, 2019 11:45
4
It should be in the custom fields like you’ve mentioned
def notice
raise Discourse::NotFound unless guardian.is_staff?
post = find_post_from_params
if params[:notice].present?
post.custom_fields["notice_type"] = Post.notices[:custom]
post.custom_fields["notice_args"] = PrettyText.cook(params[:notice], features: { onebox: false })
post.save_custom_fields
else
post.delete_post_notices
end
render body: nil
end
4 Me gusta
j127
8 Agosto, 2019 06:40
5
Thanks. In case anyone else is looking for a quick way to skim the data, this works in the Rails console:
results = Post.all.reject { |p| p.custom_fields['notice_type'].nil? }
results.each do |r|
puts r.custom_fields
end
Sample output:
{"notice_type"=>"returning_user", "notice_args"=>"2018-08-04T07:43:52Z"}
{"notice_type"=>"new_user"}
{"notice_type"=>"new_user"}
{"notice_type"=>"new_user"}
{"notice_type"=>"returning_user", "notice_args"=>"2016-10-11T09:32:30Z"}
{"notice_type"=>"returning_user", "notice_args"=>"2014-04-02T16:16:04Z"}
{"notice_type"=>"new_user"}
{"notice_type"=>"new_user"}
I don’t see any custom text there, so I guess the staff notice I was looking for isn’t live.
2 Me gusta
system
(system)
Cerrado
7 Septiembre, 2019 06:40
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.