FIX: Add users to user directory on account activation (#28505)

Follow-up to e3ae57ea7a

The previous commit added an `after_create` callback that triggers a refresh for the user directory whenever a `User` record is created. Theoretically, this approach should work, however, there's a gotcha in practice, because during a real user registration, when the `User` record is created in the database, it's not marked as active until the user verifies their email address and the user directory excludes inactive users, so the initial directory refresh triggered by the `after_create` callback becomes pointless.

To make a new user appear in the user directory immediately after sign up, we need to trigger a refresh via an `after_save` callback when they verify their email address and become active.
This commit is contained in:
Osama Sayegh
2024-08-26 18:01:24 +03:00
committed by GitHub
parent cda596601b
commit 5eea7244c7
4 changed files with 64 additions and 41 deletions

View File

@ -129,27 +129,6 @@ RSpec.describe User do
) { user.update(name: "Batman") }
end
end
describe "#refresh_user_directory" do
context "when bootstrap mode is enabled" do
before { SiteSetting.bootstrap_mode_enabled = true }
it "creates directory items for a new user for all periods" do
expect do user = Fabricate(:user) end.to change { DirectoryItem.count }.by(
DirectoryItem.period_types.count,
)
expect(DirectoryItem.where(user_id: user.id)).to exist
end
end
context "when bootstrap mode is disabled" do
before { SiteSetting.bootstrap_mode_enabled = false }
it "doesn't create directory items for a new user" do
expect do Fabricate(:user) end.not_to change { DirectoryItem.count }
end
end
end
end
describe "Validations" do