Skip to content

Set detumbled_email address before saving emails

Ian Anderson requested to merge ia-normalize-all-email-addresses into master

What does this MR do and why?

Relates to https://gitlab.com/gitlab-org/modelops/anti-abuse/team-tasks/-/work_items/827

This MR adds a before_save hook to the Email model that sets the detumbled_email attribute. This attribute will be used to identify duplicate email addresses when alternative addressing schemes are used. Gmail addresses are normalized by removing the . character and everything between the + and the @ character in an email address. For example, test.user+gitlab@gmail.com will become testuser@gmail.com when normalized. Non-Gmail addresses only strip the characters between the + and @ characters, so test.user+gitlab@example.com will be normalized to test.user@example.com.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. In rails console enable the experiment fully
    Feature.enable(:store_detumbled_email)
  2. Create a user with an alternative gmail address and confirm the user. The detumbled_email attribute should be present in the email record.
    admin = User.first
    user = Users::CreateService.new(admin, { name: 'new_user123', username: "new_user123", email: "new.user123+gitlab@gmail.com", password: "asdfasdf123"}).execute 
    user.confirm
    user.emails.first.detumbled_email
    => "newuser123@gmail.com"
  3. Create another user with an alternative email address from a non-gmail domain. The detumbled_email should still contain the . characters.
    user = Users::CreateService.new(admin, { name: 'new_user456', username: "new_user456", email: "new.user456+gitlab@example.com", password: "asdfasdf123"}).execute 
    user.confirm
    user.emails.first.detumbled_email
    => "new.user456@example.com"
Edited by Ian Anderson

Merge request reports

Loading