diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-12-07 12:44:49 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-12-07 12:44:49 +0000 |
commit | 996da1e52c3e1f3f1ec58f81f602167e4ff539a3 (patch) | |
tree | 72182129a81d996a886ea765514d20bc7e2bcf8c /lib/banzai | |
parent | fe62860e05ca6e3ef7125fe92fdf52cd6f7b63df (diff) | |
parent | f7c18ca31469b199c1a898cef583c9aae99f1375 (diff) | |
download | gitlab-ce-996da1e52c3e1f3f1ec58f81f602167e4ff539a3.tar.gz |
Merge branch 'ce-backport-3938' into 'master'
Support uploads for groups
See merge request gitlab-org/gitlab-ce!15781
Diffstat (limited to 'lib/banzai')
-rw-r--r-- | lib/banzai/filter/upload_link_filter.rb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/banzai/filter/upload_link_filter.rb b/lib/banzai/filter/upload_link_filter.rb index 09844931be5..d64f9ac4eb6 100644 --- a/lib/banzai/filter/upload_link_filter.rb +++ b/lib/banzai/filter/upload_link_filter.rb @@ -8,7 +8,7 @@ module Banzai # class UploadLinkFilter < HTML::Pipeline::Filter def call - return doc unless project + return doc unless project || group doc.xpath('descendant-or-self::a[starts-with(@href, "/uploads/")]').each do |el| process_link_attr el.attribute('href') @@ -28,13 +28,27 @@ module Banzai end def build_url(uri) - File.join(Gitlab.config.gitlab.url, project.full_path, uri) + base_path = Gitlab.config.gitlab.url + + if group + urls = Gitlab::Routing.url_helpers + # we need to get last 2 parts of the uri which are secret and filename + uri_parts = uri.split(File::SEPARATOR) + file_path = urls.show_group_uploads_path(group, uri_parts[-2], uri_parts[-1]) + File.join(base_path, file_path) + else + File.join(base_path, project.full_path, uri) + end end def project context[:project] end + def group + context[:group] + end + # Ensure that a :project key exists in context # # Note that while the key might exist, its value could be nil! |