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

Add permission checking to UserReferenceFilter

parent 189c5347
...@@ -78,12 +78,16 @@ module Gitlab ...@@ -78,12 +78,16 @@ module Gitlab
%(<a href="#{url}" class="#{klass}">@#{user}</a>) %(<a href="#{url}" class="#{klass}">@#{user}</a>)
elsif namespace = Namespace.find_by(path: user) elsif namespace = Namespace.find_by(path: user)
if namespace.is_a?(Group) 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 else
url = user_url(user, only_path: context[:only_path]) url = user_url(user, only_path: context[:only_path])
%(<a href="#{url}" class="#{klass}">@#{user}</a>)
end end
%(<a href="#{url}" class="#{klass}">@#{user}</a>)
else else
match match
end end
...@@ -112,6 +116,11 @@ module Gitlab ...@@ -112,6 +116,11 @@ module Gitlab
h.namespace_project_url(project.namespace, project, h.namespace_project_url(project.namespace, project,
only_path: context[:only_path]) only_path: context[:only_path])
end 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 end
end end
...@@ -47,11 +47,21 @@ module Gitlab::Markdown ...@@ -47,11 +47,21 @@ module Gitlab::Markdown
end end
end end
it 'links to a Group' do context 'mentioning a group' do
group = create(:group) let(:group) { create(:group) }
let(:user) { create(:user) }
doc = filter("Hey @#{group.name}") it 'links to a Group that the current user can read' do
expect(doc.css('a').first.attr('href')).to eq urls.group_url(group) 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 end
it 'links with adjacent text' do 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