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
ffb107ac
Commit
ffb107ac
authored
Feb 26, 2018
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Keep link when redacting unauthorized object links
parent
565e4ee5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
10 deletions
+45
-10
changelogs/unreleased/40502-osw-keep-link-when-redacting-unauthorized-objects.yml
...502-osw-keep-link-when-redacting-unauthorized-objects.yml
+5
-0
lib/banzai/filter/abstract_reference_filter.rb
lib/banzai/filter/abstract_reference_filter.rb
+9
-6
lib/banzai/redactor.rb
lib/banzai/redactor.rb
+21
-4
spec/lib/banzai/redactor_spec.rb
spec/lib/banzai/redactor_spec.rb
+10
-0
No files found.
changelogs/unreleased/40502-osw-keep-link-when-redacting-unauthorized-objects.yml
0 → 100644
View file @
ffb107ac
---
title
:
Keep link when redacting unauthorized object links
merge_request
:
author
:
type
:
fixed
lib/banzai/filter/abstract_reference_filter.rb
View file @
ffb107ac
...
...
@@ -174,7 +174,9 @@ module Banzai
title
=
object_link_title
(
object
)
klass
=
reference_class
(
object_sym
)
data
=
data_attributes_for
(
link_content
||
match
,
parent
,
object
,
link:
!!
link_content
)
data
=
data_attributes_for
(
link_content
||
match
,
parent
,
object
,
link_content:
!!
link_content
,
link_reference:
link_reference
)
url
=
if
matches
.
names
.
include?
(
"url"
)
&&
matches
[
:url
]
...
...
@@ -194,12 +196,13 @@ module Banzai
end
end
def
data_attributes_for
(
text
,
project
,
object
,
link:
false
)
def
data_attributes_for
(
text
,
project
,
object
,
link
_content:
false
,
link_reference
:
false
)
data_attribute
(
original:
text
,
link:
link
,
project:
project
.
id
,
object_sym
=>
object
.
id
original:
text
,
link:
link_content
,
link_reference:
link_reference
,
project:
project
.
id
,
object_sym
=>
object
.
id
)
end
...
...
lib/banzai/redactor.rb
View file @
ffb107ac
...
...
@@ -42,16 +42,33 @@ module Banzai
next
if
visible
.
include?
(
node
)
doc_data
[
:visible_reference_count
]
-=
1
# The reference should be replaced by the original link's content,
# which is not always the same as the rendered one.
content
=
node
.
attr
(
'data-original'
)
||
node
.
inner_html
node
.
replace
(
content
)
redacted_content
=
redacted_node_content
(
node
)
node
.
replace
(
redacted_content
)
end
end
metadata
end
# Return redacted content of given node as either the original link (<a> tag),
# the original content (text), or the inner HTML of the node.
#
def
redacted_node_content
(
node
)
original_content
=
node
.
attr
(
'data-original'
)
link_reference
=
node
.
attr
(
'data-link-reference'
)
# Build the raw <a> tag just with a link as href and content if
# it's originally a link pattern. We shouldn't return a plain text href.
original_link
=
if
link_reference
==
'true'
&&
href
=
original_content
%(<a href="#{href}">#{href}</a>)
end
# The reference should be replaced by the original link's content,
# which is not always the same as the rendered one.
original_link
||
original_content
||
node
.
inner_html
end
def
redact_cross_project_references
(
documents
)
extractor
=
Banzai
::
IssuableExtractor
.
new
(
project
,
user
)
issuables
=
extractor
.
extract
(
documents
)
...
...
spec/lib/banzai/redactor_spec.rb
View file @
ffb107ac
...
...
@@ -40,6 +40,16 @@ describe Banzai::Redactor do
expect
(
doc
.
to_html
).
to
eq
(
original_content
)
end
end
it
'returns <a> tag with original href if it is originally a link reference'
do
href
=
'http://localhost:3000'
doc
=
Nokogiri
::
HTML
.
fragment
(
"<a class='gfm' data-reference-type='issue' data-original=
#{
href
}
data-link-reference='true'>
#{
href
}
</a>"
)
redactor
.
redact
([
doc
])
expect
(
doc
.
to_html
).
to
eq
(
'<a href="http://localhost:3000">http://localhost:3000</a>'
)
end
end
context
'when project is in pending delete'
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