diff options
Diffstat (limited to 'lib/banzai/filter/relative_link_filter.rb')
-rw-r--r-- | lib/banzai/filter/relative_link_filter.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/banzai/filter/relative_link_filter.rb b/lib/banzai/filter/relative_link_filter.rb index 86f18679496..2b734db5cfb 100644 --- a/lib/banzai/filter/relative_link_filter.rb +++ b/lib/banzai/filter/relative_link_filter.rb @@ -9,6 +9,7 @@ module Banzai # Context options: # :commit # :group + # :current_user # :project # :project_wiki # :ref @@ -48,7 +49,7 @@ module Banzai if html_attr.value.start_with?('/uploads/') process_link_to_upload_attr(html_attr) - elsif linkable_files? + elsif linkable_files? && repo_visible_to_user? process_link_to_repository_attr(html_attr) end end @@ -166,6 +167,10 @@ module Banzai Gitlab.config.gitlab.relative_url_root.presence || '/' end + def repo_visible_to_user? + project && Ability.allowed?(current_user, :download_code, project) + end + def ref context[:ref] || project.default_branch end @@ -178,6 +183,10 @@ module Banzai context[:project] end + def current_user + context[:current_user] + end + def repository @repository ||= project&.repository end |