Skip to content
Snippets Groups Projects
Commit 2c55fd00 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Add GFM support to nested groups

parent e5f446b7
No related branches found
No related tags found
No related merge requests found
Loading
@@ -81,7 +81,7 @@ class Group < Namespace
Loading
@@ -81,7 +81,7 @@ class Group < Namespace
end end
   
def to_reference(_from_project = nil, full: nil) def to_reference(_from_project = nil, full: nil)
"#{self.class.reference_prefix}#{name}" "#{self.class.reference_prefix}#{full_path}"
end end
   
def web_url def web_url
Loading
Loading
Loading
@@ -335,7 +335,7 @@ class User < ActiveRecord::Base
Loading
@@ -335,7 +335,7 @@ class User < ActiveRecord::Base
def reference_pattern def reference_pattern
%r{ %r{
#{Regexp.escape(reference_prefix)} #{Regexp.escape(reference_prefix)}
(?<user>#{Gitlab::Regex::NAMESPACE_REGEX_STR}) (?<user>#{Gitlab::Regex::NAMESPACE_REF_REGEX_STR})
}x }x
end end
end end
Loading
Loading
Loading
@@ -36,7 +36,7 @@ module Projects
Loading
@@ -36,7 +36,7 @@ module Projects
def groups def groups
current_user.authorized_groups.sort_by(&:path).map do |group| current_user.authorized_groups.sort_by(&:path).map do |group|
count = group.users.count count = group.users.count
{ username: group.path, name: group.name, count: count, avatar_url: group.avatar_url } { username: group.full_path, name: group.full_name, count: count, avatar_url: group.avatar_url }
end end
end end
   
Loading
Loading
Loading
@@ -285,7 +285,7 @@ module Banzai
Loading
@@ -285,7 +285,7 @@ module Banzai
end end
   
def current_project_namespace_path def current_project_namespace_path
@current_project_namespace_path ||= project.namespace.path @current_project_namespace_path ||= project.namespace.full_path
end end
   
private private
Loading
Loading
Loading
@@ -75,8 +75,8 @@ module Banzai
Loading
@@ -75,8 +75,8 @@ module Banzai
# corresponding Namespace objects. # corresponding Namespace objects.
def namespaces def namespaces
@namespaces ||= @namespaces ||=
Namespace.where(path: usernames).each_with_object({}) do |row, hash| Namespace.where_full_path_in(usernames).each_with_object({}) do |row, hash|
hash[row.path] = row hash[row.full_path] = row
end end
end end
   
Loading
@@ -122,7 +122,7 @@ module Banzai
Loading
@@ -122,7 +122,7 @@ module Banzai
   
def link_to_namespace(namespace, link_content: nil) def link_to_namespace(namespace, link_content: nil)
if namespace.is_a?(Group) if namespace.is_a?(Group)
link_to_group(namespace.path, namespace, link_content: link_content) link_to_group(namespace.full_path, namespace, link_content: link_content)
else else
link_to_user(namespace.path, namespace, link_content: link_content) link_to_user(namespace.path, namespace, link_content: link_content)
end end
Loading
Loading
Loading
@@ -13,6 +13,10 @@ module Gitlab
Loading
@@ -13,6 +13,10 @@ module Gitlab
NAMESPACE_REGEX_STR = '(?:' + NAMESPACE_REGEX_STR_SIMPLE + ')(?<!\.git|\.atom)'.freeze NAMESPACE_REGEX_STR = '(?:' + NAMESPACE_REGEX_STR_SIMPLE + ')(?<!\.git|\.atom)'.freeze
PROJECT_REGEX_STR = PATH_REGEX_STR + '(?<!\.git|\.atom)'.freeze PROJECT_REGEX_STR = PATH_REGEX_STR + '(?<!\.git|\.atom)'.freeze
   
# Same as NAMESPACE_REGEX_STR but allows `/` in the path.
# So `group/subgroup` will match this regex but not NAMESPACE_REGEX_STR
NAMESPACE_REF_REGEX_STR = '(?:[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.\/]*[a-zA-Z0-9_\-]|[a-zA-Z0-9_])(?<!\.git|\.atom)'.freeze
def namespace_regex def namespace_regex
@namespace_regex ||= /\A#{NAMESPACE_REGEX_STR}\z/.freeze @namespace_regex ||= /\A#{NAMESPACE_REGEX_STR}\z/.freeze
end end
Loading
Loading
Loading
@@ -112,6 +112,19 @@ describe Banzai::Filter::UserReferenceFilter, lib: true do
Loading
@@ -112,6 +112,19 @@ describe Banzai::Filter::UserReferenceFilter, lib: true do
end end
end end
   
context 'mentioning a nested group' do
it_behaves_like 'a reference containing an element node'
let(:group) { create(:group, :nested) }
let(:reference) { group.to_reference }
it 'links to the nested group' do
doc = reference_filter("Hey #{reference}")
expect(doc.css('a').first.attr('href')).to eq urls.group_url(group)
end
end
it 'links with adjacent text' do it 'links with adjacent text' do
doc = reference_filter("Mention me (#{reference}.)") doc = reference_filter("Mention me (#{reference}.)")
expect(doc.to_html).to match(/\(<a.+>#{reference}<\/a>\.\)/) expect(doc.to_html).to match(/\(<a.+>#{reference}<\/a>\.\)/)
Loading
Loading
Loading
@@ -50,4 +50,16 @@ describe Gitlab::Regex, lib: true do
Loading
@@ -50,4 +50,16 @@ describe Gitlab::Regex, lib: true do
it { is_expected.not_to match('9foo') } it { is_expected.not_to match('9foo') }
it { is_expected.not_to match('foo-') } it { is_expected.not_to match('foo-') }
end end
describe 'NAMESPACE_REF_REGEX_STR' do
subject { %r{\A#{Gitlab::Regex::NAMESPACE_REF_REGEX_STR}\z} }
it { is_expected.to match('gitlab.org') }
it { is_expected.to match('gitlab.org/gitlab-git') }
it { is_expected.not_to match('gitlab.org.') }
it { is_expected.not_to match('gitlab.org/') }
it { is_expected.not_to match('/gitlab.org') }
it { is_expected.not_to match('gitlab.git') }
it { is_expected.not_to match('gitlab git') }
end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment