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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
a2071f2b
Commit
a2071f2b
authored
Apr 19, 2018
by
Rubén Dávila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix missing namespace for some internal users
parent
ff778061
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
113 additions
and
0 deletions
+113
-0
changelogs/unreleased/rd-44635-error-500-when-clicking-ghost-user-or-gitlab-support-bot-in-ui.yml
...-when-clicking-ghost-user-or-gitlab-support-bot-in-ui.yml
+5
-0
db/migrate/20180413022611_create_missing_namespace_for_internal_users.rb
...0413022611_create_missing_namespace_for_internal_users.rb
+66
-0
spec/migrations/create_missing_namespace_for_internal_users_spec.rb
...tions/create_missing_namespace_for_internal_users_spec.rb
+42
-0
No files found.
changelogs/unreleased/rd-44635-error-500-when-clicking-ghost-user-or-gitlab-support-bot-in-ui.yml
0 → 100644
View file @
a2071f2b
---
title
:
Fix missing namespace for some internal users
merge_request
:
18357
author
:
type
:
fixed
db/migrate/20180413022611_create_missing_namespace_for_internal_users.rb
0 → 100644
View file @
a2071f2b
class
CreateMissingNamespaceForInternalUsers
<
ActiveRecord
::
Migration
DOWNTIME
=
false
def
up
connection
.
exec_query
(
users_query
.
to_sql
).
rows
.
each
do
|
id
,
username
|
create_namespace
(
id
,
username
)
# When testing locally I've noticed that these internal users are missing
# the notification email, for more details visit the below link:
# https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/18357#note_68327560
set_notification_email
(
id
)
end
end
def
down
# no-op
end
private
def
users
@users
||=
Arel
::
Table
.
new
(
:users
)
end
def
namespaces
@namespaces
||=
Arel
::
Table
.
new
(
:namespaces
)
end
def
users_query
condition
=
users
[
:ghost
].
eq
(
true
)
if
column_exists?
(
:users
,
:support_bot
)
condition
=
condition
.
or
(
users
[
:support_bot
].
eq
(
true
))
end
users
.
join
(
namespaces
,
Arel
::
Nodes
::
OuterJoin
)
.
on
(
namespaces
[
:type
].
eq
(
nil
).
and
(
namespaces
[
:owner_id
].
eq
(
users
[
:id
])))
.
where
(
namespaces
[
:owner_id
].
eq
(
nil
))
.
where
(
condition
)
.
project
(
users
[
:id
],
users
[
:username
])
end
def
create_namespace
(
user_id
,
username
)
path
=
Uniquify
.
new
.
string
(
username
)
do
|
str
|
query
=
"SELECT id FROM namespaces WHERE parent_id IS NULL AND path='
#{
str
}
' LIMIT 1"
connection
.
exec_query
(
query
).
present?
end
insert_query
=
"INSERT INTO namespaces(owner_id, path, name) VALUES(
#{
user_id
}
, '
#{
path
}
', '
#{
path
}
')"
namespace_id
=
connection
.
insert_sql
(
insert_query
)
create_route
(
namespace_id
)
end
def
create_route
(
namespace_id
)
return
unless
namespace_id
row
=
connection
.
exec_query
(
"SELECT id, path FROM namespaces WHERE id=
#{
namespace_id
}
"
).
first
id
,
path
=
row
.
values_at
(
'id'
,
'path'
)
execute
(
"INSERT INTO routes(source_id, source_type, path, name) VALUES(
#{
id
}
, 'Namespace', '
#{
path
}
', '
#{
path
}
')"
)
end
def
set_notification_email
(
user_id
)
execute
"UPDATE users SET notification_email = email WHERE notification_email IS NULL AND id =
#{
user_id
}
"
end
end
spec/migrations/create_missing_namespace_for_internal_users_spec.rb
0 → 100644
View file @
a2071f2b
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'migrate'
,
'20180413022611_create_missing_namespace_for_internal_users.rb'
)
describe
CreateMissingNamespaceForInternalUsers
,
:migration
do
let
(
:users
)
{
table
(
:users
)
}
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:routes
)
{
table
(
:routes
)
}
internal_user_types
=
[
:ghost
]
internal_user_types
<<
:support_bot
if
ActiveRecord
::
Base
.
connection
.
column_exists?
(
:users
,
:support_bot
)
internal_user_types
.
each
do
|
attr
|
context
"for
#{
attr
}
user"
do
let
(
:internal_user
)
do
users
.
create!
(
email:
'test@example.com'
,
projects_limit:
100
,
username:
'test'
,
attr
=>
true
)
end
it
'creates the missing namespace'
do
expect
(
namespaces
.
find_by
(
owner_id:
internal_user
.
id
)).
to
be_nil
migrate!
namespace
=
Namespace
.
find_by
(
type:
nil
,
owner_id:
internal_user
.
id
)
route
=
namespace
.
route
expect
(
namespace
.
path
).
to
eq
(
route
.
path
)
expect
(
namespace
.
name
).
to
eq
(
route
.
name
)
end
it
'sets notification email'
do
users
.
update
(
internal_user
.
id
,
notification_email:
nil
)
expect
(
users
.
find
(
internal_user
.
id
).
notification_email
).
to
be_nil
migrate!
user
=
users
.
find
(
internal_user
.
id
)
expect
(
user
.
notification_email
).
to
eq
(
user
.
email
)
end
end
end
end
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