diff --git a/app/models/email_token.rb b/app/models/email_token.rb index 4feea3fa5a1..00e91a4f95a 100644 --- a/app/models/email_token.rb +++ b/app/models/email_token.rb @@ -72,6 +72,7 @@ class EmailToken < ActiveRecord::Base user.save! user.create_reviewable unless skip_reviewable user.set_automatic_groups + DiscourseEvent.trigger(:user_confirmed_email, user) end if user diff --git a/config/initializers/012-web_hook_events.rb b/config/initializers/012-web_hook_events.rb index 29e543982de..e7620933332 100644 --- a/config/initializers/012-web_hook_events.rb +++ b/config/initializers/012-web_hook_events.rb @@ -41,6 +41,7 @@ end user_logged_in user_approved user_updated + user_confirmed_email ).each do |event| DiscourseEvent.on(event) do |user| WebHook.enqueue_object_hooks(:user, user, event) diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 51f9e64b250..c9daee0143c 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -3999,7 +3999,7 @@ en: details: "When there is a new reply, edit, deleted or recovered." user_event: name: "User Event" - details: "When a user logs in, logs out, is created, approved or updated." + details: "When a user logs in, logs out, confirms their email, is created, approved or updated." group_event: name: "Group Event" details: "When a group is created, updated or destroyed." diff --git a/spec/models/web_hook_spec.rb b/spec/models/web_hook_spec.rb index 6f67fce731c..f6b873aaee8 100644 --- a/spec/models/web_hook_spec.rb +++ b/spec/models/web_hook_spec.rb @@ -324,7 +324,6 @@ describe WebHook do Fabricate(:user_web_hook, active: true) user - user.activate Jobs::CreateUserReviewable.new.execute(user_id: user.id) job_args = Jobs::EmitWebHookEvent.jobs.last["args"].first @@ -333,6 +332,14 @@ describe WebHook do payload = JSON.parse(job_args["payload"]) expect(payload["id"]).to eq(user.id) + email_token = user.email_tokens.create(email: user.email) + EmailToken.confirm(email_token.token) + job_args = Jobs::EmitWebHookEvent.jobs.last["args"].first + + expect(job_args["event_name"]).to eq("user_confirmed_email") + payload = JSON.parse(job_args["payload"]) + expect(payload["id"]).to eq(user.id) + admin job_args = Jobs::EmitWebHookEvent.jobs.last["args"].first diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index 938a7d34caf..31c8b0750fe 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -230,7 +230,7 @@ describe UsersController do end expect(events.map { |event| event[:event_name] }).to contain_exactly( - :user_logged_in, :user_first_logged_in + :user_logged_in, :user_first_logged_in, :user_confirmed_email ) expect(response.status).to eq(200)