BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
2823c058
Commit
2823c058
authored
Apr 16, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
project_from_ref returns nil when reference can't be accessed
Prior it would return the project from the current context, which wasn't the intended behavior.
parent
3a0b4340
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
16 additions
and
11 deletions
+16
-11
commit_range_reference_filter.rb
lib/gitlab/markdown/commit_range_reference_filter.rb
+1
-1
commit_reference_filter.rb
lib/gitlab/markdown/commit_reference_filter.rb
+7
-1
cross_project_reference.rb
lib/gitlab/markdown/cross_project_reference.rb
+3
-4
issue_reference_filter.rb
lib/gitlab/markdown/issue_reference_filter.rb
+1
-1
merge_request_reference_filter.rb
lib/gitlab/markdown/merge_request_reference_filter.rb
+1
-1
snippet_reference_filter.rb
lib/gitlab/markdown/snippet_reference_filter.rb
+1
-1
cross_project_reference_spec.rb
spec/lib/gitlab/markdown/cross_project_reference_spec.rb
+2
-2
No files found.
lib/gitlab/markdown/commit_range_reference_filter.rb
View file @
2823c058
...
@@ -91,7 +91,7 @@ module Gitlab
...
@@ -91,7 +91,7 @@ module Gitlab
end
end
def
valid_range?
(
project
,
from_id
,
to_id
)
def
valid_range?
(
project
,
from_id
,
to_id
)
project
.
valid_repo?
&&
commit
(
from_id
)
&&
commit
(
to_id
)
project
&&
project
.
valid_repo?
&&
commit
(
from_id
)
&&
commit
(
to_id
)
end
end
def
url_for_commit_range
(
project
,
from_id
,
to_id
)
def
url_for_commit_range
(
project
,
from_id
,
to_id
)
...
...
lib/gitlab/markdown/commit_reference_filter.rb
View file @
2823c058
...
@@ -47,7 +47,7 @@ module Gitlab
...
@@ -47,7 +47,7 @@ module Gitlab
self
.
class
.
references_in
(
text
)
do
|
match
,
commit_ref
,
project_ref
|
self
.
class
.
references_in
(
text
)
do
|
match
,
commit_ref
,
project_ref
|
project
=
self
.
project_from_ref
(
project_ref
)
project
=
self
.
project_from_ref
(
project_ref
)
if
project
.
valid_repo?
&&
commit
=
project
.
repository
.
commit
(
commit_ref
)
if
commit
=
commit_from_ref
(
project
,
commit_ref
)
url
=
url_for_commit
(
project
,
commit
)
url
=
url_for_commit
(
project
,
commit
)
title
=
escape_once
(
commit
.
link_title
)
title
=
escape_once
(
commit
.
link_title
)
...
@@ -64,6 +64,12 @@ module Gitlab
...
@@ -64,6 +64,12 @@ module Gitlab
end
end
end
end
def
commit_from_ref
(
project
,
commit_ref
)
if
project
&&
project
.
valid_repo?
project
.
repository
.
commit
(
commit_ref
)
end
end
def
url_for_commit
(
project
,
commit
)
def
url_for_commit
(
project
,
commit
)
h
=
Rails
.
application
.
routes
.
url_helpers
h
=
Rails
.
application
.
routes
.
url_helpers
h
.
namespace_project_commit_url
(
project
.
namespace
,
project
,
commit
,
h
.
namespace_project_commit_url
(
project
.
namespace
,
project
,
commit
,
...
...
lib/gitlab/markdown/cross_project_reference.rb
View file @
2823c058
...
@@ -10,18 +10,17 @@ module Gitlab
...
@@ -10,18 +10,17 @@ module Gitlab
#
#
# Defaults to value of `context[:project]` if:
# Defaults to value of `context[:project]` if:
# * No reference is given OR
# * No reference is given OR
# * Reference given doesn't exist OR
# * Reference given doesn't exist
# * Reference given can't be read by the current user
#
#
# ref - String reference.
# ref - String reference.
#
#
# Returns a Project
# Returns a Project
, or nil if the reference can't be accessed
def
project_from_ref
(
ref
)
def
project_from_ref
(
ref
)
if
ref
&&
other
=
Project
.
find_with_namespace
(
ref
)
if
ref
&&
other
=
Project
.
find_with_namespace
(
ref
)
if
user_can_reference_project?
(
other
)
if
user_can_reference_project?
(
other
)
other
other
else
else
context
[
:project
]
nil
end
end
else
else
context
[
:project
]
context
[
:project
]
...
...
lib/gitlab/markdown/issue_reference_filter.rb
View file @
2823c058
...
@@ -47,7 +47,7 @@ module Gitlab
...
@@ -47,7 +47,7 @@ module Gitlab
self
.
class
.
references_in
(
text
)
do
|
match
,
issue
,
project_ref
|
self
.
class
.
references_in
(
text
)
do
|
match
,
issue
,
project_ref
|
project
=
self
.
project_from_ref
(
project_ref
)
project
=
self
.
project_from_ref
(
project_ref
)
if
project
.
issue_exists?
(
issue
)
if
project
&&
project
.
issue_exists?
(
issue
)
url
=
url_for_issue
(
issue
,
project
,
only_path:
context
[
:only_path
])
url
=
url_for_issue
(
issue
,
project
,
only_path:
context
[
:only_path
])
title
=
escape_once
(
"Issue:
#{
title_for_issue
(
issue
,
project
)
}
"
)
title
=
escape_once
(
"Issue:
#{
title_for_issue
(
issue
,
project
)
}
"
)
...
...
lib/gitlab/markdown/merge_request_reference_filter.rb
View file @
2823c058
...
@@ -47,7 +47,7 @@ module Gitlab
...
@@ -47,7 +47,7 @@ module Gitlab
self
.
class
.
references_in
(
text
)
do
|
match
,
id
,
project_ref
|
self
.
class
.
references_in
(
text
)
do
|
match
,
id
,
project_ref
|
project
=
self
.
project_from_ref
(
project_ref
)
project
=
self
.
project_from_ref
(
project_ref
)
if
merge_request
=
project
.
merge_requests
.
find_by
(
iid:
id
)
if
project
&&
merge_request
=
project
.
merge_requests
.
find_by
(
iid:
id
)
title
=
escape_once
(
"Merge Request:
#{
merge_request
.
title
}
"
)
title
=
escape_once
(
"Merge Request:
#{
merge_request
.
title
}
"
)
klass
=
reference_class
(
:merge_request
)
klass
=
reference_class
(
:merge_request
)
...
...
lib/gitlab/markdown/snippet_reference_filter.rb
View file @
2823c058
...
@@ -47,7 +47,7 @@ module Gitlab
...
@@ -47,7 +47,7 @@ module Gitlab
self
.
class
.
references_in
(
text
)
do
|
match
,
id
,
project_ref
|
self
.
class
.
references_in
(
text
)
do
|
match
,
id
,
project_ref
|
project
=
self
.
project_from_ref
(
project_ref
)
project
=
self
.
project_from_ref
(
project_ref
)
if
snippet
=
project
.
snippets
.
find_by
(
id:
id
)
if
project
&&
snippet
=
project
.
snippets
.
find_by
(
id:
id
)
title
=
escape_once
(
"Snippet:
#{
snippet
.
title
}
"
)
title
=
escape_once
(
"Snippet:
#{
snippet
.
title
}
"
)
klass
=
reference_class
(
:snippet
)
klass
=
reference_class
(
:snippet
)
...
...
spec/lib/gitlab/markdown/cross_project_reference_spec.rb
View file @
2823c058
...
@@ -37,11 +37,11 @@ module Gitlab::Markdown
...
@@ -37,11 +37,11 @@ module Gitlab::Markdown
end
end
context
'and the user does not have permission to read it'
do
context
'and the user does not have permission to read it'
do
it
'returns
the project from context
'
do
it
'returns
nil
'
do
expect
(
self
).
to
receive
(
:user_can_reference_project?
).
expect
(
self
).
to
receive
(
:user_can_reference_project?
).
with
(
project2
).
and_return
(
false
)
with
(
project2
).
and_return
(
false
)
expect
(
project_from_ref
(
'cross/reference'
)).
to
eq
context
[
:project
]
expect
(
project_from_ref
(
'cross/reference'
)).
to
be_nil
end
end
end
end
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