Commit 29604ff2 authored by Robert Speicher's avatar Robert Speicher

Add permission checking to UserReferenceFilter

parent 189c5347
......@@ -78,12 +78,16 @@ module Gitlab
%(<a href="#{url}" class="#{klass}">@#{user}</a>)
elsif namespace = Namespace.find_by(path: user)
if namespace.is_a?(Group)
url = group_url(user, only_path: context[:only_path])
if user_can_read_group?(namespace)
url = group_url(user, only_path: context[:only_path])
%(<a href="#{url}" class="#{klass}">@#{user}</a>)
else
match
end
else
url = user_url(user, only_path: context[:only_path])
%(<a href="#{url}" class="#{klass}">@#{user}</a>)
end
%(<a href="#{url}" class="#{klass}">@#{user}</a>)
else
match
end
......@@ -112,6 +116,11 @@ module Gitlab
h.namespace_project_url(project.namespace, project,
only_path: context[:only_path])
end
def user_can_read_group?(group)
return false if context[:current_user].blank?
Ability.abilities.allowed?(context[:current_user], :read_group, group)
end
end
end
end
......@@ -47,11 +47,21 @@ module Gitlab::Markdown
end
end
it 'links to a Group' do
group = create(:group)
context 'mentioning a group' do
let(:group) { create(:group) }
let(:user) { create(:user) }
doc = filter("Hey @#{group.name}")
expect(doc.css('a').first.attr('href')).to eq urls.group_url(group)
it 'links to a Group that the current user can read' do
group.add_user(user, Gitlab::Access::DEVELOPER)
doc = filter("Hey @#{group.name}", current_user: user)
expect(doc.css('a').first.attr('href')).to eq urls.group_url(group)
end
it 'ignores references to a Group that the current user cannot read' do
doc = filter("Hey @#{group.name}", current_user: user)
expect(doc.to_html).to eq "Hey @#{group.name}"
end
end
it 'links with adjacent text' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment