diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-19 03:09:15 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-19 03:09:15 +0300 |
commit | 60f63d15794e62c4bac9756445f618cd9acb8654 (patch) | |
tree | 30c2b2dc678995dd332b32672f9faa460fabdb79 /lib/banzai | |
parent | 93d7441cc98c1db55797a2181a3d9f4b3d26d82c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/banzai')
-rw-r--r-- | lib/banzai/filter/inline_metrics_filter.rb | 1 | ||||
-rw-r--r-- | lib/banzai/filter/inline_metrics_redactor_filter.rb | 20 | ||||
-rw-r--r-- | lib/banzai/pipeline/gfm_pipeline.rb | 10 |
3 files changed, 26 insertions, 5 deletions
diff --git a/lib/banzai/filter/inline_metrics_filter.rb b/lib/banzai/filter/inline_metrics_filter.rb index c1f4bf1f97f..e8145e93851 100644 --- a/lib/banzai/filter/inline_metrics_filter.rb +++ b/lib/banzai/filter/inline_metrics_filter.rb @@ -20,6 +20,7 @@ module Banzai # the cost of doing a full regex match. def xpath_search "descendant-or-self::a[contains(@href,'metrics') and \ + contains(@href,'environments') and \ starts-with(@href, '#{Gitlab.config.gitlab.url}')]" end diff --git a/lib/banzai/filter/inline_metrics_redactor_filter.rb b/lib/banzai/filter/inline_metrics_redactor_filter.rb index ae830831a27..664a897970a 100644 --- a/lib/banzai/filter/inline_metrics_redactor_filter.rb +++ b/lib/banzai/filter/inline_metrics_redactor_filter.rb @@ -9,8 +9,8 @@ module Banzai METRICS_CSS_CLASS = '.js-render-metrics' EMBED_LIMIT = 100 - URL = Gitlab::Metrics::Dashboard::Url + Route = Struct.new(:regex, :permission) Embed = Struct.new(:project_path, :permission) # Finds all embeds based on the css class the FE @@ -59,14 +59,28 @@ module Banzai embed = Embed.new url = node.attribute('data-dashboard-url').to_s - set_path_and_permission(embed, url, URL.metrics_regex, :read_environment) - set_path_and_permission(embed, url, URL.grafana_regex, :read_project) unless embed.permission + permissions_by_route.each do |route| + set_path_and_permission(embed, url, route.regex, route.permission) unless embed.permission + end embeds[node] = embed if embed.permission end end end + def permissions_by_route + [ + Route.new( + ::Gitlab::Metrics::Dashboard::Url.metrics_regex, + :read_environment + ), + Route.new( + ::Gitlab::Metrics::Dashboard::Url.grafana_regex, + :read_project + ) + ] + end + # Attempts to determine the path and permission attributes # of a url based on expected dashboard url formats and # sets the attributes on an Embed object diff --git a/lib/banzai/pipeline/gfm_pipeline.rb b/lib/banzai/pipeline/gfm_pipeline.rb index dad0d95685e..b6238dfe7f0 100644 --- a/lib/banzai/pipeline/gfm_pipeline.rb +++ b/lib/banzai/pipeline/gfm_pipeline.rb @@ -29,8 +29,7 @@ module Banzai Filter::AudioLinkFilter, Filter::ImageLazyLoadFilter, Filter::ImageLinkFilter, - Filter::InlineMetricsFilter, - Filter::InlineGrafanaMetricsFilter, + *metrics_filters, Filter::TableOfContentsFilter, Filter::TableOfContentsTagFilter, Filter::AutolinkFilter, @@ -48,6 +47,13 @@ module Banzai ] end + def self.metrics_filters + [ + Filter::InlineMetricsFilter, + Filter::InlineGrafanaMetricsFilter + ] + end + def self.reference_filters [ Filter::UserReferenceFilter, |