diff options
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/git_access_snippet.rb | 48 | ||||
-rw-r--r-- | lib/gitlab/gl_repository.rb | 9 | ||||
-rw-r--r-- | lib/gitlab/gl_repository/repo_type.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/metrics/dashboard/finder.rb | 14 | ||||
-rw-r--r-- | lib/gitlab/metrics/dashboard/service_selector.rb | 1 |
5 files changed, 74 insertions, 2 deletions
diff --git a/lib/gitlab/git_access_snippet.rb b/lib/gitlab/git_access_snippet.rb new file mode 100644 index 00000000000..d99b9c3fe89 --- /dev/null +++ b/lib/gitlab/git_access_snippet.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +module Gitlab + class GitAccessSnippet < GitAccess + ERROR_MESSAGES = { + snippet_not_found: 'The snippet you were looking for could not be found.', + repository_not_found: 'The snippet repository you were looking for could not be found.' + }.freeze + + attr_reader :snippet + + def initialize(actor, snippet, protocol, **kwargs) + @snippet = snippet + + super(actor, project, protocol, **kwargs) + end + + def check(cmd, _changes) + unless Feature.enabled?(:version_snippets, user) + raise NotFoundError, ERROR_MESSAGES[:snippet_not_found] + end + + check_snippet_accessibility! + + success_result(cmd) + end + + def project + snippet&.project + end + + private + + def repository + snippet&.repository + end + + def check_snippet_accessibility! + if snippet.blank? + raise NotFoundError, ERROR_MESSAGES[:snippet_not_found] + end + + unless repository&.exists? + raise NotFoundError, ERROR_MESSAGES[:repository_not_found] + end + end + end +end diff --git a/lib/gitlab/gl_repository.rb b/lib/gitlab/gl_repository.rb index 347084e779c..fcebcb463cd 100644 --- a/lib/gitlab/gl_repository.rb +++ b/lib/gitlab/gl_repository.rb @@ -15,10 +15,17 @@ module Gitlab repository_resolver: -> (project) { project.wiki.repository }, suffix: :wiki ).freeze + SNIPPET = RepoType.new( + name: :snippet, + access_checker_class: Gitlab::GitAccessSnippet, + repository_resolver: -> (snippet) { snippet.repository }, + container_resolver: -> (id) { Snippet.find_by_id(id) } + ).freeze TYPES = { PROJECT.name.to_s => PROJECT, - WIKI.name.to_s => WIKI + WIKI.name.to_s => WIKI, + SNIPPET.name.to_s => SNIPPET }.freeze def self.types diff --git a/lib/gitlab/gl_repository/repo_type.rb b/lib/gitlab/gl_repository/repo_type.rb index 20a0dd48468..9663fd7de8f 100644 --- a/lib/gitlab/gl_repository/repo_type.rb +++ b/lib/gitlab/gl_repository/repo_type.rb @@ -47,6 +47,10 @@ module Gitlab self == PROJECT end + def snippet? + self == SNIPPET + end + def path_suffix suffix ? ".#{suffix}" : '' end diff --git a/lib/gitlab/metrics/dashboard/finder.rb b/lib/gitlab/metrics/dashboard/finder.rb index 0374484d357..3dd86c8685d 100644 --- a/lib/gitlab/metrics/dashboard/finder.rb +++ b/lib/gitlab/metrics/dashboard/finder.rb @@ -65,7 +65,7 @@ module Gitlab def find_all_paths_from_source(project) Gitlab::Metrics::Dashboard::Cache.delete_all! - system_service.all_dashboard_paths(project) + default_dashboard_path(project) .+ project_service.all_dashboard_paths(project) end @@ -79,6 +79,18 @@ module Gitlab ::Metrics::Dashboard::ProjectDashboardService end + def self_monitoring_service + ::Metrics::Dashboard::SelfMonitoringDashboardService + end + + def default_dashboard_path(project) + if project.self_monitoring? + self_monitoring_service.all_dashboard_paths(project) + else + system_service.all_dashboard_paths(project) + end + end + def service_for(options) Gitlab::Metrics::Dashboard::ServiceSelector.call(options) end diff --git a/lib/gitlab/metrics/dashboard/service_selector.rb b/lib/gitlab/metrics/dashboard/service_selector.rb index 5a3007e4814..24ea85a5a95 100644 --- a/lib/gitlab/metrics/dashboard/service_selector.rb +++ b/lib/gitlab/metrics/dashboard/service_selector.rb @@ -18,6 +18,7 @@ module Gitlab ::Metrics::Dashboard::DefaultEmbedService, ::Metrics::Dashboard::SystemDashboardService, ::Metrics::Dashboard::PodDashboardService, + ::Metrics::Dashboard::SelfMonitoringDashboardService, ::Metrics::Dashboard::ProjectDashboardService ].freeze |