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
# owns records previously belonging to deleted users.
def ghost
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.name = 'Ghost User'
end
......@@ -651,6 +651,13 @@ class User < ApplicationRecord
ghost? || bot?
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
where(ghost: true).or(bots)
end
......
......@@ -2,13 +2,11 @@
module UserTypeEnums
def self.types
bots.merge(human: nil)
@types ||= bots.merge(human: nil, ghost: 5)
end
def self.bots
{
alert_bot: 2
}.with_indifferent_access
@bots ||= { alert_bot: 2 }.with_indifferent_access
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
override :types
def types
super.merge(service_user: 4)
@types ||= super.merge(service_user: 4)
end
override :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
......
......@@ -3134,6 +3134,8 @@ describe User, :do_not_mock_admin_mode do
expect(ghost).to be_persisted
expect(ghost.namespace).not_to be_nil
expect(ghost.namespace).to be_persisted
expect(ghost.user_type).to eq 'ghost'
expect(ghost.ghost).to eq true
end
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