mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-18 22:48:32 +08:00
This node allows to display a modal to a specific user and react to the answer of the user. It requires the user to be actually on the discourse site. <img width="2089" height="876" alt="Screenshot 2026-06-17 at 11 31 28" src="https://github.com/user-attachments/assets/abc40762-eb8e-445e-80b6-1a24bc3c54ea" /> <img width="281" height="237" alt="Screenshot 2026-06-17 at 11 31 21" src="https://github.com/user-attachments/assets/481a9cfa-9d6b-40a9-a593-458a99d9f50a" />
47 lines
1.5 KiB
Ruby
Vendored
47 lines
1.5 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
RSpec.describe CurrentUserSerializer do
|
|
fab!(:admin)
|
|
fab!(:user)
|
|
|
|
before { DiscourseWorkflows::WorkflowDependency.clear_cache! }
|
|
|
|
def serialized(target)
|
|
JSON.parse(described_class.new(target, scope: Guardian.new(target), root: false).to_json)
|
|
end
|
|
|
|
def index_modal_workflow
|
|
graph =
|
|
build_workflow_graph do |g|
|
|
g.node "t1", "trigger:manual"
|
|
g.node "m1",
|
|
"action:modal",
|
|
configuration: {
|
|
"title" => "Approve?",
|
|
"buttons" => {
|
|
"values" => [{ "label" => "Approve", "value" => "approve" }],
|
|
},
|
|
}
|
|
g.chain "t1", "m1"
|
|
end
|
|
workflow = Fabricate(:discourse_workflows_workflow, created_by: admin, **graph)
|
|
version = workflow.workflow_versions.find_by(version_id: workflow.version_id)
|
|
DiscourseWorkflows::WorkflowDependencyIndexer.call(workflow, version: version)
|
|
end
|
|
|
|
describe "discourse_workflows_user_modal_last_id" do
|
|
it "is omitted when no workflow uses a modal node" do
|
|
expect(serialized(user)).not_to have_key("discourse_workflows_user_modal_last_id")
|
|
end
|
|
|
|
it "is the channel's last id when a workflow uses a modal node" do
|
|
index_modal_workflow
|
|
channel = DiscourseWorkflows::Nodes::Modal::V1.user_channel(user.id)
|
|
MessageBus.publish(channel, { type: "show_modal" }, user_ids: [user.id])
|
|
|
|
payload = serialized(user)
|
|
|
|
expect(payload["discourse_workflows_user_modal_last_id"]).to eq(MessageBus.last_id(channel))
|
|
end
|
|
end
|
|
end
|