DEV: Add skip_email_bulk_invites hidden site setting (#26430)

This adds a hidden site setting of `skip_email_bulk_invites`

If set to `true`, the `BulkInvite` job will pass the value to `Invite`, meaning the generated invite wont trigger an email notification being sent to the newly invited user.

(This is useful if you want to manage the sending of the invite emails outside of Discourse.)
This commit is contained in:
jbrw 2024-03-29 13:22:00 -04:00 committed by GitHub
parent 95e4b53aab
commit 74d55f14fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 1 deletions

View File

@ -24,6 +24,8 @@ module Jobs
@current_user = User.find_by(id: args[:current_user_id])
raise Discourse::InvalidParameters.new(:current_user_id) unless @current_user
@skip_email = SiteSetting.skip_email_bulk_invites
@guardian = Guardian.new(@current_user)
process_invites(@invites)
@ -168,7 +170,12 @@ module Jobs
user.save!
end
invite_opts = { email: email, topic: topic, group_ids: groups.map(&:id) }
invite_opts = {
email: email,
topic: topic,
group_ids: groups.map(&:id),
skip_email: @skip_email,
}
if @invites.length > Invite::BULK_INVITE_EMAIL_LIMIT
invite_opts[:emailed_status] = Invite.emailed_status_types[:bulk_pending]

View File

@ -2858,6 +2858,10 @@ uncategorized:
default: 50000
hidden: true
skip_email_bulk_invites:
default: false
hidden: true
max_api_invites:
default: 200
hidden: true

View File

@ -141,5 +141,14 @@ RSpec.describe Jobs::BulkInvite do
expect(Jobs::ProcessBulkInviteEmails.jobs.size).to eq(1)
end
end
it "does not send an invite email when skip_email_bulk_invites is true" do
SiteSetting.skip_email_bulk_invites = true
described_class.new.execute(current_user_id: admin.id, invites: invites)
invite = Invite.last
expect(invite.emailed_status).to eq(Invite.emailed_status_types[:not_required])
end
end
end