diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
commit | 05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch) | |
tree | 11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /db/fixtures/development/35_emails.rb | |
parent | ec73467c23693d0db63a797d10194da9e72a74af (diff) |
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'db/fixtures/development/35_emails.rb')
-rw-r--r-- | db/fixtures/development/35_emails.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/db/fixtures/development/35_emails.rb b/db/fixtures/development/35_emails.rb new file mode 100644 index 00000000000..a743c326015 --- /dev/null +++ b/db/fixtures/development/35_emails.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +class Gitlab::Seeder::Emails + attr_reader :user, :group_namespace_ids, :project_namespace_ids + + def initialize(user, group_namespace_ids, project_namespace_ids) + @user = user + @group_namespace_ids = group_namespace_ids.sample(3) + @project_namespace_ids = project_namespace_ids.sample(3) + end + + def seed! + company_email = "#{user.username}-work@example.com" + personal_email = "#{user.username}-home@example.com" + oss_email = "#{user.username}-oss@example.com" + unverified_email = "#{user.username}-unverified@example.com" + + Email.create!( + user_id: user.id, + email: unverified_email + ) + + [company_email, personal_email, oss_email].each_with_index do |email, index| + email_id = Email.create!( + user_id: user.id, + email: email, + confirmed_at: DateTime.current + ).id + Users::NamespaceCommitEmail.create!( + user_id: user.id, + namespace_id: group_namespace_ids[index], + email_id: email_id + ) + Users::NamespaceCommitEmail.create!( + user_id: user.id, + namespace_id: project_namespace_ids[index], + email_id: email_id + ) + print '.' + end + end +end + +Gitlab::Seeder.quiet do + puts "\nGenerating email data" + + group_namespace_ids = Group.not_mass_generated.where('parent_id IS NULL').pluck(:id) + project_namespace_ids = Project.all.pluck(:project_namespace_id) + + User.first(3).each do |user| + Gitlab::Seeder::Emails.new(user, group_namespace_ids, project_namespace_ids).seed! + rescue => e + warn "\nError seeding e-mails: #{e}" + end +end |