mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-19 07:43:46 +08:00
Promotes the posts query-string filter that previously lived in
discourse-ai's `Research::Filter` to a core `PostsFilter` class so it
can
be shared across core and plugins. The parser gains alias support
(`categories`, `exclude_category`, `exclude_tag`, `created_after`, ...),
`-`/`=`/`-=` exclusion prefixes, an `option_info` helper for
autocomplete,
and an `add_filter`/`remove_filter` extension API backed by a new
`posts_filter_options` plugin modifier.
Consumers are updated to build on the shared class:
* discourse-ai: `Research::Filter` becomes a thin subclass, the
researcher
tool documents the new exclusion syntax, and the report context
generator builds its relation from a PostsFilter query string instead of
hand-rolled SQL.
* discourse-assign: registers an `assigned_to:` filter (supporting
`nobody`, `*` and usernames) and contributes its autocomplete entry.
* discourse-workflows: adds an `action:post` node with create/get/list
operations built on PostsFilter, and extracts a shared `PostHelper`
mixin
reused by the existing create_post node.
Adds core locale strings and specs for the new class.
We also added two new APIs to node context to facilitate working with
posts:
#### `exec_ctx.create_post`
Creates a post while enforcing workflow actor permissions and preventing
recursive workflow execution.
```rb
post =
exec_ctx.create_post(
user: author,
raw: "Reply body",
topic_id: topic_id,
reply_to_post_number: reply_to_post_number,
)
```
Arguments:
- `user:` required `User` object used as the post author.
- `raw:` required raw post body.
- `topic_id:` required topic id where the post should be created.
- `reply_to_post_number:` optional post number to reply to.
The helper verifies that the author can see the topic, rejects closed or
archived topics, and creates the post with `skip_workflows: true`.
#### `exec_ctx.serialize_post`
Serializes a post into the standard Discourse Workflows post output
shape.
```rb
data =
exec_ctx.serialize_post(
post,
guardian: actor.guardian,
include_raw: true,
include_cooked: false,
)
```
Arguments:
- `post` required `Post` record.
- `guardian:` optional guardian used for permission-aware fields such as
visible tags. Defaults to the system guardian.
- `include_raw:` optional boolean. Defaults to `true`.
- `include_cooked:` optional boolean. Defaults to `false`.
Use this helper whenever a workflow node outputs post data. It keeps
post outputs consistent across action and trigger nodes.
---------
Co-authored-by: discourse-patch-triage[bot] <272280883+discourse-patch-triage[bot]@users.noreply.github.com>
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
|
||
|---|---|---|
| .. | ||
| llm_formatter_spec.rb | ||