mirror of
https://github.com/discourse/discourse.git
synced 2026-08-09 21:45:25 +08:00
The "Encrypts PM if available" checkbox in automation script options was a leftover from the discourse-encrypt plugin, which was archived almost a year ago. Since `EncryptedPostCreator` no longer exists, the option had no effect - the code always fell back to using the regular `PostCreator`. This removes all traces of the `prefers_encrypt` feature: - The checkbox UI in the PM field component - The `prefers_encrypt` parameter from `Utils.send_pm` - References in send_pms and gift_exchange scripts - The column from the pending_pms table (via post-deploy migration) - Associated translations and tests The column removal follows the standard two-phase approach: first declaring `ignored_columns` in the model, then dropping the column in a post-deploy migration. Ref - https://meta.discourse.org/t/-/392664
54 lines
1.6 KiB
Ruby
Vendored
54 lines
1.6 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
DiscourseAutomation::Scriptable.add(DiscourseAutomation::Scripts::SEND_PMS) do
|
|
version 1
|
|
|
|
placeholder :sender_username
|
|
placeholder :receiver_username
|
|
|
|
field :sender, component: :user
|
|
field :receiver, component: :user, triggerable: :recurring
|
|
field :sendable_pms, component: :pms, accepts_placeholders: true, required: true
|
|
|
|
triggerables %i[
|
|
user_badge_granted
|
|
user_added_to_group
|
|
stalled_wiki
|
|
recurring
|
|
user_promoted
|
|
api_call
|
|
user_removed_from_group
|
|
]
|
|
|
|
script do |context, fields, automation|
|
|
sender_username = fields.dig("sender", "value") || Discourse.system_user.username
|
|
|
|
placeholders = { sender_username: sender_username }.merge(context["placeholders"] || {})
|
|
|
|
usernames = context["usernames"] || []
|
|
|
|
# optional field when using recurring triggerable
|
|
if u = fields.dig("receiver", "value")
|
|
usernames << u
|
|
end
|
|
|
|
usernames.compact.uniq.each do |username|
|
|
placeholders[:receiver_username] = username
|
|
Array(fields.dig("sendable_pms", "value")).each do |sendable|
|
|
next if !sendable["title"] || !sendable["raw"]
|
|
|
|
pm = {}
|
|
pm["title"] = utils.apply_placeholders(sendable["title"], placeholders)
|
|
pm["raw"] = utils.apply_placeholders(sendable["raw"], placeholders)
|
|
pm["target_usernames"] = Array(username)
|
|
|
|
utils.send_pm(
|
|
pm,
|
|
sender: sender_username,
|
|
automation_id: automation.id,
|
|
delay: sendable["delay"],
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|