Luicid
(Luicid)
2023 年 10 月 2 日午前 6:06
1
こんにちは。
プラグインを構築しており、ユーザーのメールに何かを送信する必要があります。
次を使用しています。
creator = PostCreator.new(test_user, {
target_recipients: "someone@toto.com",
archetype: Archetype.private_message,
subtype: TopicSubtype.system_message,
title: "Hello test subject",
raw: "This is the message. Does it work ?"
})
test_user は管理者です。
しかし、これを使用して送信しようとするたびに、「トピックが空です 」というエラーが発生します。
何か考えはありますか?
仕様によると、グループ名またはユーザー名を受け取るはずです。
it "can send a message to a group" do
Group.refresh_automatic_groups!
group = Group.create(name: "test_group", messageable_level: Group::ALIAS_LEVELS[:nobody])
user1 = user
group.add(user1)
post "/posts.json",
params: {
raw: "I can haz a test",
title: "I loves my test",
target_recipients: group.name,
archetype: Archetype.private_message,
}
expect(response).not_to be_successful
# allow pm to this group
group.update_columns(messageable_level: Group::ALIAS_LEVELS[:everyone])
post "/posts.json",
params: {
fab!(:topic) { Fabricate(:topic) }
it "errors when creating a private post" do
user_2 = Fabricate(:user)
post "/posts.json",
params: {
raw: "this is the test content",
archetype: "private_message",
title: "this is some post",
target_recipients: user_2.username,
topic_id: topic.id,
}
expect(response.status).to eq(422)
expect(response.parsed_body["errors"]).to include(I18n.t("create_pm_on_existing_topic"))
end
end
context "with errors" do
it "does not succeed" do
「いいね!」 2
Luicid
(Luicid)
2023 年 10 月 2 日午前 7:44
3
こんにちは、ロバートさん。
それは奇妙ですね。フロントエンドでは、Discourse は次のようなペイロードを使用しており、機能しています(私のプライベートメールでテスト済み):
raw: Again a message content here.
title: Hello there general kenoby
archetype: private_message
target_recipients: j.doe@something.com
バックエンドでグループ名を期待しているのは奇妙だと思います
「いいね!」 1
RGJ
(Richard - Communiteq)
2023 年 10 月 2 日午前 10:52
4
TL;DR: target_recipients ではなく target_emails を使用してください。
target_recipients は PostsController のパラメータであり、PostCreator の引数ではないことに注意してください。
そのコントローラーは、受信者がユーザー、グループ、またはメールアドレスであるかどうかを 判断し 、最終的に NewPostsManager に target_emails として渡され、最終的に TopicCreator に渡されます。
「いいね!」 5
system
(system)
クローズされました:
2023 年 11 月 1 日午後 1:00
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.