Commit b7e44a48 authored by Dmytro Zaporozhets's avatar Dmytro Zaporozhets

Merge branch '210025-migrate-ghost-to-user-type' into 'master'

First part of transition from ghost boolean column to user_type

See merge request gitlab-org/gitlab!27387
parents 37c5bbb9 6c0f4d05
...@@ -613,7 +613,7 @@ class User < ApplicationRecord ...@@ -613,7 +613,7 @@ class User < ApplicationRecord
# owns records previously belonging to deleted users. # owns records previously belonging to deleted users.
def ghost def ghost
email = 'ghost%s@example.com' email = 'ghost%s@example.com'
unique_internal(where(ghost: true), 'ghost', email) do |u| unique_internal(where(ghost: true, user_type: :ghost), 'ghost', email) do |u|
u.bio = _('This is a "Ghost User", created to hold all issues authored by users that have since been deleted. This user cannot be removed.') u.bio = _('This is a "Ghost User", created to hold all issues authored by users that have since been deleted. This user cannot be removed.')
u.name = 'Ghost User' u.name = 'Ghost User'
end end
...@@ -651,6 +651,13 @@ class User < ApplicationRecord ...@@ -651,6 +651,13 @@ class User < ApplicationRecord
ghost? || bot? ghost? || bot?
end end
# We are transitioning from ghost boolean column to user_type
# so we need to read from old column for now
# @see https://gitlab.com/gitlab-org/gitlab/-/issues/210025
def ghost?
ghost
end
def self.internal def self.internal
where(ghost: true).or(bots) where(ghost: true).or(bots)
end end
......
...@@ -2,13 +2,11 @@ ...@@ -2,13 +2,11 @@
module UserTypeEnums module UserTypeEnums
def self.types def self.types
bots.merge(human: nil) @types ||= bots.merge(human: nil, ghost: 5)
end end
def self.bots def self.bots
{ @bots ||= { alert_bot: 2 }.with_indifferent_access
alert_bot: 2
}.with_indifferent_access
end end
end end
......
---
title: Fill user_type for ghost users
merge_request: 27387
author:
type: other
# frozen_string_literal: true
class FillGhostUserType < ActiveRecord::Migration[6.0]
DOWNTIME = false
def up
execute('UPDATE users SET user_type = 5 WHERE ghost IS TRUE AND user_type IS NULL')
end
def down
execute('UPDATE users SET user_type = NULL WHERE ghost IS TRUE AND user_type IS NOT NULL')
end
end
...@@ -9,12 +9,12 @@ module EE ...@@ -9,12 +9,12 @@ module EE
override :types override :types
def types def types
super.merge(service_user: 4) @types ||= super.merge(service_user: 4)
end end
override :bots override :bots
def bots def bots
super.merge(support_bot: 1, visual_review_bot: 3) @bots ||= super.merge(support_bot: 1, visual_review_bot: 3)
end end
end end
end end
......
...@@ -3134,6 +3134,8 @@ describe User, :do_not_mock_admin_mode do ...@@ -3134,6 +3134,8 @@ describe User, :do_not_mock_admin_mode do
expect(ghost).to be_persisted expect(ghost).to be_persisted
expect(ghost.namespace).not_to be_nil expect(ghost.namespace).not_to be_nil
expect(ghost.namespace).to be_persisted expect(ghost.namespace).to be_persisted
expect(ghost.user_type).to eq 'ghost'
expect(ghost.ghost).to eq true
end end
it "does not create a second ghost user if one is already present" do it "does not create a second ghost user if one is already present" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment