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
Jérome Perrin
gitlab-ce
Commits
454d227b
Commit
454d227b
authored
Aug 11, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove all permission checking from Reference filters
parent
afb2e6f4
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
105 additions
and
228 deletions
+105
-228
lib/gitlab/markdown/cross_project_reference.rb
lib/gitlab/markdown/cross_project_reference.rb
+2
-9
lib/gitlab/markdown/user_reference_filter.rb
lib/gitlab/markdown/user_reference_filter.rb
+0
-6
spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
...lib/gitlab/markdown/commit_range_reference_filter_spec.rb
+18
-32
spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
+16
-30
spec/lib/gitlab/markdown/cross_project_reference_spec.rb
spec/lib/gitlab/markdown/cross_project_reference_spec.rb
+0
-12
spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
+21
-35
spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb
...ib/gitlab/markdown/merge_request_reference_filter_spec.rb
+16
-30
spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
+15
-29
spec/lib/gitlab/markdown/user_reference_filter_spec.rb
spec/lib/gitlab/markdown/user_reference_filter_spec.rb
+17
-31
spec/support/filter_spec_helper.rb
spec/support/filter_spec_helper.rb
+0
-14
No files found.
lib/gitlab/markdown/cross_project_reference.rb
View file @
454d227b
...
...
@@ -13,18 +13,11 @@ module Gitlab
#
# ref - String reference.
#
# Returns a Project, or nil if the reference can't be
accesse
d
# Returns a Project, or nil if the reference can't be
foun
d
def
project_from_ref
(
ref
)
return
context
[
:project
]
unless
ref
other
=
Project
.
find_with_namespace
(
ref
)
return
nil
unless
other
&&
user_can_reference_project?
(
other
)
other
end
def
user_can_reference_project?
(
project
,
user
=
context
[
:current_user
])
Ability
.
abilities
.
allowed?
(
user
,
:read_project
,
project
)
Project
.
find_with_namespace
(
ref
)
end
end
end
...
...
lib/gitlab/markdown/user_reference_filter.rb
View file @
454d227b
...
...
@@ -80,8 +80,6 @@ module Gitlab
end
def
link_to_group
(
group
,
namespace
)
return
unless
user_can_reference_group?
(
namespace
)
push_result
(
:user
,
*
namespace
.
users
)
url
=
urls
.
group_url
(
group
,
only_path:
context
[
:only_path
])
...
...
@@ -100,10 +98,6 @@ module Gitlab
text
=
User
.
reference_prefix
+
user
%(<a href="#{url}" #{data} class="#{link_class}">#{text}</a>)
end
def
user_can_reference_group?
(
group
)
Ability
.
abilities
.
allowed?
(
context
[
:current_user
],
:read_group
,
group
)
end
end
end
end
spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
View file @
454d227b
...
...
@@ -106,9 +106,6 @@ module Gitlab::Markdown
range
.
project
=
project2
end
context
'when user can access reference'
do
before
{
allow_cross_reference!
}
it
'links to a valid reference'
do
doc
=
filter
(
"See
#{
reference
}
"
)
...
...
@@ -136,16 +133,5 @@ module Gitlab::Markdown
expect
(
result
[
:references
][
:commit_range
]).
not_to
be_empty
end
end
context
'when user cannot access reference'
do
before
{
disallow_cross_reference!
}
it
'ignores valid references'
do
exp
=
act
=
"See
#{
reference
}
"
expect
(
filter
(
act
).
to_html
).
to
eq
exp
end
end
end
end
end
spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
View file @
454d227b
...
...
@@ -99,9 +99,6 @@ module Gitlab::Markdown
let
(
:commit
)
{
project2
.
commit
}
let
(
:reference
)
{
commit
.
to_reference
(
project
)
}
context
'when user can access reference'
do
before
{
allow_cross_reference!
}
it
'links to a valid reference'
do
doc
=
filter
(
"See
#{
reference
}
"
)
...
...
@@ -126,16 +123,5 @@ module Gitlab::Markdown
expect
(
result
[
:references
][
:commit
]).
not_to
be_empty
end
end
context
'when user cannot access reference'
do
before
{
disallow_cross_reference!
}
it
'ignores valid references'
do
exp
=
act
=
"See
#{
reference
}
"
expect
(
filter
(
act
).
to_html
).
to
eq
exp
end
end
end
end
end
spec/lib/gitlab/markdown/cross_project_reference_spec.rb
View file @
454d227b
...
...
@@ -35,21 +35,9 @@ module Gitlab::Markdown
context
'and the user has permission to read it'
do
it
'returns the referenced project'
do
expect
(
self
).
to
receive
(
:user_can_reference_project?
).
with
(
project2
).
and_return
(
true
)
expect
(
project_from_ref
(
'cross/reference'
)).
to
eq
project2
end
end
context
'and the user does not have permission to read it'
do
it
'returns nil'
do
expect
(
self
).
to
receive
(
:user_can_reference_project?
).
with
(
project2
).
and_return
(
false
)
expect
(
project_from_ref
(
'cross/reference'
)).
to
be_nil
end
end
end
end
end
...
...
spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
View file @
454d227b
...
...
@@ -96,9 +96,6 @@ module Gitlab::Markdown
let
(
:issue
)
{
create
(
:issue
,
project:
project2
)
}
let
(
:reference
)
{
issue
.
to_reference
(
project
)
}
context
'when user can access reference'
do
before
{
allow_cross_reference!
}
it
'ignores valid references when cross-reference project uses external tracker'
do
expect_any_instance_of
(
Project
).
to
receive
(
:get_issue
).
with
(
issue
.
iid
).
and_return
(
nil
)
...
...
@@ -130,16 +127,5 @@ module Gitlab::Markdown
expect
(
result
[
:references
][
:issue
]).
to
eq
[
issue
]
end
end
context
'when user cannot access reference'
do
before
{
disallow_cross_reference!
}
it
'ignores valid references'
do
exp
=
act
=
"See
#{
reference
}
"
expect
(
filter
(
act
).
to_html
).
to
eq
exp
end
end
end
end
end
spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb
View file @
454d227b
...
...
@@ -84,9 +84,6 @@ module Gitlab::Markdown
let
(
:merge
)
{
create
(
:merge_request
,
source_project:
project2
)
}
let
(
:reference
)
{
merge
.
to_reference
(
project
)
}
context
'when user can access reference'
do
before
{
allow_cross_reference!
}
it
'links to a valid reference'
do
doc
=
filter
(
"See
#{
reference
}
"
)
...
...
@@ -111,16 +108,5 @@ module Gitlab::Markdown
expect
(
result
[
:references
][
:merge_request
]).
to
eq
[
merge
]
end
end
context
'when user cannot access reference'
do
before
{
disallow_cross_reference!
}
it
'ignores valid references'
do
exp
=
act
=
"See
#{
reference
}
"
expect
(
filter
(
act
).
to_html
).
to
eq
exp
end
end
end
end
end
spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
View file @
454d227b
...
...
@@ -83,9 +83,6 @@ module Gitlab::Markdown
let
(
:snippet
)
{
create
(
:project_snippet
,
project:
project2
)
}
let
(
:reference
)
{
snippet
.
to_reference
(
project
)
}
context
'when user can access reference'
do
before
{
allow_cross_reference!
}
it
'links to a valid reference'
do
doc
=
filter
(
"See
#{
reference
}
"
)
...
...
@@ -109,16 +106,5 @@ module Gitlab::Markdown
expect
(
result
[
:references
][
:snippet
]).
to
eq
[
snippet
]
end
end
context
'when user cannot access reference'
do
before
{
disallow_cross_reference!
}
it
'ignores valid references'
do
exp
=
act
=
"See
#{
reference
}
"
expect
(
filter
(
act
).
to_html
).
to
eq
exp
end
end
end
end
end
spec/lib/gitlab/markdown/user_reference_filter_spec.rb
View file @
454d227b
...
...
@@ -83,7 +83,6 @@ module Gitlab::Markdown
let
(
:user
)
{
create
(
:user
)
}
let
(
:reference
)
{
group
.
to_reference
}
context
'that the current user can read'
do
before
do
group
.
add_developer
(
user
)
end
...
...
@@ -107,19 +106,6 @@ module Gitlab::Markdown
end
end
context
'that the current user cannot read'
do
it
'ignores references to the Group'
do
doc
=
filter
(
"Hey
#{
reference
}
"
,
current_user:
user
)
expect
(
doc
.
to_html
).
to
eq
"Hey
#{
reference
}
"
end
it
'does not add to the results hash'
do
result
=
pipeline_result
(
"Hey
#{
reference
}
"
,
current_user:
user
)
expect
(
result
[
:references
][
:user
]).
to
eq
[]
end
end
end
it
'links with adjacent text'
do
doc
=
filter
(
"Mention me (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
/\(<a.+>
#{
reference
}
<\/a>\.\)/
)
...
...
spec/support/filter_spec_helper.rb
View file @
454d227b
...
...
@@ -55,20 +55,6 @@ module FilterSpecHelper
end
end
# Stub CrossProjectReference#user_can_reference_project? to return true for
# the current test
def
allow_cross_reference!
allow_any_instance_of
(
described_class
).
to
receive
(
:user_can_reference_project?
).
and_return
(
true
)
end
# Stub CrossProjectReference#user_can_reference_project? to return false for
# the current test
def
disallow_cross_reference!
allow_any_instance_of
(
described_class
).
to
receive
(
:user_can_reference_project?
).
and_return
(
false
)
end
# Shortcut to Rails' auto-generated routes helpers, to avoid including the
# module
def
urls
...
...
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