Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
6c0f4d05
Commit
6c0f4d05
authored
Mar 13, 2020
by
Pavel Shutsin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Transition from ghost boolean column to user_type
Part 1: double write for ghost attribute
parent
7bd06449
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
32 additions
and
7 deletions
+32
-7
app/models/user.rb
app/models/user.rb
+8
-1
app/models/user_type_enums.rb
app/models/user_type_enums.rb
+2
-4
changelogs/unreleased/210025-migrate-ghost-to-user-type.yml
changelogs/unreleased/210025-migrate-ghost-to-user-type.yml
+5
-0
db/migrate/20200313101649_fill_ghost_user_type.rb
db/migrate/20200313101649_fill_ghost_user_type.rb
+13
-0
ee/app/models/ee/user_type_enums.rb
ee/app/models/ee/user_type_enums.rb
+2
-2
spec/models/user_spec.rb
spec/models/user_spec.rb
+2
-0
No files found.
app/models/user.rb
View file @
6c0f4d05
...
...
@@ -612,7 +612,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
...
...
@@ -650,6 +650,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
...
...
app/models/user_type_enums.rb
View file @
6c0f4d05
...
...
@@ -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
...
...
changelogs/unreleased/210025-migrate-ghost-to-user-type.yml
0 → 100644
View file @
6c0f4d05
---
title
:
Fill user_type for ghost users
merge_request
:
27387
author
:
type
:
other
db/migrate/20200313101649_fill_ghost_user_type.rb
0 → 100644
View file @
6c0f4d05
# 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
ee/app/models/ee/user_type_enums.rb
View file @
6c0f4d05
...
...
@@ -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
...
...
spec/models/user_spec.rb
View file @
6c0f4d05
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment