diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /app/serializers | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) | |
download | gitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'app/serializers')
29 files changed, 287 insertions, 76 deletions
diff --git a/app/serializers/build_artifact_entity.rb b/app/serializers/build_artifact_entity.rb index fac0fbd14b9..7a030372591 100644 --- a/app/serializers/build_artifact_entity.rb +++ b/app/serializers/build_artifact_entity.rb @@ -4,30 +4,28 @@ class BuildArtifactEntity < Grape::Entity include RequestAwareEntity include GitlabRoutingHelper - expose :name do |job| - job.name - end - - expose :artifacts_expired?, as: :expired - expose :artifacts_expire_at, as: :expire_at + alias_method :artifact, :object - expose :path do |job| - fast_download_project_job_artifacts_path(project, job) + expose :name do |artifact| + "#{artifact.job.name}:#{artifact.file_type}" end - expose :keep_path, if: -> (*) { job.has_expiring_archive_artifacts? } do |job| - fast_keep_project_job_artifacts_path(project, job) - end + expose :expire_at + expose :expired?, as: :expired - expose :browse_path do |job| - fast_browse_project_job_artifacts_path(project, job) + expose :path do |artifact| + fast_download_project_job_artifacts_path( + artifact.project, + artifact.job, + file_type: artifact.file_type + ) end - private - - alias_method :job, :object + expose :keep_path, if: -> (*) { artifact.expiring? } do |artifact| + fast_keep_project_job_artifacts_path(artifact.project, artifact.job) + end - def project - job.project + expose :browse_path do |artifact| + fast_browse_project_job_artifacts_path(artifact.project, artifact.job) end end diff --git a/app/serializers/ci/dag_job_entity.rb b/app/serializers/ci/dag_job_entity.rb index b4947319ed1..ed4d4505152 100644 --- a/app/serializers/ci/dag_job_entity.rb +++ b/app/serializers/ci/dag_job_entity.rb @@ -3,6 +3,7 @@ module Ci class DagJobEntity < Grape::Entity expose :name + expose :scheduling_type expose :needs, if: -> (job, _) { job.scheduling_type_dag? } do |job| job.needs.pluck(:name) # rubocop: disable CodeReuse/ActiveRecord diff --git a/app/serializers/ci/dag_pipeline_entity.rb b/app/serializers/ci/dag_pipeline_entity.rb index b615dd2b194..51aa487ec29 100644 --- a/app/serializers/ci/dag_pipeline_entity.rb +++ b/app/serializers/ci/dag_pipeline_entity.rb @@ -2,12 +2,12 @@ module Ci class DagPipelineEntity < Grape::Entity - expose :ordered_stages_with_preloads, as: :stages, using: Ci::DagStageEntity + expose :stages_with_preloads, as: :stages, using: Ci::DagStageEntity private - def ordered_stages_with_preloads - object.ordered_stages.preload(preloaded_relations) # rubocop: disable CodeReuse/ActiveRecord + def stages_with_preloads + object.stages.preload(preloaded_relations) # rubocop: disable CodeReuse/ActiveRecord end def preloaded_relations diff --git a/app/serializers/ci/daily_build_group_report_result_entity.rb b/app/serializers/ci/daily_build_group_report_result_entity.rb new file mode 100644 index 00000000000..e4118db9b1f --- /dev/null +++ b/app/serializers/ci/daily_build_group_report_result_entity.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Ci + class DailyBuildGroupReportResultEntity < Grape::Entity + expose :date + + ::Ci::DailyBuildGroupReportResult::PARAM_TYPES.each do |type| + expose type, if: lambda { |report_result, options| options[:param_type] == type } do |report_result, options| + report_result.data[options[:param_type]] + end + end + end +end diff --git a/app/serializers/ci/daily_build_group_report_result_serializer.rb b/app/serializers/ci/daily_build_group_report_result_serializer.rb new file mode 100644 index 00000000000..fdc693d01b2 --- /dev/null +++ b/app/serializers/ci/daily_build_group_report_result_serializer.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module Ci + class DailyBuildGroupReportResultSerializer < BaseSerializer + entity ::Ci::DailyBuildGroupReportResultEntity + + def represent(resource, opts = {}) + group(resource).map do |group_name, data| + { + group_name: group_name, + data: super(data, opts) + } + end + end + + private + + def group(resource) + collect(resource).group_by(&:group_name) + end + + def collect(resource) + return resource if resource.respond_to?(:group_by) + + [resource] + end + end +end diff --git a/app/serializers/cluster_entity.rb b/app/serializers/cluster_entity.rb index 4f53ea30544..8a1d41dbd96 100644 --- a/app/serializers/cluster_entity.rb +++ b/app/serializers/cluster_entity.rb @@ -8,6 +8,7 @@ class ClusterEntity < Grape::Entity expose :environment_scope expose :name expose :nodes + expose :provider_type expose :status_name, as: :status expose :status_reason expose :applications, using: ClusterApplicationEntity diff --git a/app/serializers/cluster_serializer.rb b/app/serializers/cluster_serializer.rb index f59b6a35a29..27156d3178f 100644 --- a/app/serializers/cluster_serializer.rb +++ b/app/serializers/cluster_serializer.rb @@ -13,6 +13,7 @@ class ClusterSerializer < BaseSerializer :name, :nodes, :path, + :provider_type, :status ] }) diff --git a/app/serializers/container_repository_entity.rb b/app/serializers/container_repository_entity.rb index 46aa0adc5a0..4c87d1438b0 100644 --- a/app/serializers/container_repository_entity.rb +++ b/app/serializers/container_repository_entity.rb @@ -3,7 +3,7 @@ class ContainerRepositoryEntity < Grape::Entity include RequestAwareEntity - expose :id, :name, :path, :location, :created_at, :status + expose :id, :name, :path, :location, :created_at, :status, :tags_count expose :tags_path do |repository| project_registry_repository_tags_path(project, repository, format: :json) diff --git a/app/serializers/diff_file_base_entity.rb b/app/serializers/diff_file_base_entity.rb index 8c2b3a65d57..33eb33d314b 100644 --- a/app/serializers/diff_file_base_entity.rb +++ b/app/serializers/diff_file_base_entity.rb @@ -67,10 +67,8 @@ class DiffFileBaseEntity < Grape::Entity end end - expose :file_hash do |diff_file| - Digest::SHA1.hexdigest(diff_file.file_path) - end - + expose :file_identifier_hash + expose :file_hash expose :file_path expose :old_path expose :new_path diff --git a/app/serializers/diff_file_metadata_entity.rb b/app/serializers/diff_file_metadata_entity.rb index 05280518f39..460f4967e99 100644 --- a/app/serializers/diff_file_metadata_entity.rb +++ b/app/serializers/diff_file_metadata_entity.rb @@ -7,7 +7,6 @@ class DiffFileMetadataEntity < Grape::Entity expose :old_path expose :new_file?, as: :new_file expose :deleted_file?, as: :deleted_file - expose :file_hash do |diff_file| - Digest::SHA1.hexdigest(diff_file.file_path) - end + expose :file_identifier_hash + expose :file_hash end diff --git a/app/serializers/diffs_entity.rb b/app/serializers/diffs_entity.rb index fb4fbe57130..6ef524b5bec 100644 --- a/app/serializers/diffs_entity.rb +++ b/app/serializers/diffs_entity.rb @@ -69,19 +69,17 @@ class DiffsEntity < Grape::Entity expose :diff_files do |diffs, options| submodule_links = Gitlab::SubmoduleLinks.new(merge_request.project.repository) - code_navigation_path = - Gitlab::CodeNavigationPath.new(merge_request.project, diffs.diff_refs.head_sha) DiffFileEntity.represent(diffs.diff_files, - options.merge(submodule_links: submodule_links, code_navigation_path: code_navigation_path)) + options.merge(submodule_links: submodule_links, code_navigation_path: code_navigation_path(diffs))) end expose :merge_request_diffs, using: MergeRequestDiffEntity, if: -> (_, options) { options[:merge_request_diffs]&.any? } do |diffs| options[:merge_request_diffs] end - expose :definition_path_prefix, if: -> (diff_file) { Feature.enabled?(:code_navigation, merge_request.project) } do |diffs| - project_blob_path(merge_request.project, diffs.diff_refs.head_sha) + expose :definition_path_prefix, if: -> (diff_file) { Feature.enabled?(:code_navigation, merge_request.project, default_enabled: true) } do |diffs| + project_blob_path(merge_request.project, diffs.diff_refs&.head_sha) end def merge_request @@ -90,6 +88,12 @@ class DiffsEntity < Grape::Entity private + def code_navigation_path(diffs) + return unless Feature.enabled?(:code_navigation, merge_request.project, default_enabled: true) + + Gitlab::CodeNavigationPath.new(merge_request.project, diffs.diff_refs&.head_sha) + end + def commit_ids @commit_ids ||= merge_request.recent_commits.map(&:id) end diff --git a/app/serializers/draft_note_entity.rb b/app/serializers/draft_note_entity.rb new file mode 100644 index 00000000000..cab4849ebc9 --- /dev/null +++ b/app/serializers/draft_note_entity.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true +class DraftNoteEntity < Grape::Entity + include RequestAwareEntity + + expose :id + expose :author, using: NoteUserEntity + expose :merge_request_id + expose :position, if: -> (note, _) { note.on_diff? } + expose :line_code + expose :file_identifier_hash + expose :file_hash + expose :file_path + expose :note + expose :rendered_note, as: :note_html + expose :references + expose :discussion_id + expose :resolve_discussion + expose :noteable_type + + expose :current_user do + expose :can_edit do |note| + can?(current_user, :admin_note, note) + end + + expose :can_award_emoji do |note| + note.emoji_awardable? + end + + expose :can_resolve do |note| + note.resolvable? && can?(current_user, :resolve_note, note) + end + end + + private + + def current_user + request.current_user + end +end diff --git a/app/serializers/draft_note_serializer.rb b/app/serializers/draft_note_serializer.rb new file mode 100644 index 00000000000..282d7f9bdda --- /dev/null +++ b/app/serializers/draft_note_serializer.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true +class DraftNoteSerializer < BaseSerializer + entity DraftNoteEntity +end diff --git a/app/serializers/import/base_provider_repo_entity.rb b/app/serializers/import/base_provider_repo_entity.rb new file mode 100644 index 00000000000..88a831a1686 --- /dev/null +++ b/app/serializers/import/base_provider_repo_entity.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class Import::BaseProviderRepoEntity < Grape::Entity + expose :id + expose :full_name + expose :sanitized_name + expose :provider_link +end diff --git a/app/serializers/import/bitbucket_provider_repo_entity.rb b/app/serializers/import/bitbucket_provider_repo_entity.rb new file mode 100644 index 00000000000..e8c647d407e --- /dev/null +++ b/app/serializers/import/bitbucket_provider_repo_entity.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class Import::BitbucketProviderRepoEntity < Import::BaseProviderRepoEntity + expose :id, override: true do |repo| + repo.full_name + end + + expose :sanitized_name, override: true do |repo| + repo.name.gsub(/[^\s\w.-]/, '') + end + + expose :provider_link, override: true do |repo, options| + repo.clone_url + end +end diff --git a/app/serializers/import/bitbucket_server_provider_repo_entity.rb b/app/serializers/import/bitbucket_server_provider_repo_entity.rb new file mode 100644 index 00000000000..d818cac46cd --- /dev/null +++ b/app/serializers/import/bitbucket_server_provider_repo_entity.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class Import::BitbucketServerProviderRepoEntity < Import::BitbucketProviderRepoEntity + expose :provider_link, override: true do |repo, options| + repo.browse_url + end +end diff --git a/app/serializers/import/fogbugz_provider_repo_entity.rb b/app/serializers/import/fogbugz_provider_repo_entity.rb new file mode 100644 index 00000000000..d420de141e1 --- /dev/null +++ b/app/serializers/import/fogbugz_provider_repo_entity.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class Import::FogbugzProviderRepoEntity < Import::BaseProviderRepoEntity + include ImportHelper + + expose :full_name, override: true do |repo| + repo.name + end + + expose :sanitized_name, override: true do |repo| + repo.safe_name + end + + expose :provider_link, override: true do |repo, options| + provider_project_link_url(options[:provider_url], repo.path) + end +end diff --git a/app/serializers/provider_repo_entity.rb b/app/serializers/import/githubish_provider_repo_entity.rb index d70aaa91324..d3e323053f9 100644 --- a/app/serializers/provider_repo_entity.rb +++ b/app/serializers/import/githubish_provider_repo_entity.rb @@ -1,19 +1,13 @@ # frozen_string_literal: true -class ProviderRepoEntity < Grape::Entity +class Import::GithubishProviderRepoEntity < Import::BaseProviderRepoEntity include ImportHelper - expose :id - expose :full_name - expose :owner_name do |provider_repo, options| - owner_name(provider_repo, options[:provider]) - end - - expose :sanitized_name do |provider_repo| + expose :sanitized_name, override: true do |provider_repo| sanitize_project_name(provider_repo[:name]) end - expose :provider_link do |provider_repo, options| + expose :provider_link, override: true do |provider_repo, options| provider_project_link_url(options[:provider_url], provider_repo[:full_name]) end diff --git a/app/serializers/import/gitlab_provider_repo_entity.rb b/app/serializers/import/gitlab_provider_repo_entity.rb new file mode 100644 index 00000000000..5fecd0a1cd3 --- /dev/null +++ b/app/serializers/import/gitlab_provider_repo_entity.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class Import::GitlabProviderRepoEntity < Import::BaseProviderRepoEntity + expose :id, override: true do |repo| + repo["id"] + end + + expose :full_name, override: true do |repo| + repo["path_with_namespace"] + end + + expose :sanitized_name, override: true do |repo| + repo["path"] + end + + expose :provider_link, override: true do |repo| + repo["web_url"] + end +end diff --git a/app/serializers/import/provider_repo_serializer.rb b/app/serializers/import/provider_repo_serializer.rb new file mode 100644 index 00000000000..5a9549d79aa --- /dev/null +++ b/app/serializers/import/provider_repo_serializer.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class Import::ProviderRepoSerializer < BaseSerializer + def represent(repo, opts = {}) + entity = + case opts[:provider] + when :fogbugz + Import::FogbugzProviderRepoEntity + when :github, :gitea + Import::GithubishProviderRepoEntity + when :bitbucket + Import::BitbucketProviderRepoEntity + when :bitbucket_server + Import::BitbucketServerProviderRepoEntity + when :gitlab + Import::GitlabProviderRepoEntity + else + raise NotImplementedError + end + + super(repo, opts, entity) + end +end diff --git a/app/serializers/merge_request_noteable_entity.rb b/app/serializers/merge_request_noteable_entity.rb index 8e7456ce059..a356b5b5cd4 100644 --- a/app/serializers/merge_request_noteable_entity.rb +++ b/app/serializers/merge_request_noteable_entity.rb @@ -50,6 +50,8 @@ class MergeRequestNoteableEntity < IssuableEntity merge_request.project.archived? end + expose :project_id + expose :archived_project_docs_path, if: -> (merge_request) { merge_request.project.archived? } do |merge_request| help_page_path('user/project/settings/index.md', anchor: 'archiving-a-project') end diff --git a/app/serializers/paginated_diff_entity.rb b/app/serializers/paginated_diff_entity.rb index a31c9d70d4b..37c48338e55 100644 --- a/app/serializers/paginated_diff_entity.rb +++ b/app/serializers/paginated_diff_entity.rb @@ -10,11 +10,9 @@ class PaginatedDiffEntity < Grape::Entity expose :diff_files do |diffs, options| submodule_links = Gitlab::SubmoduleLinks.new(merge_request.project.repository) - code_navigation_path = - Gitlab::CodeNavigationPath.new(merge_request.project, diffs.diff_refs.head_sha) DiffFileEntity.represent(diffs.diff_files, - options.merge(submodule_links: submodule_links, code_navigation_path: code_navigation_path)) + options.merge(submodule_links: submodule_links, code_navigation_path: code_navigation_path(diffs))) end expose :pagination do @@ -38,6 +36,12 @@ class PaginatedDiffEntity < Grape::Entity private + def code_navigation_path(diffs) + return unless Feature.enabled?(:code_navigation, merge_request.project, default_enabled: true) + + Gitlab::CodeNavigationPath.new(merge_request.project, diffs.diff_refs&.head_sha) + end + %i[current_page next_page total_pages].each do |method| define_method method do pagination_data[method] diff --git a/app/serializers/pipeline_details_entity.rb b/app/serializers/pipeline_details_entity.rb index a58278cf4ef..50efa9ea15d 100644 --- a/app/serializers/pipeline_details_entity.rb +++ b/app/serializers/pipeline_details_entity.rb @@ -9,8 +9,7 @@ class PipelineDetailsEntity < PipelineEntity expose :details do expose :artifacts do |pipeline, options| - rel = pipeline.artifacts - rel = rel.eager_load_job_artifacts_archive if options.fetch(:preload_job_artifacts_archive, true) + rel = pipeline.downloadable_artifacts BuildArtifactEntity.represent(rel, options) end diff --git a/app/serializers/pipeline_serializer.rb b/app/serializers/pipeline_serializer.rb index b2c0ceb640b..21d49c6c292 100644 --- a/app/serializers/pipeline_serializer.rb +++ b/app/serializers/pipeline_serializer.rb @@ -7,10 +7,6 @@ class PipelineSerializer < BaseSerializer # rubocop: disable CodeReuse/ActiveRecord def represent(resource, opts = {}) if resource.is_a?(ActiveRecord::Relation) - # We don't want PipelineDetailsEntity to preload the job_artifacts_archive - # because we do it with preloaded_relations in a more optimal way - # if the given resource is a collection of multiple pipelines. - opts[:preload_job_artifacts_archive] = false resource = resource.preload(preloaded_relations) end @@ -44,35 +40,29 @@ class PipelineSerializer < BaseSerializer def preloaded_relations [ - :latest_statuses_ordered_by_stage, - :project, - :stages, - { - failed_builds: %i(project metadata) - }, - :retryable_builds, :cancelable_statuses, - :trigger_requests, + :latest_statuses_ordered_by_stage, :manual_actions, + :retryable_builds, :scheduled_actions, - :artifacts, + :stages, + :trigger_requests, :user, { + downloadable_artifacts: { + project: [:route, { namespace: :route }], + job: [] + }, + failed_builds: %i(project metadata), merge_request: { source_project: [:route, { namespace: :route }], target_project: [:route, { namespace: :route }] - } - }, - { + }, pending_builds: :project, project: [:route, { namespace: :route }], - artifacts: { - project: [:route, { namespace: :route }], - job_artifacts_archive: [] - } - }, - { triggered_by_pipeline: [:project, :user] }, - { triggered_pipelines: [:project, :user] } + triggered_by_pipeline: [:project, :user], + triggered_pipelines: [:project, :user] + } ] end end diff --git a/app/serializers/provider_repo_serializer.rb b/app/serializers/provider_repo_serializer.rb deleted file mode 100644 index 8a73f6fe6df..00000000000 --- a/app/serializers/provider_repo_serializer.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -class ProviderRepoSerializer < BaseSerializer - entity ProviderRepoEntity -end diff --git a/app/serializers/service_field_entity.rb b/app/serializers/service_field_entity.rb new file mode 100644 index 00000000000..9929d7e2e5a --- /dev/null +++ b/app/serializers/service_field_entity.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class ServiceFieldEntity < Grape::Entity + include RequestAwareEntity + + expose :type, :name, :title, :placeholder, :required, :choices, :help + + expose :value do |field| + # field[:name] is not user input and so can assume is safe + value = service.public_send(field[:name]) # rubocop:disable GitlabSecurity/PublicSend + + if field[:type] == 'password' && value.present? + 'true' + else + value + end + end + + private + + def service + request.service + end +end diff --git a/app/serializers/service_field_serializer.rb b/app/serializers/service_field_serializer.rb new file mode 100644 index 00000000000..120d0f5820e --- /dev/null +++ b/app/serializers/service_field_serializer.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class ServiceFieldSerializer < BaseSerializer + entity ServiceFieldEntity +end diff --git a/app/serializers/web_ide_terminal_entity.rb b/app/serializers/web_ide_terminal_entity.rb new file mode 100644 index 00000000000..e2e90e824e7 --- /dev/null +++ b/app/serializers/web_ide_terminal_entity.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class WebIdeTerminalEntity < Grape::Entity + expose :id + expose :status + expose :show_path + expose :cancel_path + expose :retry_path + expose :terminal_path + expose :services + expose :proxy_websocket_path, if: ->(_) { Feature.enabled?(:build_service_proxy) } +end diff --git a/app/serializers/web_ide_terminal_serializer.rb b/app/serializers/web_ide_terminal_serializer.rb new file mode 100644 index 00000000000..5a9c4b99e0a --- /dev/null +++ b/app/serializers/web_ide_terminal_serializer.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class WebIdeTerminalSerializer < BaseSerializer + entity WebIdeTerminalEntity + + def represent(resource, opts = {}) + resource = WebIdeTerminal.new(resource) if resource.is_a?(Ci::Build) + + super + end +end |