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
iv
gitlab-ce
Commits
3f7531d6
Commit
3f7531d6
authored
9 years ago
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move User.cleanup_username to Namespace.cleanup_path.
parent
28592ae4
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
39 deletions
+42
-39
app/models/namespace.rb
app/models/namespace.rb
+31
-12
app/models/user.rb
app/models/user.rb
+0
-16
lib/gitlab/oauth/user.rb
lib/gitlab/oauth/user.rb
+1
-1
spec/models/namespace_spec.rb
spec/models/namespace_spec.rb
+10
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+0
-10
No files found.
app/models/namespace.rb
View file @
3f7531d6
...
...
@@ -44,23 +44,42 @@ class Namespace < ActiveRecord::Base
scope
:root
,
->
{
where
(
'type IS NULL'
)
}
def
self
.
by_path
(
path
)
class
<<
self
def
by_path
(
path
)
where
(
'lower(path) = :value'
,
value:
path
.
downcase
).
first
end
# Case insensetive search for namespace by path or name
def
self
.
find_by_path_or_name
(
path
)
def
find_by_path_or_name
(
path
)
find_by
(
"lower(path) = :path OR lower(name) = :path"
,
path:
path
.
downcase
)
end
def
self
.
search
(
query
)
def
search
(
query
)
where
(
"name LIKE :query OR path LIKE :query"
,
query:
"%
#{
query
}
%"
)
end
def
self
.
global_id
def
global_id
'GLN'
end
def
clean_path
(
path
)
path
.
gsub!
(
/@.*\z/
,
""
)
path
.
gsub!
(
/\.git\z/
,
""
)
path
.
gsub!
(
/\A-/
,
""
)
path
.
gsub!
(
/\z./
,
""
)
path
.
gsub!
(
/[^a-zA-Z0-9_\-\.]/
,
""
)
counter
=
0
base
=
path
while
Namespace
.
by_path
(
path
).
present?
counter
+=
1
path
=
"
#{
base
}#{
counter
}
"
end
path
end
end
def
to_param
path
end
...
...
This diff is collapsed.
Click to expand it.
app/models/user.rb
View file @
3f7531d6
...
...
@@ -229,22 +229,6 @@ class User < ActiveRecord::Base
def
build_user
(
attrs
=
{})
User
.
new
(
attrs
)
end
def
clean_username
(
username
)
username
.
gsub!
(
/@.*\z/
,
""
)
username
.
gsub!
(
/\.git\z/
,
""
)
username
.
gsub!
(
/\A-/
,
""
)
username
.
gsub!
(
/[^a-zA-Z0-9_\-\.]/
,
""
)
counter
=
0
base
=
username
while
User
.
by_login
(
username
).
present?
||
Namespace
.
by_path
(
username
).
present?
counter
+=
1
username
=
"
#{
base
}#{
counter
}
"
end
username
end
end
#
...
...
This diff is collapsed.
Click to expand it.
lib/gitlab/oauth/user.rb
View file @
3f7531d6
...
...
@@ -86,7 +86,7 @@ module Gitlab
def
user_attributes
{
name:
auth_hash
.
name
,
username:
::
User
.
clean_username
(
auth_hash
.
username
),
username:
::
Namespace
.
clean_path
(
auth_hash
.
username
),
email:
auth_hash
.
email
,
password:
auth_hash
.
password
,
password_confirmation:
auth_hash
.
password
,
...
...
This diff is collapsed.
Click to expand it.
spec/models/namespace_spec.rb
View file @
3f7531d6
...
...
@@ -85,4 +85,14 @@ describe Namespace do
it
{
expect
(
Namespace
.
find_by_path_or_name
(
'WOW'
)).
to
eq
(
@namespace
)
}
it
{
expect
(
Namespace
.
find_by_path_or_name
(
'unknown'
)).
to
eq
(
nil
)
}
end
describe
".clean_path"
do
let!
(
:user
)
{
create
(
:user
,
username:
"johngitlab-etc"
)
}
let!
(
:namespace
)
{
create
(
:namespace
,
path:
"JohnGitLab-etc1"
)
}
it
"cleans the path and makes sure it's available"
do
expect
(
Namespace
.
clean_path
(
"-john+gitlab-ETC%.git@gmail.com"
)).
to
eq
(
"johngitlab-ETC2"
)
end
end
end
This diff is collapsed.
Click to expand it.
spec/models/user_spec.rb
View file @
3f7531d6
...
...
@@ -307,16 +307,6 @@ describe User do
end
end
describe
".clean_username"
do
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"
)
end
end
describe
'all_ssh_keys'
do
it
{
is_expected
.
to
have_many
(
:keys
).
dependent
(
:destroy
)
}
...
...
This diff is collapsed.
Click to expand it.
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