FEATURE: User fields required for existing users - Part 2 (#27172)

We want to allow admins to make new required fields apply to existing users. In order for this to work we need to have a way to make those users fill up the fields on their next page load. This is very similar to how adding a 2FA requirement post-fact works. Users will be redirected to a page where they can fill up the remaining required fields, and until they do that they won't be able to do anything else.
This commit is contained in:
Ted Johansson
2024-06-25 19:32:18 +08:00
committed by GitHub
parent 867b3822f3
commit d63f1826fe
51 changed files with 661 additions and 209 deletions

View File

@ -602,40 +602,61 @@ RSpec.describe UserUpdater do
end
end
it "logs the action" do
user = Fabricate(:user, name: "Billy Bob")
context "when updating the name" do
it "logs the action" do
user = Fabricate(:user, name: "Billy Bob")
expect do UserUpdater.new(user, user).update(name: "Jim Tom") end.to change {
UserHistory.count
}.by(1)
expect do UserUpdater.new(user, user).update(name: "Jim Tom") end.to change {
UserHistory.count
}.by(1)
expect(UserHistory.last.action).to eq(UserHistory.actions[:change_name])
expect(UserHistory.last.action).to eq(UserHistory.actions[:change_name])
expect do UserUpdater.new(user, user).update(name: "JiM TOm") end.to_not change {
UserHistory.count
}
expect do UserUpdater.new(user, user).update(name: "JiM TOm") end.to_not change {
UserHistory.count
}
expect do UserUpdater.new(user, user).update(bio_raw: "foo bar") end.to_not change {
UserHistory.count
}
expect do UserUpdater.new(user, user).update(bio_raw: "foo bar") end.to_not change {
UserHistory.count
}
user_without_name = Fabricate(:user, name: nil)
user_without_name = Fabricate(:user, name: nil)
expect do
UserUpdater.new(user_without_name, user_without_name).update(bio_raw: "foo bar")
end.to_not change { UserHistory.count }
expect do
UserUpdater.new(user_without_name, user_without_name).update(bio_raw: "foo bar")
end.to_not change { UserHistory.count }
expect do
UserUpdater.new(user_without_name, user_without_name).update(name: "Jim Tom")
end.to change { UserHistory.count }.by(1)
expect do
UserUpdater.new(user_without_name, user_without_name).update(name: "Jim Tom")
end.to change { UserHistory.count }.by(1)
expect(UserHistory.last.action).to eq(UserHistory.actions[:change_name])
expect(UserHistory.last.action).to eq(UserHistory.actions[:change_name])
expect do UserUpdater.new(user, user).update(name: "") end.to change { UserHistory.count }.by(
1,
)
expect do UserUpdater.new(user, user).update(name: "") end.to change {
UserHistory.count
}.by(1)
expect(UserHistory.last.action).to eq(UserHistory.actions[:change_name])
expect(UserHistory.last.action).to eq(UserHistory.actions[:change_name])
end
end
context "when updating required fields" do
it "logs the action" do
user = Fabricate(:user)
Fabricate(:user_field, name: "favorite_pokemon", requirement: "for_all_users")
UserRequiredFieldsVersion.create!
expect do
UserUpdater.new(user, user).update(custom_fields: { "favorite_pokemon" => "Mudkip" })
end.to change { UserHistory.count }.by(1)
user.bump_required_fields_version
expect do
UserUpdater.new(user, user).update(custom_fields: { "favorite_pokemon" => "Mudkip" })
end.not_to change { UserHistory.count }
end
end
it "clears the homepage_id when the special 'custom' id is chosen" do