diff options
Diffstat (limited to 'app/serializers')
28 files changed, 228 insertions, 33 deletions
diff --git a/app/serializers/accessibility_error_entity.rb b/app/serializers/accessibility_error_entity.rb new file mode 100644 index 00000000000..540f5384d66 --- /dev/null +++ b/app/serializers/accessibility_error_entity.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class AccessibilityErrorEntity < Grape::Entity + expose :code + expose :type + expose :typeCode, as: :type_code + expose :message + expose :context + expose :selector + expose :runner + expose :runnerExtras, as: :runner_extras +end diff --git a/app/serializers/accessibility_reports_comparer_entity.rb b/app/serializers/accessibility_reports_comparer_entity.rb new file mode 100644 index 00000000000..3768607a3fc --- /dev/null +++ b/app/serializers/accessibility_reports_comparer_entity.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AccessibilityReportsComparerEntity < Grape::Entity + expose :status + + expose :new_errors, using: AccessibilityErrorEntity + expose :resolved_errors, using: AccessibilityErrorEntity + expose :existing_errors, using: AccessibilityErrorEntity + + expose :summary do + expose :total_count, as: :total + expose :resolved_count, as: :resolved + expose :errors_count, as: :errored + end +end diff --git a/app/serializers/accessibility_reports_comparer_serializer.rb b/app/serializers/accessibility_reports_comparer_serializer.rb new file mode 100644 index 00000000000..a6b8162e4ea --- /dev/null +++ b/app/serializers/accessibility_reports_comparer_serializer.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class AccessibilityReportsComparerSerializer < BaseSerializer + entity AccessibilityReportsComparerEntity +end diff --git a/app/serializers/analytics_summary_entity.rb b/app/serializers/analytics_summary_entity.rb index 57e9225e2da..62828fc1428 100644 --- a/app/serializers/analytics_summary_entity.rb +++ b/app/serializers/analytics_summary_entity.rb @@ -8,8 +8,6 @@ class AnalyticsSummaryEntity < Grape::Entity private def value - return object.value if object.value.is_a? String - - object.value&.nonzero? ? object.value.to_s : '-' + object.value.to_s end end diff --git a/app/serializers/ci/basic_variable_entity.rb b/app/serializers/ci/basic_variable_entity.rb new file mode 100644 index 00000000000..dad59e8735b --- /dev/null +++ b/app/serializers/ci/basic_variable_entity.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Ci + class BasicVariableEntity < Grape::Entity + expose :id + expose :key + expose :value + expose :variable_type + + expose :protected?, as: :protected + expose :masked?, as: :masked + end +end diff --git a/app/serializers/ci/dag_job_entity.rb b/app/serializers/ci/dag_job_entity.rb new file mode 100644 index 00000000000..b4947319ed1 --- /dev/null +++ b/app/serializers/ci/dag_job_entity.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Ci + class DagJobEntity < Grape::Entity + expose :name + + expose :needs, if: -> (job, _) { job.scheduling_type_dag? } do |job| + job.needs.pluck(:name) # rubocop: disable CodeReuse/ActiveRecord + end + end +end diff --git a/app/serializers/ci/dag_job_group_entity.rb b/app/serializers/ci/dag_job_group_entity.rb new file mode 100644 index 00000000000..ac1ed89281c --- /dev/null +++ b/app/serializers/ci/dag_job_group_entity.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module Ci + class DagJobGroupEntity < Grape::Entity + expose :name + expose :size + expose :jobs, with: Ci::DagJobEntity + end +end diff --git a/app/serializers/ci/dag_pipeline_entity.rb b/app/serializers/ci/dag_pipeline_entity.rb new file mode 100644 index 00000000000..b615dd2b194 --- /dev/null +++ b/app/serializers/ci/dag_pipeline_entity.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Ci + class DagPipelineEntity < Grape::Entity + expose :ordered_stages_with_preloads, as: :stages, using: Ci::DagStageEntity + + private + + def ordered_stages_with_preloads + object.ordered_stages.preload(preloaded_relations) # rubocop: disable CodeReuse/ActiveRecord + end + + def preloaded_relations + [ + :project, + { latest_statuses: :needs } + ] + end + end +end diff --git a/app/serializers/ci/dag_pipeline_serializer.rb b/app/serializers/ci/dag_pipeline_serializer.rb new file mode 100644 index 00000000000..0c9e9a9db69 --- /dev/null +++ b/app/serializers/ci/dag_pipeline_serializer.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Ci + class DagPipelineSerializer < BaseSerializer + entity Ci::DagPipelineEntity + end +end diff --git a/app/serializers/ci/dag_stage_entity.rb b/app/serializers/ci/dag_stage_entity.rb new file mode 100644 index 00000000000..c7969da6c3c --- /dev/null +++ b/app/serializers/ci/dag_stage_entity.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module Ci + class DagStageEntity < Grape::Entity + expose :name + + expose :groups, with: Ci::DagJobGroupEntity + end +end diff --git a/app/serializers/ci/instance_variable_serializer.rb b/app/serializers/ci/instance_variable_serializer.rb new file mode 100644 index 00000000000..b0b49aecdbd --- /dev/null +++ b/app/serializers/ci/instance_variable_serializer.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Ci + class InstanceVariableSerializer < BaseSerializer + entity BasicVariableEntity + end +end diff --git a/app/serializers/cluster_application_entity.rb b/app/serializers/cluster_application_entity.rb index 85a40f1f5cb..32b759b9628 100644 --- a/app/serializers/cluster_application_entity.rb +++ b/app/serializers/cluster_application_entity.rb @@ -19,4 +19,6 @@ class ClusterApplicationEntity < Grape::Entity expose :host, if: -> (e, _) { e.respond_to?(:host) } expose :port, if: -> (e, _) { e.respond_to?(:port) } expose :protocol, if: -> (e, _) { e.respond_to?(:protocol) } + expose :waf_log_enabled, if: -> (e, _) { e.respond_to?(:waf_log_enabled) } + expose :cilium_log_enabled, if: -> (e, _) { e.respond_to?(:cilium_log_enabled) } end diff --git a/app/serializers/cluster_entity.rb b/app/serializers/cluster_entity.rb index c59f68bbc49..4f53ea30544 100644 --- a/app/serializers/cluster_entity.rb +++ b/app/serializers/cluster_entity.rb @@ -3,7 +3,16 @@ class ClusterEntity < Grape::Entity include RequestAwareEntity + expose :cluster_type + expose :enabled + expose :environment_scope + expose :name + expose :nodes expose :status_name, as: :status expose :status_reason expose :applications, using: ClusterApplicationEntity + + expose :path do |cluster| + Clusters::ClusterPresenter.new(cluster).show_path # rubocop: disable CodeReuse/Presenter + end end diff --git a/app/serializers/cluster_serializer.rb b/app/serializers/cluster_serializer.rb index 4bb4d4880d4..f59b6a35a29 100644 --- a/app/serializers/cluster_serializer.rb +++ b/app/serializers/cluster_serializer.rb @@ -1,8 +1,23 @@ # frozen_string_literal: true class ClusterSerializer < BaseSerializer + include WithPagination entity ClusterEntity + def represent_list(resource) + represent(resource, { + only: [ + :cluster_type, + :enabled, + :environment_scope, + :name, + :nodes, + :path, + :status + ] + }) + end + def represent_status(resource) represent(resource, { only: [:status, :status_reason, :applications] }) end diff --git a/app/serializers/diff_file_base_entity.rb b/app/serializers/diff_file_base_entity.rb index 302fe3d7c67..8c2b3a65d57 100644 --- a/app/serializers/diff_file_base_entity.rb +++ b/app/serializers/diff_file_base_entity.rb @@ -22,16 +22,16 @@ class DiffFileBaseEntity < Grape::Entity expose :edit_path, if: -> (_, options) { options[:merge_request] } do |diff_file| merge_request = options[:merge_request] - options = merge_request.persisted? ? { from_merge_request_iid: merge_request.iid } : {} + next unless merge_request.merged? || merge_request.source_branch_exists? - next unless merge_request.source_project + target_project, target_branch = edit_project_branch_options(merge_request) if Feature.enabled?(:web_ide_default) - ide_edit_path(merge_request.source_project, merge_request.source_branch, diff_file.new_path) + ide_edit_path(target_project, target_branch, diff_file.new_path) else - project_edit_blob_path(merge_request.source_project, - tree_join(merge_request.source_branch, diff_file.new_path), - options) + options = merge_request.persisted? && merge_request.source_branch_exists? && !merge_request.merged? ? { from_merge_request_iid: merge_request.iid } : {} + + project_edit_blob_path(target_project, tree_join(target_branch, diff_file.new_path), options) end end @@ -61,7 +61,7 @@ class DiffFileBaseEntity < Grape::Entity next unless diff_file.blob if merge_request&.source_project && current_user - can_modify_blob?(diff_file.blob, merge_request.source_project, merge_request.source_branch) + can_modify_blob?(diff_file.blob, merge_request.source_project, merge_request.source_branch_exists? ? merge_request.source_branch : merge_request.target_branch) else false end @@ -88,6 +88,7 @@ class DiffFileBaseEntity < Grape::Entity expose :b_mode expose :viewer, using: DiffViewerEntity + expose :alternate_viewer, using: DiffViewerEntity expose :old_size do |diff_file| diff_file.old_blob&.raw_size @@ -112,4 +113,12 @@ class DiffFileBaseEntity < Grape::Entity def current_user request.current_user end + + def edit_project_branch_options(merge_request) + if merge_request.source_branch_exists? && !merge_request.merged? + [merge_request.source_project, merge_request.source_branch] + else + [merge_request.target_project, merge_request.target_branch] + end + end end diff --git a/app/serializers/diffs_entity.rb b/app/serializers/diffs_entity.rb index 568d0f6aa8f..fb4fbe57130 100644 --- a/app/serializers/diffs_entity.rb +++ b/app/serializers/diffs_entity.rb @@ -11,6 +11,10 @@ class DiffsEntity < Grape::Entity merge_request&.source_branch end + expose :source_branch_exists do |diffs| + merge_request&.source_branch_exists? + end + expose :target_branch_name do |diffs| merge_request&.target_branch end diff --git a/app/serializers/group_variable_entity.rb b/app/serializers/group_variable_entity.rb index 622106458c3..4f44723fefe 100644 --- a/app/serializers/group_variable_entity.rb +++ b/app/serializers/group_variable_entity.rb @@ -1,11 +1,4 @@ # frozen_string_literal: true -class GroupVariableEntity < Grape::Entity - expose :id - expose :key - expose :value - expose :variable_type - - expose :protected?, as: :protected - expose :masked?, as: :masked +class GroupVariableEntity < Ci::BasicVariableEntity end diff --git a/app/serializers/issuable_sidebar_basic_entity.rb b/app/serializers/issuable_sidebar_basic_entity.rb index 498cfe5930d..bbec107544e 100644 --- a/app/serializers/issuable_sidebar_basic_entity.rb +++ b/app/serializers/issuable_sidebar_basic_entity.rb @@ -21,7 +21,7 @@ class IssuableSidebarBasicEntity < Grape::Entity expose :labels, using: LabelEntity expose :current_user, if: lambda { |_issuable| current_user } do - expose :current_user, merge: true, using: API::Entities::UserBasic + expose :current_user, merge: true, using: ::API::Entities::UserBasic expose :todo, using: IssuableSidebarTodoEntity do |issuable| current_user.pending_todo_for(issuable) diff --git a/app/serializers/issuable_sidebar_extras_entity.rb b/app/serializers/issuable_sidebar_extras_entity.rb index 0e1fcc58d7a..77f2e34fa5d 100644 --- a/app/serializers/issuable_sidebar_extras_entity.rb +++ b/app/serializers/issuable_sidebar_extras_entity.rb @@ -21,5 +21,5 @@ class IssuableSidebarExtrasEntity < Grape::Entity issuable.subscribed?(request.current_user, issuable.project) end - expose :assignees, using: API::Entities::UserBasic + expose :assignees, using: ::API::Entities::UserBasic end diff --git a/app/serializers/merge_request_assignee_entity.rb b/app/serializers/merge_request_assignee_entity.rb index 6849c62e759..b7ef7449270 100644 --- a/app/serializers/merge_request_assignee_entity.rb +++ b/app/serializers/merge_request_assignee_entity.rb @@ -5,3 +5,5 @@ class MergeRequestAssigneeEntity < ::API::Entities::UserBasic options[:merge_request]&.can_be_merged_by?(assignee) end end + +MergeRequestAssigneeEntity.prepend_if_ee('EE::MergeRequestAssigneeEntity') diff --git a/app/serializers/merge_request_poll_widget_entity.rb b/app/serializers/merge_request_poll_widget_entity.rb index 18e8ec0e7d1..aad607f358a 100644 --- a/app/serializers/merge_request_poll_widget_entity.rb +++ b/app/serializers/merge_request_poll_widget_entity.rb @@ -71,6 +71,18 @@ class MergeRequestPollWidgetEntity < Grape::Entity end end + expose :accessibility_report_path do |merge_request| + if merge_request.has_accessibility_reports? + accessibility_reports_project_merge_request_path(merge_request.project, merge_request, format: :json) + end + end + + expose :terraform_reports_path do |merge_request| + if merge_request.has_terraform_reports? + terraform_reports_project_merge_request_path(merge_request.project, merge_request, format: :json) + end + end + expose :exposed_artifacts_path do |merge_request| if merge_request.has_exposed_artifacts? exposed_artifacts_project_merge_request_path(merge_request.project, merge_request, format: :json) diff --git a/app/serializers/merge_request_serializer.rb b/app/serializers/merge_request_serializer.rb index 9fd50c8c51d..508a2510dbd 100644 --- a/app/serializers/merge_request_serializer.rb +++ b/app/serializers/merge_request_serializer.rb @@ -27,3 +27,5 @@ class MergeRequestSerializer < BaseSerializer super(merge_request, opts, entity) end end + +MergeRequestSerializer.prepend_if_ee('EE::MergeRequestSerializer') diff --git a/app/serializers/note_user_entity.rb b/app/serializers/note_user_entity.rb index 8d30bbff5e4..38e71528f18 100644 --- a/app/serializers/note_user_entity.rb +++ b/app/serializers/note_user_entity.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class NoteUserEntity < UserEntity - expose :gitlab_employee?, as: :is_gitlab_employee, if: ->(user, options) { user.gitlab_employee? } - unexpose :web_url end + +NoteUserEntity.prepend_if_ee('EE::NoteUserEntity') diff --git a/app/serializers/service_event_entity.rb b/app/serializers/service_event_entity.rb new file mode 100644 index 00000000000..fd655dd1ed3 --- /dev/null +++ b/app/serializers/service_event_entity.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class ServiceEventEntity < Grape::Entity + include RequestAwareEntity + + expose :title do |event| + event + end + + expose :event_field_name, as: :name + + expose :value do |event| + service[event_field_name] + end + + expose :description do |event| + service.class.event_description(event) + end + + expose :field, if: -> (_, _) { event_field } do + expose :name do |event| + event_field[:name] + end + expose :value do |event| + service.public_send(event_field[:name]) # rubocop:disable GitlabSecurity/PublicSend + end + end + + private + + alias_method :event, :object + + def event_field_name + ServicesHelper.service_event_field_name(event) + end + + def event_field + @event_field ||= service.event_field(event) + end + + def service + request.service + end +end diff --git a/app/serializers/service_event_serializer.rb b/app/serializers/service_event_serializer.rb new file mode 100644 index 00000000000..7f5fe36e571 --- /dev/null +++ b/app/serializers/service_event_serializer.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class ServiceEventSerializer < BaseSerializer + entity ServiceEventEntity +end diff --git a/app/serializers/test_suite_comparer_entity.rb b/app/serializers/test_suite_comparer_entity.rb index 78c243f75b8..a9f19564b60 100644 --- a/app/serializers/test_suite_comparer_entity.rb +++ b/app/serializers/test_suite_comparer_entity.rb @@ -46,8 +46,6 @@ class TestSuiteComparerEntity < Grape::Entity private def max_tests(*used) - return Integer::MAX unless Feature.enabled?(:ci_limit_test_reports_size, default_enabled: true) - [DEFAULT_MAX_TESTS - used.map(&:count).sum, DEFAULT_MIN_TESTS].max end # rubocop: enable CodeReuse/ActiveRecord diff --git a/app/serializers/test_suite_entity.rb b/app/serializers/test_suite_entity.rb index 0f88a496c77..53fa830718a 100644 --- a/app/serializers/test_suite_entity.rb +++ b/app/serializers/test_suite_entity.rb @@ -9,8 +9,9 @@ class TestSuiteEntity < Grape::Entity expose :failed_count expose :skipped_count expose :error_count + expose :suite_error expose :test_cases, using: TestCaseEntity do |test_suite| - test_suite.test_cases.values.flat_map(&:values) + test_suite.suite_error ? [] : test_suite.test_cases.values.flat_map(&:values) end end diff --git a/app/serializers/variable_entity.rb b/app/serializers/variable_entity.rb index 017035fa117..9b0db371acb 100644 --- a/app/serializers/variable_entity.rb +++ b/app/serializers/variable_entity.rb @@ -1,12 +1,5 @@ # frozen_string_literal: true -class VariableEntity < Grape::Entity - expose :id - expose :key - expose :value - expose :variable_type - - expose :protected?, as: :protected - expose :masked?, as: :masked +class VariableEntity < Ci::BasicVariableEntity expose :environment_scope end |