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)
if user_can_read_group?(namespace)
url = group_url(user, only_path: context[:only_path]) url = group_url(user, only_path: context[:only_path])
%(<a href="#{url}" class="#{klass}">@#{user}</a>)
else else
url = user_url(user, only_path: context[:only_path]) match
end end
else
url = user_url(user, only_path: context[:only_path])
%(<a href="#{url}" class="#{klass}">@#{user}</a>) %(<a href="#{url}" class="#{klass}">@#{user}</a>)
end
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,13 +47,23 @@ module Gitlab::Markdown ...@@ -47,13 +47,23 @@ 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) }
it 'links to a Group that the current user can read' do
group.add_user(user, Gitlab::Access::DEVELOPER)
doc = filter("Hey @#{group.name}") doc = filter("Hey @#{group.name}", current_user: user)
expect(doc.css('a').first.attr('href')).to eq urls.group_url(group) expect(doc.css('a').first.attr('href')).to eq urls.group_url(group)
end 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 it 'links with adjacent text' do
doc = filter("Mention me (@#{user.username}.)") doc = filter("Mention me (@#{user.username}.)")
expect(doc.to_html).to match(/\(<a.+>@#{user.username}<\/a>\.\)/) expect(doc.to_html).to match(/\(<a.+>@#{user.username}<\/a>\.\)/)
......
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