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
255be6c5
Commit
255be6c5
authored
Aug 09, 2017
by
Michael Kozono
Committed by
Robert Speicher
Aug 09, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent user from changing username with container registry tags
parent
a0fa59f6
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
1 deletion
+24
-1
app/models/user.rb
app/models/user.rb
+8
-0
changelogs/unreleased/mk-validate-username-change-with-container-registry-tags.yml
...validate-username-change-with-container-registry-tags.yml
+4
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+11
-0
spec/serializers/pipeline_serializer_spec.rb
spec/serializers/pipeline_serializer_spec.rb
+1
-1
No files found.
app/models/user.rb
View file @
255be6c5
...
...
@@ -148,6 +148,8 @@ class User < ActiveRecord::Base
uniqueness:
{
case_sensitive:
false
}
validate
:namespace_uniq
,
if: :username_changed?
validate
:namespace_move_dir_allowed
,
if: :username_changed?
validate
:avatar_type
,
if:
->
(
user
)
{
user
.
avatar
.
present?
&&
user
.
avatar_changed?
}
validate
:unique_email
,
if: :email_changed?
validate
:owns_notification_email
,
if: :notification_email_changed?
...
...
@@ -487,6 +489,12 @@ class User < ActiveRecord::Base
end
end
def
namespace_move_dir_allowed
if
namespace
&
.
any_project_has_container_registry_tags?
errors
.
add
(
:username
,
'cannot be changed if a personal project has container registry tags.'
)
end
end
def
avatar_type
unless
avatar
.
image?
errors
.
add
:avatar
,
"only images allowed"
...
...
changelogs/unreleased/mk-validate-username-change-with-container-registry-tags.yml
0 → 100644
View file @
255be6c5
---
title
:
Add missing validation error for username change with container registry tags
merge_request
:
13356
author
:
spec/models/user_spec.rb
View file @
255be6c5
...
...
@@ -118,6 +118,17 @@ describe User do
expect
(
user
).
to
validate_uniqueness_of
(
:username
).
case_insensitive
end
context
'when username is changed'
do
let
(
:user
)
{
build_stubbed
(
:user
,
username:
'old_path'
,
namespace:
build_stubbed
(
: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
)
user
.
username
=
'new_path'
expect
(
user
).
to
be_invalid
expect
(
user
.
errors
.
messages
[
:username
].
first
).
to
match
(
'cannot be changed if a personal project has container registry tags'
)
end
end
end
it
{
is_expected
.
to
validate_presence_of
(
:projects_limit
)
}
...
...
spec/serializers/pipeline_serializer_spec.rb
View file @
255be6c5
...
...
@@ -111,7 +111,7 @@ describe PipelineSerializer do
shared_examples
'no N+1 queries'
do
it
'verifies number of queries'
,
:request_store
do
recorded
=
ActiveRecord
::
QueryRecorder
.
new
{
subject
}
expect
(
recorded
.
count
).
to
be_within
(
1
).
of
(
5
9
)
expect
(
recorded
.
count
).
to
be_within
(
1
).
of
(
5
7
)
expect
(
recorded
.
cached_count
).
to
eq
(
0
)
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