summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/api/entities.rb154
-rw-r--r--lib/api/entities/board.rb14
-rw-r--r--lib/api/entities/broadcast_message.rb2
-rw-r--r--lib/api/entities/compare.rb25
-rw-r--r--lib/api/entities/contributor.rb9
-rw-r--r--lib/api/entities/list.rb11
-rw-r--r--lib/api/entities/release.rb54
-rw-r--r--lib/api/entities/runner.rb16
-rw-r--r--lib/api/entities/runner_details.rb34
-rw-r--r--lib/api/entities/runner_registration_details.rb9
-rw-r--r--lib/api/entities/tag.rb23
-rw-r--r--lib/api/project_container_repositories.rb2
-rw-r--r--lib/gitlab/git_access_snippet.rb48
-rw-r--r--lib/gitlab/gl_repository.rb9
-rw-r--r--lib/gitlab/gl_repository/repo_type.rb4
-rw-r--r--lib/gitlab/metrics/dashboard/finder.rb14
-rw-r--r--lib/gitlab/metrics/dashboard/service_selector.rb1
17 files changed, 271 insertions, 158 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 5d5a61b76f1..5128ffa6a1f 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -163,160 +163,6 @@ module API
end
end
- class List < Grape::Entity
- expose :id
- expose :label, using: Entities::LabelBasic
- expose :position
- end
-
- class Board < Grape::Entity
- expose :id
- expose :project, using: Entities::BasicProjectDetails
-
- expose :lists, using: Entities::List do |board|
- board.destroyable_lists
- end
- end
-
- class Compare < Grape::Entity
- expose :commit, using: Entities::Commit do |compare, _|
- compare.commits.last
- end
-
- expose :commits, using: Entities::Commit do |compare, _|
- compare.commits
- end
-
- expose :diffs, using: Entities::Diff do |compare, _|
- compare.diffs.diffs.to_a
- end
-
- expose :compare_timeout do |compare, _|
- compare.diffs.diffs.overflow?
- end
-
- expose :same, as: :compare_same_ref
- end
-
- class Contributor < Grape::Entity
- expose :name, :email, :commits, :additions, :deletions
- end
-
- class BroadcastMessage < Grape::Entity
- expose :message, :starts_at, :ends_at, :color, :font, :target_path, :broadcast_type
- end
-
- class Release < Grape::Entity
- include ::API::Helpers::Presentable
-
- expose :name do |release, _|
- can_download_code? ? release.name : "Release-#{release.id}"
- end
- expose :tag, as: :tag_name, if: ->(_, _) { can_download_code? }
- expose :description
- expose :description_html do |entity|
- MarkupHelper.markdown_field(entity, :description)
- end
- expose :created_at
- expose :released_at
- expose :author, using: Entities::UserBasic, if: -> (release, _) { release.author.present? }
- expose :commit, using: Entities::Commit, if: ->(_, _) { can_download_code? }
- expose :upcoming_release?, as: :upcoming_release
- expose :milestones, using: Entities::Milestone, if: -> (release, _) { release.milestones.present? && can_read_milestone? }
- expose :commit_path, expose_nil: false
- expose :tag_path, expose_nil: false
- expose :evidence_sha, expose_nil: false, if: ->(_, _) { can_download_code? }
- expose :assets do
- expose :assets_count, as: :count do |release, _|
- assets_to_exclude = can_download_code? ? [] : [:sources]
- release.assets_count(except: assets_to_exclude)
- end
- expose :sources, using: Entities::Releases::Source, if: ->(_, _) { can_download_code? }
- expose :links, using: Entities::Releases::Link do |release, options|
- release.links.sorted
- end
- expose :evidence_file_path, expose_nil: false, if: ->(_, _) { can_download_code? }
- end
- expose :_links do
- expose :self_url, as: :self, expose_nil: false
- expose :merge_requests_url, expose_nil: false
- expose :issues_url, expose_nil: false
- expose :edit_url, expose_nil: false
- end
-
- private
-
- def can_download_code?
- Ability.allowed?(options[:current_user], :download_code, object.project)
- end
-
- def can_read_milestone?
- Ability.allowed?(options[:current_user], :read_milestone, object.project)
- end
- end
-
- class Tag < Grape::Entity
- expose :name, :message, :target
-
- expose :commit, using: Entities::Commit do |repo_tag, options|
- options[:project].repository.commit(repo_tag.dereferenced_target)
- end
-
- # rubocop: disable CodeReuse/ActiveRecord
- expose :release, using: Entities::TagRelease do |repo_tag, options|
- options[:project].releases.find_by(tag: repo_tag.name)
- end
- # rubocop: enable CodeReuse/ActiveRecord
-
- expose :protected do |repo_tag, options|
- ::ProtectedTag.protected?(options[:project], repo_tag.name)
- end
- end
-
- class Runner < Grape::Entity
- expose :id
- expose :description
- expose :ip_address
- expose :active
- expose :instance_type?, as: :is_shared
- expose :name
- expose :online?, as: :online
- expose :status
- end
-
- class RunnerDetails < Runner
- expose :tag_list
- expose :run_untagged
- expose :locked
- expose :maximum_timeout
- expose :access_level
- expose :version, :revision, :platform, :architecture
- expose :contacted_at
- expose :token, if: lambda { |runner, options| options[:current_user].admin? || !runner.instance_type? }
- # rubocop: disable CodeReuse/ActiveRecord
- expose :projects, with: Entities::BasicProjectDetails do |runner, options|
- if options[:current_user].admin?
- runner.projects
- else
- options[:current_user].authorized_projects.where(id: runner.projects)
- end
- end
- # rubocop: enable CodeReuse/ActiveRecord
- # rubocop: disable CodeReuse/ActiveRecord
- expose :groups, with: Entities::BasicGroupDetails do |runner, options|
- if options[:current_user].admin?
- runner.groups
- else
- options[:current_user].authorized_groups.where(id: runner.groups)
- end
- end
- # rubocop: enable CodeReuse/ActiveRecord
- end
-
- class RunnerRegistrationDetails < Grape::Entity
- expose :id, :token
- end
-
class Trigger < Grape::Entity
include ::API::Helpers::Presentable
diff --git a/lib/api/entities/board.rb b/lib/api/entities/board.rb
new file mode 100644
index 00000000000..afbf5b4b65b
--- /dev/null
+++ b/lib/api/entities/board.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class Board < Grape::Entity
+ expose :id
+ expose :project, using: Entities::BasicProjectDetails
+
+ expose :lists, using: Entities::List do |board|
+ board.destroyable_lists
+ end
+ end
+ end
+end
diff --git a/lib/api/entities/broadcast_message.rb b/lib/api/entities/broadcast_message.rb
index 31d4cc50526..403677aa300 100644
--- a/lib/api/entities/broadcast_message.rb
+++ b/lib/api/entities/broadcast_message.rb
@@ -3,7 +3,7 @@
module API
module Entities
class BroadcastMessage < Grape::Entity
- expose :id, :message, :starts_at, :ends_at, :color, :font
+ expose :id, :message, :starts_at, :ends_at, :color, :font, :target_path, :broadcast_type
expose :active?, as: :active
end
end
diff --git a/lib/api/entities/compare.rb b/lib/api/entities/compare.rb
new file mode 100644
index 00000000000..fe2f03db2af
--- /dev/null
+++ b/lib/api/entities/compare.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class Compare < Grape::Entity
+ expose :commit, using: Entities::Commit do |compare, _|
+ compare.commits.last
+ end
+
+ expose :commits, using: Entities::Commit do |compare, _|
+ compare.commits
+ end
+
+ expose :diffs, using: Entities::Diff do |compare, _|
+ compare.diffs.diffs.to_a
+ end
+
+ expose :compare_timeout do |compare, _|
+ compare.diffs.diffs.overflow?
+ end
+
+ expose :same, as: :compare_same_ref
+ end
+ end
+end
diff --git a/lib/api/entities/contributor.rb b/lib/api/entities/contributor.rb
new file mode 100644
index 00000000000..8763822b674
--- /dev/null
+++ b/lib/api/entities/contributor.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class Contributor < Grape::Entity
+ expose :name, :email, :commits, :additions, :deletions
+ end
+ end
+end
diff --git a/lib/api/entities/list.rb b/lib/api/entities/list.rb
new file mode 100644
index 00000000000..e856359efc1
--- /dev/null
+++ b/lib/api/entities/list.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class List < Grape::Entity
+ expose :id
+ expose :label, using: Entities::LabelBasic
+ expose :position
+ end
+ end
+end
diff --git a/lib/api/entities/release.rb b/lib/api/entities/release.rb
new file mode 100644
index 00000000000..dc4b91e594e
--- /dev/null
+++ b/lib/api/entities/release.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class Release < Grape::Entity
+ include ::API::Helpers::Presentable
+
+ expose :name do |release, _|
+ can_download_code? ? release.name : "Release-#{release.id}"
+ end
+ expose :tag, as: :tag_name, if: ->(_, _) { can_download_code? }
+ expose :description
+ expose :description_html do |entity|
+ MarkupHelper.markdown_field(entity, :description)
+ end
+ expose :created_at
+ expose :released_at
+ expose :author, using: Entities::UserBasic, if: -> (release, _) { release.author.present? }
+ expose :commit, using: Entities::Commit, if: ->(_, _) { can_download_code? }
+ expose :upcoming_release?, as: :upcoming_release
+ expose :milestones, using: Entities::Milestone, if: -> (release, _) { release.milestones.present? && can_read_milestone? }
+ expose :commit_path, expose_nil: false
+ expose :tag_path, expose_nil: false
+ expose :evidence_sha, expose_nil: false, if: ->(_, _) { can_download_code? }
+ expose :assets do
+ expose :assets_count, as: :count do |release, _|
+ assets_to_exclude = can_download_code? ? [] : [:sources]
+ release.assets_count(except: assets_to_exclude)
+ end
+ expose :sources, using: Entities::Releases::Source, if: ->(_, _) { can_download_code? }
+ expose :links, using: Entities::Releases::Link do |release, options|
+ release.links.sorted
+ end
+ expose :evidence_file_path, expose_nil: false, if: ->(_, _) { can_download_code? }
+ end
+ expose :_links do
+ expose :self_url, as: :self, expose_nil: false
+ expose :merge_requests_url, expose_nil: false
+ expose :issues_url, expose_nil: false
+ expose :edit_url, expose_nil: false
+ end
+
+ private
+
+ def can_download_code?
+ Ability.allowed?(options[:current_user], :download_code, object.project)
+ end
+
+ def can_read_milestone?
+ Ability.allowed?(options[:current_user], :read_milestone, object.project)
+ end
+ end
+ end
+end
diff --git a/lib/api/entities/runner.rb b/lib/api/entities/runner.rb
new file mode 100644
index 00000000000..6165b54cddb
--- /dev/null
+++ b/lib/api/entities/runner.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class Runner < Grape::Entity
+ expose :id
+ expose :description
+ expose :ip_address
+ expose :active
+ expose :instance_type?, as: :is_shared
+ expose :name
+ expose :online?, as: :online
+ expose :status
+ end
+ end
+end
diff --git a/lib/api/entities/runner_details.rb b/lib/api/entities/runner_details.rb
new file mode 100644
index 00000000000..17202821e6e
--- /dev/null
+++ b/lib/api/entities/runner_details.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class RunnerDetails < Runner
+ expose :tag_list
+ expose :run_untagged
+ expose :locked
+ expose :maximum_timeout
+ expose :access_level
+ expose :version, :revision, :platform, :architecture
+ expose :contacted_at
+ expose :token, if: lambda { |runner, options| options[:current_user].admin? || !runner.instance_type? }
+ # rubocop: disable CodeReuse/ActiveRecord
+ expose :projects, with: Entities::BasicProjectDetails do |runner, options|
+ if options[:current_user].admin?
+ runner.projects
+ else
+ options[:current_user].authorized_projects.where(id: runner.projects)
+ end
+ end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
+ expose :groups, with: Entities::BasicGroupDetails do |runner, options|
+ if options[:current_user].admin?
+ runner.groups
+ else
+ options[:current_user].authorized_groups.where(id: runner.groups)
+ end
+ end
+ # rubocop: enable CodeReuse/ActiveRecord
+ end
+ end
+end
diff --git a/lib/api/entities/runner_registration_details.rb b/lib/api/entities/runner_registration_details.rb
new file mode 100644
index 00000000000..c8ed88ba10a
--- /dev/null
+++ b/lib/api/entities/runner_registration_details.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class RunnerRegistrationDetails < Grape::Entity
+ expose :id, :token
+ end
+ end
+end
diff --git a/lib/api/entities/tag.rb b/lib/api/entities/tag.rb
new file mode 100644
index 00000000000..2d3569bb9bb
--- /dev/null
+++ b/lib/api/entities/tag.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class Tag < Grape::Entity
+ expose :name, :message, :target
+
+ expose :commit, using: Entities::Commit do |repo_tag, options|
+ options[:project].repository.commit(repo_tag.dereferenced_target)
+ end
+
+ # rubocop: disable CodeReuse/ActiveRecord
+ expose :release, using: Entities::TagRelease do |repo_tag, options|
+ options[:project].releases.find_by(tag: repo_tag.name)
+ end
+ # rubocop: enable CodeReuse/ActiveRecord
+
+ expose :protected do |repo_tag, options|
+ ::ProtectedTag.protected?(options[:project], repo_tag.name)
+ end
+ end
+ end
+end
diff --git a/lib/api/project_container_repositories.rb b/lib/api/project_container_repositories.rb
index 2b33069e324..e2963c0de22 100644
--- a/lib/api/project_container_repositories.rb
+++ b/lib/api/project_container_repositories.rb
@@ -80,7 +80,7 @@ module API
render_api_error!(message, 400) unless obtain_new_cleanup_container_lease
CleanupContainerRepositoryWorker.perform_async(current_user.id, repository.id,
- declared_params.except(:repository_id))
+ declared_params.except(:repository_id).merge(container_expiration_policy: false))
track_event('delete_tag_bulk')
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