Skip to content

Commit

Permalink
DEV: Add skip_email_bulk_invites hidden site setting (discourse#26430)
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
jbrw authored Mar 29, 2024
1 parent 95e4b53 commit 74d55f1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/jobs/regular/bulk_invite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def execute(args)
@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)
Expand Down Expand Up @@ -168,7 +170,12 @@ def send_invite(invite)
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]
Expand Down
4 changes: 4 additions & 0 deletions config/site_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2858,6 +2858,10 @@ uncategorized:
default: 50000
hidden: true

skip_email_bulk_invites:
default: false
hidden: true

max_api_invites:
default: 200
hidden: true
Expand Down
9 changes: 9 additions & 0 deletions spec/jobs/bulk_invite_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,14 @@
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

0 comments on commit 74d55f1

Please sign in to comment.