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
59606cbc
Commit
59606cbc
authored
Jun 17, 2020
by
Maxime Orefice
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Merge branch '215315-repository-identifier' into 'master'"
This reverts merge request !30279
parent
2304a32e
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
24 additions
and
154 deletions
+24
-154
app/models/concerns/route_model_query.rb
app/models/concerns/route_model_query.rb
+0
-19
app/models/redirect_route.rb
app/models/redirect_route.rb
+0
-2
app/models/route.rb
app/models/route.rb
+0
-1
app/models/snippet.rb
app/models/snippet.rb
+1
-5
ee/lib/ee/gitlab/repo_path.rb
ee/lib/ee/gitlab/repo_path.rb
+2
-5
ee/spec/lib/ee/gitlab/repo_path_spec.rb
ee/spec/lib/ee/gitlab/repo_path_spec.rb
+5
-29
ee/spec/requests/api/internal/base_spec.rb
ee/spec/requests/api/internal/base_spec.rb
+1
-1
lib/gitlab/repo_path.rb
lib/gitlab/repo_path.rb
+11
-24
spec/lib/gitlab/repo_path_spec.rb
spec/lib/gitlab/repo_path_spec.rb
+4
-14
spec/models/concerns/route_model_query_spec.rb
spec/models/concerns/route_model_query_spec.rb
+0
-28
spec/models/snippet_spec.rb
spec/models/snippet_spec.rb
+0
-26
No files found.
app/models/concerns/route_model_query.rb
deleted
100644 → 0
View file @
2304a32e
# frozen_string_literal: true
# Shared scope between Route and RedirectRoute
module
RouteModelQuery
extend
ActiveSupport
::
Concern
class_methods
do
def
find_source_of_path
(
path
,
case_sensitive:
true
)
scope
=
if
case_sensitive
where
(
path:
path
)
else
where
(
'LOWER(path) = LOWER(?)'
,
path
)
end
scope
.
first
&
.
source
end
end
end
app/models/redirect_route.rb
View file @
59606cbc
# frozen_string_literal: true
# frozen_string_literal: true
class
RedirectRoute
<
ApplicationRecord
class
RedirectRoute
<
ApplicationRecord
include
RouteModelQuery
belongs_to
:source
,
polymorphic:
true
# rubocop:disable Cop/PolymorphicAssociations
belongs_to
:source
,
polymorphic:
true
# rubocop:disable Cop/PolymorphicAssociations
validates
:source
,
presence:
true
validates
:source
,
presence:
true
...
...
app/models/route.rb
View file @
59606cbc
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
class
Route
<
ApplicationRecord
class
Route
<
ApplicationRecord
include
CaseSensitivity
include
CaseSensitivity
include
Gitlab
::
SQL
::
Pattern
include
Gitlab
::
SQL
::
Pattern
include
RouteModelQuery
belongs_to
:source
,
polymorphic:
true
# rubocop:disable Cop/PolymorphicAssociations
belongs_to
:source
,
polymorphic:
true
# rubocop:disable Cop/PolymorphicAssociations
validates
:source
,
presence:
true
validates
:source
,
presence:
true
...
...
app/models/snippet.rb
View file @
59606cbc
...
@@ -167,11 +167,7 @@ class Snippet < ApplicationRecord
...
@@ -167,11 +167,7 @@ class Snippet < ApplicationRecord
end
end
def
self
.
find_by_id_and_project
(
id
:,
project
:)
def
self
.
find_by_id_and_project
(
id
:,
project
:)
if
project
.
is_a?
(
Project
)
Snippet
.
find_by
(
id:
id
,
project:
project
)
ProjectSnippet
.
find_by
(
id:
id
,
project:
project
)
elsif
project
.
nil?
PersonalSnippet
.
find_by
(
id:
id
)
end
end
end
def
self
.
max_file_limit
(
user
)
def
self
.
max_file_limit
(
user
)
...
...
ee/lib/ee/gitlab/repo_path.rb
View file @
59606cbc
...
@@ -4,13 +4,10 @@ module EE
...
@@ -4,13 +4,10 @@ module EE
module
Gitlab
module
Gitlab
module
RepoPath
module
RepoPath
module
ClassMethods
module
ClassMethods
extend
::
Gitlab
::
Utils
::
Override
def
find_project
(
project_path
)
override
:find_routes_source
def
find_routes_source
(
path
,
*
args
)
return
super
unless
License
.
feature_available?
(
:project_aliases
)
return
super
unless
License
.
feature_available?
(
:project_aliases
)
if
project_alias
=
ProjectAlias
.
find_by_name
(
path
)
if
project_alias
=
ProjectAlias
.
find_by_name
(
p
roject_p
ath
)
[
project_alias
.
project
,
nil
]
[
project_alias
.
project
,
nil
]
else
else
super
super
...
...
ee/spec/lib/ee/gitlab/repo_path_spec.rb
View file @
59606cbc
...
@@ -3,17 +3,7 @@
...
@@ -3,17 +3,7 @@
require
'spec_helper'
require
'spec_helper'
RSpec
.
describe
Gitlab
::
RepoPath
do
RSpec
.
describe
Gitlab
::
RepoPath
do
let_it_be
(
:group
)
{
create
(
:group
)
}
describe
'.find_project'
do
let_it_be
(
:group_redirect_route
)
{
'foo/bar/baz'
}
let_it_be
(
:group_redirect
)
{
group
.
route
.
create_redirect
(
group_redirect_route
)
}
describe
'.parse'
do
it
'parses a full path of group wiki'
do
expect
(
described_class
.
parse
(
group
.
wiki
.
repository
.
full_path
)).
to
eq
([
group
,
nil
,
Gitlab
::
GlRepository
::
WIKI
,
nil
])
end
end
describe
'.find_routes_source'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
context
'without premium license'
do
context
'without premium license'
do
...
@@ -21,7 +11,7 @@ RSpec.describe Gitlab::RepoPath do
...
@@ -21,7 +11,7 @@ RSpec.describe Gitlab::RepoPath do
let
(
:project_alias
)
{
create
(
:project_alias
,
project:
project
)
}
let
(
:project_alias
)
{
create
(
:project_alias
,
project:
project
)
}
it
'does not return a project'
do
it
'does not return a project'
do
expect
(
described_class
.
find_
routes_source
(
project_alias
.
name
)).
to
eq
([
nil
,
nil
])
expect
(
described_class
.
find_
project
(
project_alias
.
name
)).
to
eq
([
nil
,
nil
])
end
end
end
end
end
end
...
@@ -35,36 +25,22 @@ RSpec.describe Gitlab::RepoPath do
...
@@ -35,36 +25,22 @@ RSpec.describe Gitlab::RepoPath do
let
(
:project_alias
)
{
create
(
:project_alias
,
project:
project
)
}
let
(
:project_alias
)
{
create
(
:project_alias
,
project:
project
)
}
it
'returns the project'
do
it
'returns the project'
do
expect
(
described_class
.
find_
routes_source
(
project_alias
.
name
)).
to
eq
([
project
,
nil
])
expect
(
described_class
.
find_
project
(
project_alias
.
name
)).
to
eq
([
project
,
nil
])
end
end
end
end
context
'project_path does not match a project alias'
do
context
'project_path does not match a project alias'
do
context
'project path matches project full path'
do
context
'project path matches project full path'
do
it
'returns the project'
do
it
'returns the project'
do
expect
(
described_class
.
find_
routes_source
(
project
.
full_path
)).
to
eq
([
project
,
nil
])
expect
(
described_class
.
find_
project
(
project
.
full_path
)).
to
eq
([
project
,
nil
])
end
end
end
end
context
'project path does not match an existing project full path'
do
context
'project path does not match an existing project full path'
do
it
'returns nil'
do
it
'returns nil'
do
expect
(
described_class
.
find_routes_source
(
'some-project'
)).
to
eq
([
nil
,
nil
])
expect
(
described_class
.
find_project
(
'some-project'
)).
to
eq
([
nil
,
nil
])
end
end
end
end
end
end
context
'when target is a group'
do
context
'when finding by canonical path'
do
it
'returns the group and nil'
do
expect
(
described_class
.
find_routes_source
(
group
.
full_path
)).
to
eq
([
group
,
nil
])
end
end
context
'when finding via a redirect'
do
it
'returns the group and redirect path'
do
expect
(
described_class
.
find_routes_source
(
group_redirect
.
path
)).
to
eq
([
group
,
group_redirect_route
])
end
end
end
end
end
end
end
...
...
ee/spec/requests/api/internal/base_spec.rb
View file @
59606cbc
...
@@ -256,7 +256,7 @@ RSpec.describe API::Internal::Base do
...
@@ -256,7 +256,7 @@ RSpec.describe API::Internal::Base do
end
end
it
'returns the repository_http_path at the primary node'
do
it
'returns the repository_http_path at the primary node'
do
expect
(
Route
).
to
receive
(
:find_source_of
_path
).
and_return
(
project
)
expect
(
Project
).
to
receive
(
:find_by_full
_path
).
and_return
(
project
)
lfs_auth_user
(
user
.
id
,
project
)
lfs_auth_user
(
user
.
id
,
project
)
...
...
lib/gitlab/repo_path.rb
View file @
59606cbc
...
@@ -4,11 +4,6 @@ module Gitlab
...
@@ -4,11 +4,6 @@ module Gitlab
module
RepoPath
module
RepoPath
NotFoundError
=
Class
.
new
(
StandardError
)
NotFoundError
=
Class
.
new
(
StandardError
)
# @return [Array]
# 1. container (ActiveRecord which holds repository)
# 2. project (Project)
# 3. repo_type
# 4. redirected_path
def
self
.
parse
(
path
)
def
self
.
parse
(
path
)
repo_path
=
path
.
sub
(
/\.git\z/
,
''
).
sub
(
%r{
\A
/}
,
''
)
repo_path
=
path
.
sub
(
/\.git\z/
,
''
).
sub
(
%r{
\A
/}
,
''
)
redirected_path
=
nil
redirected_path
=
nil
...
@@ -22,7 +17,7 @@ module Gitlab
...
@@ -22,7 +17,7 @@ module Gitlab
# `Gitlab::GlRepository::PROJECT` type.
# `Gitlab::GlRepository::PROJECT` type.
next
unless
type
.
valid?
(
repo_path
)
next
unless
type
.
valid?
(
repo_path
)
# Removing the suffix (.wiki, .design, ...) from path
# Removing the suffix (.wiki, .design, ...) from
the project
path
full_path
=
repo_path
.
chomp
(
type
.
path_suffix
)
full_path
=
repo_path
.
chomp
(
type
.
path_suffix
)
container
,
project
,
redirected_path
=
find_container
(
type
,
full_path
)
container
,
project
,
redirected_path
=
find_container
(
type
,
full_path
)
...
@@ -41,31 +36,23 @@ module Gitlab
...
@@ -41,31 +36,23 @@ module Gitlab
[
snippet
,
snippet
&
.
project
,
redirected_path
]
[
snippet
,
snippet
&
.
project
,
redirected_path
]
else
else
container
,
redirected_path
=
find_routes_source
(
full_path
)
project
,
redirected_path
=
find_project
(
full_path
)
if
container
.
is_a?
(
Project
)
[
project
,
project
,
redirected_path
]
[
container
,
container
,
redirected_path
]
else
[
container
,
nil
,
redirected_path
]
end
end
end
end
end
def
self
.
find_routes_source
(
path
)
def
self
.
find_project
(
project_path
)
return
[
nil
,
nil
]
if
path
.
blank?
return
[
nil
,
nil
]
if
project_path
.
blank?
source
=
Route
.
find_source_of_path
(
path
)
||
Route
.
find_source_of_path
(
path
,
case_sensitive:
false
)
||
RedirectRoute
.
find_source_of_path
(
path
,
case_sensitive:
false
)
redirected_path
=
redirected?
(
source
,
path
)
?
path
:
nil
project
=
Project
.
find_by_full_path
(
project_path
,
follow_redirects:
true
)
redirected_path
=
redirected?
(
project
,
project_path
)
?
project_path
:
nil
[
source
,
redirected_path
]
[
project
,
redirected_path
]
end
end
def
self
.
redirected?
(
container
,
container
_path
)
def
self
.
redirected?
(
project
,
project
_path
)
container
&&
container
.
full_path
.
casecmp
(
container
_path
)
!=
0
project
&&
project
.
full_path
.
casecmp
(
project
_path
)
!=
0
end
end
# Snippet_path can be either:
# Snippet_path can be either:
...
@@ -75,7 +62,7 @@ module Gitlab
...
@@ -75,7 +62,7 @@ module Gitlab
return
[
nil
,
nil
]
if
snippet_path
.
blank?
return
[
nil
,
nil
]
if
snippet_path
.
blank?
snippet_id
,
project_path
=
extract_snippet_info
(
snippet_path
)
snippet_id
,
project_path
=
extract_snippet_info
(
snippet_path
)
project
,
redirected_path
=
find_
routes_source
(
project_path
)
project
,
redirected_path
=
find_
project
(
project_path
)
[
Snippet
.
find_by_id_and_project
(
id:
snippet_id
,
project:
project
),
redirected_path
]
[
Snippet
.
find_by_id_and_project
(
id:
snippet_id
,
project:
project
),
redirected_path
]
end
end
...
...
spec/lib/gitlab/repo_path_spec.rb
View file @
59606cbc
...
@@ -67,11 +67,11 @@ describe ::Gitlab::RepoPath do
...
@@ -67,11 +67,11 @@ describe ::Gitlab::RepoPath do
end
end
end
end
describe
'.find_
routes_source
'
do
describe
'.find_
project
'
do
context
'when finding a project by its canonical path'
do
context
'when finding a project by its canonical path'
do
context
'when the cases match'
do
context
'when the cases match'
do
it
'returns the project and nil'
do
it
'returns the project and nil'
do
expect
(
described_class
.
find_
routes_source
(
project
.
full_path
)).
to
eq
([
project
,
nil
])
expect
(
described_class
.
find_
project
(
project
.
full_path
)).
to
eq
([
project
,
nil
])
end
end
end
end
...
@@ -81,14 +81,14 @@ describe ::Gitlab::RepoPath do
...
@@ -81,14 +81,14 @@ describe ::Gitlab::RepoPath do
# requests, we should accept wrongly-cased URLs because it is a pain to
# requests, we should accept wrongly-cased URLs because it is a pain to
# block people's git operations and force them to update remote URLs.
# block people's git operations and force them to update remote URLs.
it
'returns the project and nil'
do
it
'returns the project and nil'
do
expect
(
described_class
.
find_
routes_source
(
project
.
full_path
.
upcase
)).
to
eq
([
project
,
nil
])
expect
(
described_class
.
find_
project
(
project
.
full_path
.
upcase
)).
to
eq
([
project
,
nil
])
end
end
end
end
end
end
context
'when finding a project via a redirect'
do
context
'when finding a project via a redirect'
do
it
'returns the project and nil'
do
it
'returns the project and nil'
do
expect
(
described_class
.
find_
routes_source
(
redirect
.
path
)).
to
eq
([
project
,
redirect
.
path
])
expect
(
described_class
.
find_
project
(
redirect
.
path
)).
to
eq
([
project
,
redirect
.
path
])
end
end
end
end
end
end
...
@@ -110,16 +110,6 @@ describe ::Gitlab::RepoPath do
...
@@ -110,16 +110,6 @@ describe ::Gitlab::RepoPath do
end
end
end
end
context
'when path is namespace path, but has same id as project'
do
let
(
:namespace
)
{
build_stubbed
(
:namespace
,
id:
project
.
id
)
}
it
'returns nil if path is referring to namespace'
do
allow
(
described_class
).
to
receive
(
:find_route_source
).
and_return
(
namespace
)
expect
(
described_class
.
find_snippet
(
"
#{
namespace
.
full_path
}
/snippets/
#{
project_snippet
.
id
}
"
)).
to
eq
([
nil
,
nil
])
end
end
it
'returns nil for snippets not associated with the project'
do
it
'returns nil for snippets not associated with the project'
do
snippet
=
create
(
:project_snippet
)
snippet
=
create
(
:project_snippet
)
...
...
spec/models/concerns/route_model_query_spec.rb
deleted
100644 → 0
View file @
2304a32e
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Route
,
'RouteModelQuery'
,
:aggregate_failures
do
let_it_be
(
:group1
)
{
create
(
:group
,
path:
'Group1'
)
}
let_it_be
(
:group2
)
{
create
(
:group
,
path:
'Group2'
)
}
let_it_be
(
:project1
)
{
create
(
:project
,
path:
'Project1'
,
group:
group1
)
}
let_it_be
(
:project2
)
{
create
(
:project
,
path:
'Project2'
,
group:
group2
)
}
describe
'.find_source_of_path'
do
it
'finds exact match'
do
expect
(
described_class
.
find_source_of_path
(
'Group1'
)).
to
eq
(
group1
)
expect
(
described_class
.
find_source_of_path
(
'Group2/Project2'
)).
to
eq
(
project2
)
expect
(
described_class
.
find_source_of_path
(
'GROUP1'
)).
to
be_nil
expect
(
described_class
.
find_source_of_path
(
'GROUP2/PROJECT2'
)).
to
be_nil
end
it
'finds case insensitive match'
do
expect
(
described_class
.
find_source_of_path
(
'Group1'
,
case_sensitive:
false
)).
to
eq
(
group1
)
expect
(
described_class
.
find_source_of_path
(
'Group2/Project2'
,
case_sensitive:
false
)).
to
eq
(
project2
)
expect
(
described_class
.
find_source_of_path
(
'GROUP1'
,
case_sensitive:
false
)).
to
eq
(
group1
)
expect
(
described_class
.
find_source_of_path
(
'GROUP2/PROJECT2'
,
case_sensitive:
false
)).
to
eq
(
project2
)
end
end
end
spec/models/snippet_spec.rb
View file @
59606cbc
...
@@ -206,32 +206,6 @@ describe Snippet do
...
@@ -206,32 +206,6 @@ describe Snippet do
end
end
end
end
describe
'.find_by_id_and_project'
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:project_snippet
)
{
create
(
:project_snippet
,
project:
project
)
}
let_it_be
(
:personal_snippet
)
{
create
(
:personal_snippet
)
}
context
'when project is provided'
do
it
'returns ProjectSnippet'
do
expect
(
described_class
.
find_by_id_and_project
(
id:
project_snippet
.
id
,
project:
project
)).
to
eq
(
project_snippet
)
end
end
context
'when project is nil'
do
it
'returns PersonalSnippet'
do
expect
(
described_class
.
find_by_id_and_project
(
id:
personal_snippet
.
id
,
project:
nil
)).
to
eq
(
personal_snippet
)
end
end
context
'when project variable is not a Project'
do
let
(
:namespace
)
{
build_stubbed
(
:namespace
,
id:
project
.
id
)
}
it
'returns nil'
do
expect
(
described_class
.
find_by_id_and_project
(
id:
project_snippet
.
id
,
project:
namespace
)).
to
be_nil
end
end
end
describe
'.with_optional_visibility'
do
describe
'.with_optional_visibility'
do
context
'when a visibility level is provided'
do
context
'when a visibility level is provided'
do
it
'returns snippets with the given visibility'
do
it
'returns snippets with the given visibility'
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