diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /app/serializers | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) | |
download | gitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'app/serializers')
25 files changed, 209 insertions, 30 deletions
diff --git a/app/serializers/build_details_entity.rb b/app/serializers/build_details_entity.rb index df1bdc2b7a4..523f1a0f8c6 100644 --- a/app/serializers/build_details_entity.rb +++ b/app/serializers/build_details_entity.rb @@ -27,11 +27,11 @@ class BuildDetailsEntity < JobEntity end expose :artifact, if: -> (*) { can?(current_user, :read_build, build) } do - expose :download_path, if: -> (*) { build.artifacts? } do |build| + expose :download_path, if: -> (*) { build.pipeline.artifacts_locked? || build.artifacts? } do |build| download_project_job_artifacts_path(project, build) end - expose :browse_path, if: -> (*) { build.browsable_artifacts? } do |build| + expose :browse_path, if: -> (*) { build.pipeline.artifacts_locked? || build.browsable_artifacts? } do |build| browse_project_job_artifacts_path(project, build) end @@ -46,6 +46,10 @@ class BuildDetailsEntity < JobEntity expose :expired, if: -> (*) { build.artifacts_expire_at.present? } do |build| build.artifacts_expired? end + + expose :locked do |build| + build.pipeline.artifacts_locked? + end end expose :report_artifacts, @@ -147,7 +151,7 @@ class BuildDetailsEntity < JobEntity end def help_message(docs_url) - _("Please refer to <a href=\"%{docs_url}\">%{docs_url}</a>") % { docs_url: docs_url } + html_escape(_("Please refer to %{docs_url}")) % { docs_url: "<a href=\"#{docs_url}\">#{html_escape(docs_url)}</a>".html_safe } end end diff --git a/app/serializers/cluster_entity.rb b/app/serializers/cluster_entity.rb index a46f2889a96..06e14179238 100644 --- a/app/serializers/cluster_entity.rb +++ b/app/serializers/cluster_entity.rb @@ -20,4 +20,8 @@ class ClusterEntity < Grape::Entity expose :gitlab_managed_apps_logs_path do |cluster| Clusters::ClusterPresenter.new(cluster, current_user: request.current_user).gitlab_managed_apps_logs_path # rubocop: disable CodeReuse/Presenter end + + expose :kubernetes_errors do |cluster| + ClusterErrorEntity.new(cluster) + end end diff --git a/app/serializers/cluster_error_entity.rb b/app/serializers/cluster_error_entity.rb new file mode 100644 index 00000000000..c749537cb94 --- /dev/null +++ b/app/serializers/cluster_error_entity.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class ClusterErrorEntity < Grape::Entity + expose :connection_error + expose :metrics_connection_error + expose :node_connection_error +end diff --git a/app/serializers/cluster_serializer.rb b/app/serializers/cluster_serializer.rb index 92363a4942c..a70458d2bcb 100644 --- a/app/serializers/cluster_serializer.rb +++ b/app/serializers/cluster_serializer.rb @@ -11,6 +11,7 @@ class ClusterSerializer < BaseSerializer :enabled, :environment_scope, :gitlab_managed_apps_logs_path, + :kubernetes_errors, :name, :nodes, :path, diff --git a/app/serializers/diffs_metadata_entity.rb b/app/serializers/diffs_metadata_entity.rb index b7024721ea9..8973f23734a 100644 --- a/app/serializers/diffs_metadata_entity.rb +++ b/app/serializers/diffs_metadata_entity.rb @@ -3,4 +3,23 @@ class DiffsMetadataEntity < DiffsEntity unexpose :diff_files expose :raw_diff_files, as: :diff_files, using: DiffFileMetadataEntity + + expose :conflict_resolution_path do |_, options| + presenter(options[:merge_request]).conflict_resolution_path + end + + expose :has_conflicts do |_, options| + options[:merge_request].cannot_be_merged? + end + + expose :can_merge do |_, options| + options[:merge_request].can_be_merged_by?(request.current_user) + end + + private + + def presenter(merge_request) + @presenters ||= {} + @presenters[merge_request] ||= MergeRequestPresenter.new(merge_request, current_user: request.current_user) # rubocop: disable CodeReuse/Presenter + end end diff --git a/app/serializers/discussion_entity.rb b/app/serializers/discussion_entity.rb index 77881eaba0c..2957205a81c 100644 --- a/app/serializers/discussion_entity.rb +++ b/app/serializers/discussion_entity.rb @@ -72,6 +72,6 @@ class DiscussionEntity < Grape::Entity return unless discussion.diff_discussion? return if discussion.legacy_diff_discussion? - Feature.enabled?(:merge_ref_head_comments, discussion.project) + Feature.enabled?(:merge_ref_head_comments, discussion.project, default_enabled: true) end end diff --git a/app/serializers/environment_entity.rb b/app/serializers/environment_entity.rb index 7da5910a75b..a2bf9716f8f 100644 --- a/app/serializers/environment_entity.rb +++ b/app/serializers/environment_entity.rb @@ -71,6 +71,8 @@ class EnvironmentEntity < Grape::Entity can?(current_user, :destroy_environment, environment) end + expose :has_opened_alert?, if: -> (*) { can_read_alert_management_alert? }, expose_nil: false, as: :has_opened_alert + private alias_method :environment, :object @@ -91,6 +93,10 @@ class EnvironmentEntity < Grape::Entity can?(current_user, :read_pod_logs, environment.project) end + def can_read_alert_management_alert? + can?(current_user, :read_alert_management_alert, environment.project) + end + def cluster_platform_kubernetes? deployment_platform && deployment_platform.is_a?(Clusters::Platforms::Kubernetes) end diff --git a/app/serializers/group_basic_entity.rb b/app/serializers/group_basic_entity.rb new file mode 100644 index 00000000000..24a05100d43 --- /dev/null +++ b/app/serializers/group_basic_entity.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class GroupBasicEntity < Grape::Entity + include RequestAwareEntity + + expose :id + expose :name + expose :full_path + expose :full_name +end diff --git a/app/serializers/group_deploy_key_entity.rb b/app/serializers/group_deploy_key_entity.rb new file mode 100644 index 00000000000..c0bb0448a51 --- /dev/null +++ b/app/serializers/group_deploy_key_entity.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class GroupDeployKeyEntity < Grape::Entity + expose :id + expose :user_id + expose :title + expose :fingerprint + expose :fingerprint_sha256 + expose :created_at + expose :updated_at + expose :group_deploy_keys_groups, using: GroupDeployKeysGroupEntity do |group_deploy_key| + group_deploy_key.group_deploy_keys_groups_for_user(options[:user]) + end + expose :can_edit do |group_deploy_key| + group_deploy_key.can_be_edited_for?(options[:user], options[:group]) + end +end diff --git a/app/serializers/group_deploy_key_serializer.rb b/app/serializers/group_deploy_key_serializer.rb new file mode 100644 index 00000000000..e7d5f6a77ea --- /dev/null +++ b/app/serializers/group_deploy_key_serializer.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class GroupDeployKeySerializer < BaseSerializer + entity GroupDeployKeyEntity +end diff --git a/app/serializers/group_deploy_keys_group_entity.rb b/app/serializers/group_deploy_keys_group_entity.rb new file mode 100644 index 00000000000..f2801dfc112 --- /dev/null +++ b/app/serializers/group_deploy_keys_group_entity.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +class GroupDeployKeysGroupEntity < Grape::Entity + expose :can_push + expose :group, using: GroupBasicEntity +end diff --git a/app/serializers/import/bitbucket_server_provider_repo_entity.rb b/app/serializers/import/bitbucket_server_provider_repo_entity.rb index d818cac46cd..7c619cf4ebe 100644 --- a/app/serializers/import/bitbucket_server_provider_repo_entity.rb +++ b/app/serializers/import/bitbucket_server_provider_repo_entity.rb @@ -1,6 +1,10 @@ # frozen_string_literal: true class Import::BitbucketServerProviderRepoEntity < Import::BitbucketProviderRepoEntity + expose :id, override: true do |repo| + "#{repo.project_key}/#{repo.slug}" + end + expose :provider_link, override: true do |repo, options| repo.browse_url end diff --git a/app/serializers/import/manifest_provider_repo_entity.rb b/app/serializers/import/manifest_provider_repo_entity.rb new file mode 100644 index 00000000000..5da9aae80a8 --- /dev/null +++ b/app/serializers/import/manifest_provider_repo_entity.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class Import::ManifestProviderRepoEntity < Import::BaseProviderRepoEntity + expose :id + expose :full_name, override: true do |repo| + repo[:url] + end + + expose :provider_link, override: true do |repo| + repo[:url] + end + + expose :target do |repo, options| + import_project_target(options[:group_full_path], repo[:path], options[:request].current_user) + end + + private + + def import_project_target(owner, name, user) + namespace = user.can_create_group? ? owner : user.namespace_path + "#{namespace}/#{name}" + end +end diff --git a/app/serializers/import/provider_repo_serializer.rb b/app/serializers/import/provider_repo_serializer.rb index 5a9549d79aa..edd1a260146 100644 --- a/app/serializers/import/provider_repo_serializer.rb +++ b/app/serializers/import/provider_repo_serializer.rb @@ -14,6 +14,8 @@ class Import::ProviderRepoSerializer < BaseSerializer Import::BitbucketServerProviderRepoEntity when :gitlab Import::GitlabProviderRepoEntity + when :manifest + Import::ManifestProviderRepoEntity else raise NotImplementedError end diff --git a/app/serializers/merge_request_poll_widget_entity.rb b/app/serializers/merge_request_poll_widget_entity.rb index a365ebc29c9..99d6211b487 100644 --- a/app/serializers/merge_request_poll_widget_entity.rb +++ b/app/serializers/merge_request_poll_widget_entity.rb @@ -19,9 +19,21 @@ class MergeRequestPollWidgetEntity < Grape::Entity # User entities expose :merge_user, using: UserEntity - expose :actual_head_pipeline, with: PipelineDetailsEntity, as: :pipeline, if: -> (mr, _) { presenter(mr).can_read_pipeline? } + expose :actual_head_pipeline, as: :pipeline, if: -> (mr, _) { presenter(mr).can_read_pipeline? } do |merge_request, options| + if Feature.enabled?(:merge_request_short_pipeline_serializer, merge_request.project, default_enabled: true) + MergeRequests::PipelineEntity.represent(merge_request.actual_head_pipeline, options) + else + PipelineDetailsEntity.represent(merge_request.actual_head_pipeline, options) + end + end - expose :merge_pipeline, with: PipelineDetailsEntity, if: ->(mr, _) { mr.merged? && can?(request.current_user, :read_pipeline, mr.target_project)} + expose :merge_pipeline, if: ->(mr, _) { mr.merged? && can?(request.current_user, :read_pipeline, mr.target_project)} do |merge_request, options| + if Feature.enabled?(:merge_request_short_pipeline_serializer, merge_request.project, default_enabled: true) + MergeRequests::PipelineEntity.represent(merge_request.merge_pipeline, options) + else + PipelineDetailsEntity.represent(merge_request.merge_pipeline, options) + end + end expose :default_merge_commit_message diff --git a/app/serializers/merge_request_widget_entity.rb b/app/serializers/merge_request_widget_entity.rb index 2a7afb57314..b7b9e7d1036 100644 --- a/app/serializers/merge_request_widget_entity.rb +++ b/app/serializers/merge_request_widget_entity.rb @@ -3,6 +3,8 @@ class MergeRequestWidgetEntity < Grape::Entity include RequestAwareEntity + SUGGEST_PIPELINE = 'suggest_pipeline' + expose :id expose :iid @@ -14,6 +16,10 @@ class MergeRequestWidgetEntity < Grape::Entity merge_request.project&.full_path end + expose :can_create_pipeline_in_target_project do |merge_request| + can?(current_user, :create_pipeline, merge_request.target_project) + end + expose :email_patches_path do |merge_request| project_merge_request_path(merge_request.project, merge_request, format: :patch) end @@ -60,6 +66,18 @@ class MergeRequestWidgetEntity < Grape::Entity ) end + expose :user_callouts_path, if: -> (*) { Feature.enabled?(:suggest_pipeline) } do |merge_request| + user_callouts_path + end + + expose :suggest_pipeline_feature_id, if: -> (*) { Feature.enabled?(:suggest_pipeline) } do |merge_request| + SUGGEST_PIPELINE + end + + expose :is_dismissed_suggest_pipeline, if: -> (*) { Feature.enabled?(:suggest_pipeline) } do |merge_request| + current_user && current_user.dismissed_callout?(feature_name: SUGGEST_PIPELINE) + end + expose :human_access do |merge_request| merge_request.project.team.human_max_access(current_user&.id) end @@ -119,7 +137,7 @@ class MergeRequestWidgetEntity < Grape::Entity merge_request.source_branch_exists? && merge_request.source_project&.uses_default_ci_config? && !merge_request.source_project.has_ci? && - merge_request.commits_count.positive? && + merge_request.commits_count > 0 && can?(current_user, :read_build, merge_request.source_project) && can?(current_user, :create_pipeline, merge_request.source_project) end diff --git a/app/serializers/merge_requests/pipeline_entity.rb b/app/serializers/merge_requests/pipeline_entity.rb new file mode 100644 index 00000000000..97d7620154e --- /dev/null +++ b/app/serializers/merge_requests/pipeline_entity.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +class MergeRequests::PipelineEntity < Grape::Entity + include RequestAwareEntity + + expose :id + expose :active?, as: :active + + expose :path do |pipeline| + project_pipeline_path(pipeline.project, pipeline) + end + + expose :flags do + expose :merge_request_pipeline?, as: :merge_request_pipeline + end + + expose :commit, using: CommitEntity + + expose :details do + expose :name do |pipeline| + pipeline.present.name + end + + expose :detailed_status, as: :status, with: DetailedStatusEntity do |pipeline| + pipeline.detailed_status(request.current_user) + end + + expose :stages, using: StageEntity + end + + # Coverage isn't always necessary (e.g. when displaying project pipelines in + # the UI). Instead of creating an entirely different entity we just allow the + # disabling of this specific field whenever necessary. + expose :coverage, unless: proc { options[:disable_coverage] } + + expose :ref do + expose :branch?, as: :branch + end + + expose :triggered_by_pipeline, as: :triggered_by, with: TriggeredPipelineEntity + expose :triggered_pipelines, as: :triggered, using: TriggeredPipelineEntity +end diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index 8333a0bb863..de1e07139ad 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -36,7 +36,7 @@ class PipelineEntity < Grape::Entity expose :details do expose :detailed_status, as: :status, with: DetailedStatusEntity - expose :ordered_stages, as: :stages, using: StageEntity + expose :stages, using: StageEntity expose :duration expose :finished_at expose :name @@ -85,8 +85,8 @@ class PipelineEntity < Grape::Entity pipeline.failed_builds end - expose :tests_total_count, if: -> (pipeline, _) { Feature.enabled?(:build_report_summary, pipeline.project) } do |pipeline| - pipeline.test_report_summary.total_count + expose :tests_total_count do |pipeline| + pipeline.test_report_summary.total[:count] end private diff --git a/app/serializers/pipeline_serializer.rb b/app/serializers/pipeline_serializer.rb index bfd6851647f..45c5a1d3e1c 100644 --- a/app/serializers/pipeline_serializer.rb +++ b/app/serializers/pipeline_serializer.rb @@ -42,6 +42,7 @@ class PipelineSerializer < BaseSerializer [ :cancelable_statuses, :latest_statuses_ordered_by_stage, + :latest_builds_report_results, :manual_actions, :retryable_builds, :scheduled_actions, diff --git a/app/serializers/prometheus_alert_entity.rb b/app/serializers/prometheus_alert_entity.rb index 413be511903..92905d2b389 100644 --- a/app/serializers/prometheus_alert_entity.rb +++ b/app/serializers/prometheus_alert_entity.rb @@ -7,6 +7,7 @@ class PrometheusAlertEntity < Grape::Entity expose :title expose :query expose :threshold + expose :runbook_url expose :operator do |prometheus_alert| prometheus_alert.computed_operator diff --git a/app/serializers/release_entity.rb b/app/serializers/release_entity.rb new file mode 100644 index 00000000000..6777b0f9780 --- /dev/null +++ b/app/serializers/release_entity.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +class ReleaseEntity < Grape::Entity + expose :id + expose :tag # see https://gitlab.com/gitlab-org/gitlab/-/issues/36338 +end diff --git a/app/serializers/release_serializer.rb b/app/serializers/release_serializer.rb new file mode 100644 index 00000000000..05a13f71a6f --- /dev/null +++ b/app/serializers/release_serializer.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class ReleaseSerializer < BaseSerializer + entity ReleaseEntity +end diff --git a/app/serializers/suggestion_entity.rb b/app/serializers/suggestion_entity.rb index c9fcbe14f2e..c224d0b4390 100644 --- a/app/serializers/suggestion_entity.rb +++ b/app/serializers/suggestion_entity.rb @@ -16,24 +16,8 @@ class SuggestionEntity < API::Entities::Suggestion expose :inapplicable_reason do |suggestion| next _("You don't have write access to the source branch.") unless can_apply?(suggestion) - next if suggestion.appliable? - case suggestion.inapplicable_reason - when :merge_request_merged - _("This merge request was merged. To apply this suggestion, edit this file directly.") - when :merge_request_closed - _("This merge request is closed. To apply this suggestion, edit this file directly.") - when :source_branch_deleted - _("Can't apply as the source branch was deleted.") - when :outdated - phrase = suggestion.single_line? ? 'this line was' : 'these lines were' - - _("Can't apply as %{phrase} changed in a more recent version.") % { phrase: phrase } - when :same_content - _("This suggestion already matches its content.") - else - _("Can't apply this suggestion.") - end + suggestion.inapplicable_reason end private diff --git a/app/serializers/test_report_summary_entity.rb b/app/serializers/test_report_summary_entity.rb index 5995ca007d6..bc73c49092f 100644 --- a/app/serializers/test_report_summary_entity.rb +++ b/app/serializers/test_report_summary_entity.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true -class TestReportSummaryEntity < TestReportEntity +class TestReportSummaryEntity < Grape::Entity + expose :total + expose :test_suites, using: TestSuiteSummaryEntity do |summary| summary.test_suites.values end diff --git a/app/serializers/triggered_pipeline_entity.rb b/app/serializers/triggered_pipeline_entity.rb index 47f51a6d76a..9fdadb322bf 100644 --- a/app/serializers/triggered_pipeline_entity.rb +++ b/app/serializers/triggered_pipeline_entity.rb @@ -24,8 +24,8 @@ class TriggeredPipelineEntity < Grape::Entity expose :details do expose :detailed_status, as: :status, with: DetailedStatusEntity - expose :ordered_stages, - as: :stages, using: StageEntity, + expose :stages, + using: StageEntity, if: -> (_, opts) { can_read_details? && expand?(opts) } end |