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
c6a22cae
Commit
c6a22cae
authored
Sep 29, 2021
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UserNamespace should be created for new users
as opposed to a generic Namespace
parent
2e1f033e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
8 deletions
+21
-8
app/models/namespace.rb
app/models/namespace.rb
+2
-0
app/models/user.rb
app/models/user.rb
+12
-4
spec/factories/namespaces.rb
spec/factories/namespaces.rb
+2
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+5
-4
No files found.
app/models/namespace.rb
View file @
c6a22cae
...
...
@@ -44,6 +44,8 @@ class Namespace < ApplicationRecord
# This should _not_ be `inverse_of: :namespace`, because that would also set
# `user.namespace` when this user creates a group with themselves as `owner`.
# TODO: can this be moved into the UserNamespace class?
# evaluate in issue https://gitlab.com/gitlab-org/gitlab/-/issues/341070
belongs_to
:owner
,
class_name:
"User"
belongs_to
:parent
,
class_name:
"Namespace"
...
...
app/models/user.rb
View file @
c6a22cae
...
...
@@ -112,9 +112,14 @@ class User < ApplicationRecord
#
# Namespace for personal projects
# TODO: change to `type: Namespaces::UserNamespace.sti_name` when
# working on issue https://gitlab.com/gitlab-org/gitlab/-/issues/341070
has_one
:namespace
,
->
{
where
(
type:
[
nil
,
Namespaces
::
UserNamespace
.
sti_name
])
},
dependent: :destroy
,
foreign_key: :owner_id
,
inverse_of: :owner
,
autosave:
true
# rubocop:disable Cop/ActiveRecordDependent
# TODO: change to `:namespace, -> { where(type: Namespaces::UserNamespace.sti_name}, class_name: 'Namespaces::UserNamespace'...`
# when working on issue https://gitlab.com/gitlab-org/gitlab/-/issues/341070
has_one
:namespace
,
->
{
where
(
type:
[
nil
,
Namespaces
::
UserNamespace
.
sti_name
])
},
dependent: :destroy
,
# rubocop:disable Cop/ActiveRecordDependent
foreign_key: :owner_id
,
inverse_of: :owner
,
autosave:
true
# rubocop:disable Cop/ActiveRecordDependent
# Profile
has_many
:keys
,
->
{
regular_keys
},
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
...
...
@@ -1437,7 +1442,10 @@ class User < ApplicationRecord
namespace
.
path
=
username
if
username_changed?
namespace
.
name
=
name
if
name_changed?
else
namespace
=
build_namespace
(
path:
username
,
name:
name
)
# TODO: we should no longer need the `type` parameter once we can make the
# the `has_one :namespace` association use the correct class.
# issue https://gitlab.com/gitlab-org/gitlab/-/issues/341070
namespace
=
build_namespace
(
path:
username
,
name:
name
,
type:
::
Namespaces
::
UserNamespace
.
sti_name
)
namespace
.
build_namespace_settings
end
end
...
...
spec/factories/namespaces.rb
View file @
c6a22cae
...
...
@@ -5,6 +5,8 @@ FactoryBot.define do
sequence
(
:name
)
{
|
n
|
"namespace
#{
n
}
"
}
path
{
name
.
downcase
.
gsub
(
/\s/
,
'_'
)
}
# TODO: can this be moved into the :user_namespace factory?
# evaluate in issue https://gitlab.com/gitlab-org/gitlab/-/issues/341070
owner
{
association
(
:user
,
strategy: :build
,
namespace:
instance
,
username:
path
)
}
trait
:with_aggregation_schedule
do
...
...
spec/models/user_spec.rb
View file @
c6a22cae
...
...
@@ -378,7 +378,7 @@ RSpec.describe User do
end
context
'when username is changed'
do
let
(
:user
)
{
build_stubbed
(
:user
,
username:
'old_path'
,
namespace:
build_stubbed
(
:namespace
))
}
let
(
:user
)
{
build_stubbed
(
:user
,
username:
'old_path'
,
namespace:
build_stubbed
(
:
user_
namespace
))
}
it
'validates move_dir is allowed for the namespace'
do
expect
(
user
.
namespace
).
to
receive
(
:any_project_has_container_registry_tags?
).
and_return
(
true
)
...
...
@@ -3853,7 +3853,7 @@ RSpec.describe User do
end
context
'with runner in a personal project'
do
let!
(
:namespace
)
{
create
(
:namespace
,
owner:
user
)
}
let!
(
:namespace
)
{
create
(
:
user_
namespace
,
owner:
user
)
}
let!
(
:project
)
{
create
(
:project
,
namespace:
namespace
)
}
let!
(
:runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
project
])
}
...
...
@@ -3921,7 +3921,7 @@ RSpec.describe User do
end
context
'with personal project runner in an owned group in an owned namespace and a group runner in that group'
do
let!
(
:namespace
)
{
create
(
:namespace
,
owner:
user
)
}
let!
(
:namespace
)
{
create
(
:
user_
namespace
,
owner:
user
)
}
let!
(
:group
)
{
create
(
:group
)
}
let!
(
:group_runner
)
{
create
(
:ci_runner
,
:group
,
groups:
[
group
])
}
let!
(
:project
)
{
create
(
:project
,
namespace:
namespace
,
group:
group
)
}
...
...
@@ -3935,7 +3935,7 @@ RSpec.describe User do
end
context
'with personal project runner in an owned namespace, an owned group, a subgroup and a group runner in that subgroup'
do
let!
(
:namespace
)
{
create
(
:namespace
,
owner:
user
)
}
let!
(
:namespace
)
{
create
(
:
user_
namespace
,
owner:
user
)
}
let!
(
:group
)
{
create
(
:group
)
}
let!
(
:subgroup
)
{
create
(
:group
,
parent:
group
)
}
let!
(
:group_runner
)
{
create
(
:ci_runner
,
:group
,
groups:
[
subgroup
])
}
...
...
@@ -4617,6 +4617,7 @@ RSpec.describe User do
user
.
save!
expect
(
user
.
namespace
).
not_to
be_nil
expect
(
user
.
namespace
).
to
be_kind_of
(
Namespaces
::
UserNamespace
)
end
it
'creates the namespace setting'
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