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
Tatuya Kamada
gitlab-ce
Commits
bf708e55
Commit
bf708e55
authored
Jan 18, 2017
by
Jarka Kadlecova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make mentions working when project not specified
parent
d6b11daf
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
54 additions
and
10 deletions
+54
-10
app/models/concerns/cache_markdown_field.rb
app/models/concerns/cache_markdown_field.rb
+4
-1
app/models/concerns/mentionable.rb
app/models/concerns/mentionable.rb
+5
-1
lib/banzai/filter/reference_filter.rb
lib/banzai/filter/reference_filter.rb
+4
-0
lib/banzai/filter/user_reference_filter.rb
lib/banzai/filter/user_reference_filter.rb
+2
-3
lib/banzai/renderer.rb
lib/banzai/renderer.rb
+2
-2
spec/lib/banzai/filter/user_reference_filter_spec.rb
spec/lib/banzai/filter/user_reference_filter_spec.rb
+21
-0
spec/models/concerns/mentionable_spec.rb
spec/models/concerns/mentionable_spec.rb
+12
-1
spec/models/note_spec.rb
spec/models/note_spec.rb
+2
-0
spec/services/notification_service_spec.rb
spec/services/notification_service_spec.rb
+2
-2
No files found.
app/models/concerns/cache_markdown_field.rb
View file @
bf708e55
...
@@ -112,7 +112,10 @@ module CacheMarkdownField
...
@@ -112,7 +112,10 @@ module CacheMarkdownField
invalidation_method
=
"
#{
html_field
}
_invalidated?"
.
to_sym
invalidation_method
=
"
#{
html_field
}
_invalidated?"
.
to_sym
define_method
(
cache_method
)
do
define_method
(
cache_method
)
do
html
=
Banzai
::
Renderer
.
cacheless_render_field
(
self
,
markdown_field
)
options
=
{
skip_project_check:
is_a?
(
Note
)
&&
for_personal_snippet?
}
html
=
Banzai
::
Renderer
.
cacheless_render_field
(
self
,
markdown_field
,
options
)
__send__
(
"
#{
html_field
}
="
,
html
)
__send__
(
"
#{
html_field
}
="
,
html
)
true
true
end
end
...
...
app/models/concerns/mentionable.rb
View file @
bf708e55
...
@@ -49,7 +49,11 @@ module Mentionable
...
@@ -49,7 +49,11 @@ module Mentionable
self
.
class
.
mentionable_attrs
.
each
do
|
attr
,
options
|
self
.
class
.
mentionable_attrs
.
each
do
|
attr
,
options
|
text
=
__send__
(
attr
)
text
=
__send__
(
attr
)
options
=
options
.
merge
(
cache_key:
[
self
,
attr
],
author:
author
)
options
=
options
.
merge
(
cache_key:
[
self
,
attr
],
author:
author
,
skip_project_check:
is_a?
(
Note
)
&&
for_personal_snippet?
)
extractor
.
analyze
(
text
,
options
)
extractor
.
analyze
(
text
,
options
)
end
end
...
...
lib/banzai/filter/reference_filter.rb
View file @
bf708e55
...
@@ -53,6 +53,10 @@ module Banzai
...
@@ -53,6 +53,10 @@ module Banzai
context
[
:project
]
context
[
:project
]
end
end
def
skip_project_check?
context
[
:skip_project_check
]
end
def
reference_class
(
type
)
def
reference_class
(
type
)
"gfm gfm-
#{
type
}
has-tooltip"
"gfm gfm-
#{
type
}
has-tooltip"
end
end
...
...
lib/banzai/filter/user_reference_filter.rb
View file @
bf708e55
...
@@ -24,11 +24,10 @@ module Banzai
...
@@ -24,11 +24,10 @@ module Banzai
end
end
def
call
def
call
return
doc
if
project
.
nil?
return
doc
if
project
.
nil?
&&
!
skip_project_check?
ref_pattern
=
User
.
reference_pattern
ref_pattern
=
User
.
reference_pattern
ref_pattern_start
=
/\A
#{
ref_pattern
}
\z/
ref_pattern_start
=
/\A
#{
ref_pattern
}
\z/
nodes
.
each
do
|
node
|
nodes
.
each
do
|
node
|
if
text_node?
(
node
)
if
text_node?
(
node
)
replace_text_when_pattern_matches
(
node
,
ref_pattern
)
do
|
content
|
replace_text_when_pattern_matches
(
node
,
ref_pattern
)
do
|
content
|
...
@@ -58,7 +57,7 @@ module Banzai
...
@@ -58,7 +57,7 @@ module Banzai
# have `gfm` and `gfm-project_member` class names attached for styling.
# have `gfm` and `gfm-project_member` class names attached for styling.
def
user_link_filter
(
text
,
link_content:
nil
)
def
user_link_filter
(
text
,
link_content:
nil
)
self
.
class
.
references_in
(
text
)
do
|
match
,
username
|
self
.
class
.
references_in
(
text
)
do
|
match
,
username
|
if
username
==
'all'
if
username
==
'all'
&&
!
skip_project_check?
link_to_all
(
link_content:
link_content
)
link_to_all
(
link_content:
link_content
)
elsif
namespace
=
namespaces
[
username
]
elsif
namespace
=
namespaces
[
username
]
link_to_namespace
(
namespace
,
link_content:
link_content
)
||
match
link_to_namespace
(
namespace
,
link_content:
link_content
)
||
match
...
...
lib/banzai/renderer.rb
View file @
bf708e55
...
@@ -52,9 +52,9 @@ module Banzai
...
@@ -52,9 +52,9 @@ module Banzai
end
end
# Same as +render_field+, but without consulting or updating the cache field
# Same as +render_field+, but without consulting or updating the cache field
def
cacheless_render_field
(
object
,
field
)
def
cacheless_render_field
(
object
,
field
,
options
=
{}
)
text
=
object
.
__send__
(
field
)
text
=
object
.
__send__
(
field
)
context
=
object
.
banzai_render_context
(
field
)
context
=
object
.
banzai_render_context
(
field
)
.
merge
(
options
)
cacheless_render
(
text
,
context
)
cacheless_render
(
text
,
context
)
end
end
...
...
spec/lib/banzai/filter/user_reference_filter_spec.rb
View file @
bf708e55
...
@@ -152,6 +152,27 @@ describe Banzai::Filter::UserReferenceFilter, lib: true do
...
@@ -152,6 +152,27 @@ describe Banzai::Filter::UserReferenceFilter, lib: true do
end
end
end
end
context
'when a project is not specified'
do
let
(
:project
)
{
nil
}
it
'does not link a User'
do
doc
=
reference_filter
(
"Hey
#{
reference
}
"
)
expect
(
doc
).
not_to
include
(
'a'
)
end
context
'when skip_project_check set to true'
do
it
'links to a User'
do
doc
=
reference_filter
(
"Hey
#{
reference
}
"
,
skip_project_check:
true
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
user_url
(
user
)
end
it
'does not link users using @all reference'
do
doc
=
reference_filter
(
"Hey
#{
User
.
reference_prefix
}
all"
,
skip_project_check:
true
)
expect
(
doc
).
not_to
include
(
'a'
)
end
end
end
describe
'#namespaces'
do
describe
'#namespaces'
do
it
'returns a Hash containing all Namespaces'
do
it
'returns a Hash containing all Namespaces'
do
document
=
Nokogiri
::
HTML
.
fragment
(
"<p>
#{
user
.
to_reference
}
</p>"
)
document
=
Nokogiri
::
HTML
.
fragment
(
"<p>
#{
user
.
to_reference
}
</p>"
)
...
...
spec/models/concerns/mentionable_spec.rb
View file @
bf708e55
...
@@ -30,12 +30,23 @@ describe Issue, "Mentionable" do
...
@@ -30,12 +30,23 @@ describe Issue, "Mentionable" do
describe
'#mentioned_users'
do
describe
'#mentioned_users'
do
let!
(
:user
)
{
create
(
:user
,
username:
'stranger'
)
}
let!
(
:user
)
{
create
(
:user
,
username:
'stranger'
)
}
let!
(
:user2
)
{
create
(
:user
,
username:
'john'
)
}
let!
(
:user2
)
{
create
(
:user
,
username:
'john'
)
}
let!
(
:issue
)
{
create
(
:issue
,
description:
"
#{
user
.
to_reference
}
mentioned"
)
}
let!
(
:user3
)
{
create
(
:user
,
username:
'jim'
)
}
let
(
:issue
)
{
create
(
:issue
,
description:
"
#{
user
.
to_reference
}
mentioned"
)
}
subject
{
issue
.
mentioned_users
}
subject
{
issue
.
mentioned_users
}
it
{
is_expected
.
to
include
(
user
)
}
it
{
is_expected
.
to
include
(
user
)
}
it
{
is_expected
.
not_to
include
(
user2
)
}
it
{
is_expected
.
not_to
include
(
user2
)
}
context
'when a note on personal snippet'
do
let!
(
:note
)
{
create
(
:note_on_personal_snippet
,
note:
"
#{
user
.
to_reference
}
mentioned
#{
user3
.
to_reference
}
"
)
}
subject
{
note
.
mentioned_users
}
it
{
is_expected
.
to
include
(
user
)
}
it
{
is_expected
.
to
include
(
user3
)
}
it
{
is_expected
.
not_to
include
(
user2
)
}
end
end
end
describe
'#referenced_mentionables'
do
describe
'#referenced_mentionables'
do
...
...
spec/models/note_spec.rb
View file @
bf708e55
...
@@ -152,6 +152,7 @@ describe Note, models: true do
...
@@ -152,6 +152,7 @@ describe Note, models: true do
with
([{
with
([{
text:
note1
.
note
,
text:
note1
.
note
,
context:
{
context:
{
skip_project_check:
false
,
pipeline: :note
,
pipeline: :note
,
cache_key:
[
note1
,
"note"
],
cache_key:
[
note1
,
"note"
],
project:
note1
.
project
,
project:
note1
.
project
,
...
@@ -163,6 +164,7 @@ describe Note, models: true do
...
@@ -163,6 +164,7 @@ describe Note, models: true do
with
([{
with
([{
text:
note2
.
note
,
text:
note2
.
note
,
context:
{
context:
{
skip_project_check:
false
,
pipeline: :note
,
pipeline: :note
,
cache_key:
[
note2
,
"note"
],
cache_key:
[
note2
,
"note"
],
project:
note2
.
project
,
project:
note2
.
project
,
...
...
spec/services/notification_service_spec.rb
View file @
bf708e55
...
@@ -306,8 +306,8 @@ describe NotificationService, services: true do
...
@@ -306,8 +306,8 @@ describe NotificationService, services: true do
should_email
(
@u_watcher
)
should_email
(
@u_watcher
)
should_email
(
@u_snippet_author
)
should_email
(
@u_snippet_author
)
#
TODO: make mentions working for pesronal snippet
s
#
it emails mentioned user
s
# should_email(@u_mentioned_level
)
should_email
(
@u_mentioned
)
# it does not email participants with mention notification level
# it does not email participants with mention notification level
should_not_email
(
@u_mentioned_level
)
should_not_email
(
@u_mentioned_level
)
...
...
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