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
Kazuhiko Shiozaki
gitlab-ce
Commits
161d1554
Commit
161d1554
authored
Feb 13, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent autogenerated OAuth username to clash with existing namespace.
parent
529188e4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
4 deletions
+9
-4
app/models/namespace.rb
app/models/namespace.rb
+4
-0
app/models/user.rb
app/models/user.rb
+3
-2
spec/models/user_spec.rb
spec/models/user_spec.rb
+2
-2
No files found.
app/models/namespace.rb
View file @
161d1554
...
...
@@ -44,6 +44,10 @@ class Namespace < ActiveRecord::Base
scope
:root
,
->
{
where
(
'type IS NULL'
)
}
def
self
.
by_path
(
path
)
where
(
'lower(path) = :value'
,
value:
path
.
downcase
).
first
end
def
self
.
search
(
query
)
where
(
"name LIKE :query OR path LIKE :query"
,
query:
"%
#{
query
}
%"
)
end
...
...
app/models/user.rb
View file @
161d1554
...
...
@@ -252,7 +252,7 @@ class User < ActiveRecord::Base
counter
=
0
base
=
username
while
by_login
(
username
).
present?
while
User
.
by_login
(
username
).
present?
||
Namespace
.
by_path
(
username
).
present?
counter
+=
1
username
=
"
#{
base
}#{
counter
}
"
end
...
...
@@ -290,7 +290,8 @@ class User < ActiveRecord::Base
def
namespace_uniq
namespace_name
=
self
.
username
if
Namespace
.
find_by
(
path:
namespace_name
)
existing_namespace
=
Namespace
.
by_path
(
namespace_name
)
if
existing_namespace
&&
existing_namespace
!=
self
.
namespace
self
.
errors
.
add
:username
,
"already exists"
end
end
...
...
spec/models/user_spec.rb
View file @
161d1554
...
...
@@ -303,8 +303,8 @@ describe User do
describe
".clean_username"
do
let!
(
:user
1
)
{
create
(
:user
,
username:
"johngitlab-etc"
)
}
let!
(
:
user2
)
{
create
(
:user
,
username
:
"JohnGitLab-etc1"
)
}
let!
(
:user
)
{
create
(
:user
,
username:
"johngitlab-etc"
)
}
let!
(
:
namespace
)
{
create
(
:namespace
,
path
:
"JohnGitLab-etc1"
)
}
it
"cleans a username and makes sure it's available"
do
expect
(
User
.
clean_username
(
"-john+gitlab-ETC%.git@gmail.com"
)).
to
eq
(
"johngitlab-ETC2"
)
...
...
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