diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /app/serializers | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) | |
download | gitlab-ce-85dc423f7090da0a52c73eb66faf22ddb20efff9.tar.gz |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'app/serializers')
30 files changed, 210 insertions, 35 deletions
diff --git a/app/serializers/base_serializer.rb b/app/serializers/base_serializer.rb index 4744a7c1cc8..90bd4730f1e 100644 --- a/app/serializers/base_serializer.rb +++ b/app/serializers/base_serializer.rb @@ -9,7 +9,7 @@ class BaseSerializer end def represent(resource, opts = {}, entity_class = nil) - entity_class = entity_class || self.class.entity_class + entity_class ||= self.class.entity_class entity_class .represent(resource, opts.merge(request: @request)) diff --git a/app/serializers/build_coverage_entity.rb b/app/serializers/build_coverage_entity.rb new file mode 100644 index 00000000000..47e0c30ba1e --- /dev/null +++ b/app/serializers/build_coverage_entity.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class BuildCoverageEntity < Grape::Entity + expose :name, :coverage +end diff --git a/app/serializers/build_details_entity.rb b/app/serializers/build_details_entity.rb index 523f1a0f8c6..2b8522539b4 100644 --- a/app/serializers/build_details_entity.rb +++ b/app/serializers/build_details_entity.rb @@ -27,15 +27,15 @@ class BuildDetailsEntity < JobEntity end expose :artifact, if: -> (*) { can?(current_user, :read_build, build) } do - expose :download_path, if: -> (*) { build.pipeline.artifacts_locked? || build.artifacts? } do |build| + expose :download_path, if: -> (*) { build.locked_artifacts? || build.artifacts? } do |build| download_project_job_artifacts_path(project, build) end - expose :browse_path, if: -> (*) { build.pipeline.artifacts_locked? || build.browsable_artifacts? } do |build| + expose :browse_path, if: -> (*) { build.locked_artifacts? || build.browsable_artifacts? } do |build| browse_project_job_artifacts_path(project, build) end - expose :keep_path, if: -> (*) { build.has_expiring_archive_artifacts? && can?(current_user, :update_build, build) } do |build| + expose :keep_path, if: -> (*) { (build.locked_artifacts? || build.has_expiring_archive_artifacts?) && can?(current_user, :update_build, build) } do |build| keep_project_job_artifacts_path(project, build) end diff --git a/app/serializers/ci/lint/job_entity.rb b/app/serializers/ci/lint/job_entity.rb new file mode 100644 index 00000000000..2393f9ba44c --- /dev/null +++ b/app/serializers/ci/lint/job_entity.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class Ci::Lint::JobEntity < Grape::Entity + expose :name + expose :stage + expose :before_script + expose :script + expose :after_script + expose :tag_list + expose :environment + expose :when + expose :allow_failure + expose :only + expose :except +end diff --git a/app/serializers/ci/lint/result_entity.rb b/app/serializers/ci/lint/result_entity.rb new file mode 100644 index 00000000000..f9306d1dc70 --- /dev/null +++ b/app/serializers/ci/lint/result_entity.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class Ci::Lint::ResultEntity < Grape::Entity + expose :valid?, as: :valid + expose :errors + expose :warnings + expose :jobs, using: Ci::Lint::JobEntity do |result, options| + next [] unless result.valid? + + result.jobs + end +end diff --git a/app/serializers/ci/lint/result_serializer.rb b/app/serializers/ci/lint/result_serializer.rb new file mode 100644 index 00000000000..4b55b415129 --- /dev/null +++ b/app/serializers/ci/lint/result_serializer.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class Ci::Lint::ResultSerializer < BaseSerializer + entity ::Ci::Lint::ResultEntity +end diff --git a/app/serializers/cluster_entity.rb b/app/serializers/cluster_entity.rb index 06e14179238..eea0acdc11b 100644 --- a/app/serializers/cluster_entity.rb +++ b/app/serializers/cluster_entity.rb @@ -24,4 +24,8 @@ class ClusterEntity < Grape::Entity expose :kubernetes_errors do |cluster| ClusterErrorEntity.new(cluster) end + + expose :enable_advanced_logs_querying do |cluster| + cluster.application_elastic_stack_available? + end end diff --git a/app/serializers/cluster_serializer.rb b/app/serializers/cluster_serializer.rb index a70458d2bcb..700a46040e3 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, + :enable_advanced_logs_querying, :kubernetes_errors, :name, :nodes, diff --git a/app/serializers/diff_file_base_entity.rb b/app/serializers/diff_file_base_entity.rb index 2af14f1eb82..9f27191c3c8 100644 --- a/app/serializers/diff_file_base_entity.rb +++ b/app/serializers/diff_file_base_entity.rb @@ -12,11 +12,23 @@ class DiffFileBaseEntity < Grape::Entity expose :submodule?, as: :submodule expose :submodule_link do |diff_file, options| - memoized_submodule_links(diff_file, options).first + memoized_submodule_links(diff_file, options)&.web end expose :submodule_tree_url do |diff_file| - memoized_submodule_links(diff_file, options).last + memoized_submodule_links(diff_file, options)&.tree + end + + expose :submodule_compare do |diff_file| + url = memoized_submodule_links(diff_file, options)&.compare + + next unless url + + { + url: url, + old_sha: diff_file.old_blob&.id, + new_sha: diff_file.blob&.id + } end expose :edit_path, if: -> (_, options) { options[:merge_request] } do |diff_file| @@ -96,11 +108,9 @@ class DiffFileBaseEntity < Grape::Entity def memoized_submodule_links(diff_file, options) strong_memoize(:submodule_links) do - if diff_file.submodule? - options[:submodule_links].for(diff_file.blob, diff_file.content_sha) - else - [] - end + next unless diff_file.submodule? + + options[:submodule_links].for(diff_file.blob, diff_file.content_sha, diff_file) end end diff --git a/app/serializers/diff_file_entity.rb b/app/serializers/diff_file_entity.rb index 26a42d2e9eb..e3fefbb46b6 100644 --- a/app/serializers/diff_file_entity.rb +++ b/app/serializers/diff_file_entity.rb @@ -71,15 +71,11 @@ class DiffFileEntity < DiffFileBaseEntity private def parallel_diff_view?(options, diff_file) - return true unless Feature.enabled?(:single_mr_diff_view, diff_file.repository.project, default_enabled: true) - # If we're not rendering inline, we must be rendering parallel !inline_diff_view?(options, diff_file) end def inline_diff_view?(options, diff_file) - return true unless Feature.enabled?(:single_mr_diff_view, diff_file.repository.project, default_enabled: true) - # If nothing is present, inline will be the default. options.fetch(:diff_view, :inline).to_sym == :inline end diff --git a/app/serializers/environment_entity.rb b/app/serializers/environment_entity.rb index a2bf9716f8f..7da5910a75b 100644 --- a/app/serializers/environment_entity.rb +++ b/app/serializers/environment_entity.rb @@ -71,8 +71,6 @@ 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 @@ -93,10 +91,6 @@ 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/fork_namespace_entity.rb b/app/serializers/fork_namespace_entity.rb index 068862e0951..abfaf4be811 100644 --- a/app/serializers/fork_namespace_entity.rb +++ b/app/serializers/fork_namespace_entity.rb @@ -19,7 +19,7 @@ class ForkNamespaceEntity < Grape::Entity end expose :permission do |namespace, options| - membership(options[:current_user], namespace)&.human_access + membership(options[:current_user], namespace, options[:memberships])&.human_access end expose :relative_path do |namespace| @@ -37,10 +37,10 @@ class ForkNamespaceEntity < Grape::Entity private # rubocop: disable CodeReuse/ActiveRecord - def membership(user, object) + def membership(user, object, memberships) return unless user - @membership ||= user.members.find_by(source: object) + memberships[object.id] end # rubocop: enable CodeReuse/ActiveRecord diff --git a/app/serializers/group_group_link_entity.rb b/app/serializers/group_group_link_entity.rb new file mode 100644 index 00000000000..7a51e1a9316 --- /dev/null +++ b/app/serializers/group_group_link_entity.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class GroupGroupLinkEntity < Grape::Entity + expose :id + expose :created_at + expose :expires_at do |group_link| + group_link.expires_at&.to_time + end + + expose :access_level do + expose :human_access, as: :string_value + expose :group_access, as: :integer_value + end + + expose :shared_with_group do + expose :avatar_url do |group_link| + group_link.shared_with_group.avatar_url(only_path: false) + end + + expose :web_url do |group_link| + group_link.shared_with_group.web_url + end + + expose :shared_with_group, merge: true, using: GroupBasicEntity + end +end diff --git a/app/serializers/group_group_link_serializer.rb b/app/serializers/group_group_link_serializer.rb new file mode 100644 index 00000000000..6ae8daf9207 --- /dev/null +++ b/app/serializers/group_group_link_serializer.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class GroupGroupLinkSerializer < BaseSerializer + entity GroupGroupLinkEntity +end diff --git a/app/serializers/issuable_sidebar_basic_entity.rb b/app/serializers/issuable_sidebar_basic_entity.rb index bbec107544e..53c123c06fd 100644 --- a/app/serializers/issuable_sidebar_basic_entity.rb +++ b/app/serializers/issuable_sidebar_basic_entity.rb @@ -103,6 +103,10 @@ class IssuableSidebarBasicEntity < Grape::Entity issuable.project.emails_disabled? end + expose :supports_time_tracking?, as: :supports_time_tracking + expose :supports_milestone?, as: :supports_milestone + expose :supports_severity?, as: :supports_severity + private def current_user diff --git a/app/serializers/issue_sidebar_basic_entity.rb b/app/serializers/issue_sidebar_basic_entity.rb index 165dc462cfe..e9e05718af9 100644 --- a/app/serializers/issue_sidebar_basic_entity.rb +++ b/app/serializers/issue_sidebar_basic_entity.rb @@ -3,6 +3,7 @@ class IssueSidebarBasicEntity < IssuableSidebarBasicEntity expose :due_date expose :confidential + expose :severity end IssueSidebarBasicEntity.prepend_if_ee('EE::IssueSidebarBasicEntity') diff --git a/app/serializers/job_entity.rb b/app/serializers/job_entity.rb index d0099ae77f2..d05b500b140 100644 --- a/app/serializers/job_entity.rb +++ b/app/serializers/job_entity.rb @@ -9,7 +9,8 @@ class JobEntity < Grape::Entity expose :started?, as: :started expose :archived?, as: :archived - expose :build_path do |build| + # bridge jobs don't have build detail pages + expose :build_path, if: ->(build) { !build.is_a?(Ci::Bridge) } do |build| build_path(build) end diff --git a/app/serializers/linked_issue_entity.rb b/app/serializers/linked_issue_entity.rb new file mode 100644 index 00000000000..6ae3f4044db --- /dev/null +++ b/app/serializers/linked_issue_entity.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class LinkedIssueEntity < Grape::Entity + include RequestAwareEntity + + expose :id, :confidential, :title + + expose :assignees, using: UserEntity + + expose :state + + expose :milestone, using: API::Entities::Milestone + + expose :weight + + expose :reference do |link| + link.to_reference(issuable.project) + end + + expose :path do |link| + project_issue_path(link.project, link.iid) + end + + expose :relation_path + + expose :due_date, :created_at, :closed_at + + private + + def current_user + request.current_user + end + + def issuable + request.issuable + end +end diff --git a/app/serializers/linked_project_issue_entity.rb b/app/serializers/linked_project_issue_entity.rb new file mode 100644 index 00000000000..c95f68f58a3 --- /dev/null +++ b/app/serializers/linked_project_issue_entity.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class LinkedProjectIssueEntity < LinkedIssueEntity + include Gitlab::Utils::StrongMemoize + + expose :relation_path, override: true do |issue| + # Make sure the user can admin both the current issue AND the + # referenced issue projects in order to return the removal link. + if can_admin_issue_link_on_current_project? && can_admin_issue_link?(issue.project) + project_issue_link_path(issuable.project, issuable.iid, issue.issue_link_id) + end + end + + expose :link_type do |issue| + issue.issue_link_type + end + + private + + def can_admin_issue_link_on_current_project? + strong_memoize(:can_admin_on_current_project) do + can_admin_issue_link?(issuable.project) + end + end + + def can_admin_issue_link?(project) + Ability.allowed?(current_user, :admin_issue_link, project) + end +end diff --git a/app/serializers/linked_project_issue_serializer.rb b/app/serializers/linked_project_issue_serializer.rb new file mode 100644 index 00000000000..3015e593e34 --- /dev/null +++ b/app/serializers/linked_project_issue_serializer.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class LinkedProjectIssueSerializer < BaseSerializer + entity LinkedProjectIssueEntity +end diff --git a/app/serializers/merge_request_basic_entity.rb b/app/serializers/merge_request_basic_entity.rb index 82baf4a4a78..ef1177e9967 100644 --- a/app/serializers/merge_request_basic_entity.rb +++ b/app/serializers/merge_request_basic_entity.rb @@ -9,6 +9,7 @@ class MergeRequestBasicEntity < Grape::Entity expose :milestone, using: API::Entities::Milestone expose :labels, using: LabelEntity expose :assignees, using: API::Entities::UserBasic + expose :reviewers, if: -> (m) { m.allows_reviewers? }, using: API::Entities::UserBasic expose :task_status, :task_status_short expose :lock_version, :lock_version end diff --git a/app/serializers/merge_request_poll_cached_widget_entity.rb b/app/serializers/merge_request_poll_cached_widget_entity.rb index c51c08ab646..002be8be729 100644 --- a/app/serializers/merge_request_poll_cached_widget_entity.rb +++ b/app/serializers/merge_request_poll_cached_widget_entity.rb @@ -3,8 +3,8 @@ class MergeRequestPollCachedWidgetEntity < IssuableEntity expose :auto_merge_enabled expose :state - expose :merge_commit_sha - expose :short_merge_commit_sha + expose :merged_commit_sha + expose :short_merged_commit_sha expose :merge_error expose :public_merge_status, as: :merge_status expose :merge_user_id @@ -56,9 +56,9 @@ class MergeRequestPollCachedWidgetEntity < IssuableEntity presenter(merge_request).target_branch_tree_path end - expose :merge_commit_path do |merge_request| - if merge_request.merge_commit_sha - project_commit_path(merge_request.project, merge_request.merge_commit_sha) + expose :merged_commit_path do |merge_request| + if sha = merge_request.merged_commit_sha + project_commit_path(merge_request.project, sha) end end diff --git a/app/serializers/merge_request_poll_widget_entity.rb b/app/serializers/merge_request_poll_widget_entity.rb index 99d6211b487..41ab5005091 100644 --- a/app/serializers/merge_request_poll_widget_entity.rb +++ b/app/serializers/merge_request_poll_widget_entity.rb @@ -73,6 +73,8 @@ class MergeRequestPollWidgetEntity < Grape::Entity presenter(merge_request).pipeline_coverage_delta end + expose :head_pipeline_builds_with_coverage, as: :builds_with_coverage, using: BuildCoverageEntity + expose :cancel_auto_merge_path do |merge_request| presenter(merge_request).cancel_auto_merge_path end diff --git a/app/serializers/merge_request_reviewer_entity.rb b/app/serializers/merge_request_reviewer_entity.rb new file mode 100644 index 00000000000..fefd116014f --- /dev/null +++ b/app/serializers/merge_request_reviewer_entity.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class MergeRequestReviewerEntity < ::API::Entities::UserBasic + expose :can_merge do |reviewer, options| + options[:merge_request]&.can_be_merged_by?(reviewer) + end +end + +MergeRequestReviewerEntity.prepend_if_ee('EE::MergeRequestReviewerEntity') diff --git a/app/serializers/merge_request_sidebar_extras_entity.rb b/app/serializers/merge_request_sidebar_extras_entity.rb index 7276509c363..9db8e52abef 100644 --- a/app/serializers/merge_request_sidebar_extras_entity.rb +++ b/app/serializers/merge_request_sidebar_extras_entity.rb @@ -4,4 +4,8 @@ class MergeRequestSidebarExtrasEntity < IssuableSidebarExtrasEntity expose :assignees do |merge_request| MergeRequestAssigneeEntity.represent(merge_request.assignees, merge_request: merge_request) end + + expose :reviewers, if: -> (m) { m.allows_reviewers? } do |merge_request| + MergeRequestReviewerEntity.represent(merge_request.reviewers, merge_request: merge_request) + end end diff --git a/app/serializers/merge_request_widget_entity.rb b/app/serializers/merge_request_widget_entity.rb index b7b9e7d1036..494192c8dbb 100644 --- a/app/serializers/merge_request_widget_entity.rb +++ b/app/serializers/merge_request_widget_entity.rb @@ -62,6 +62,7 @@ class MergeRequestWidgetEntity < Grape::Entity merge_request.source_branch, file_name: '.gitlab-ci.yml', commit_message: s_("CommitMessage|Add %{file_name}") % { file_name: Gitlab::FileDetector::PATTERNS[:gitlab_ci] }, + mr_path: merge_request_path(merge_request), suggest_gitlab_ci_yml: true ) end diff --git a/app/serializers/note_entity.rb b/app/serializers/note_entity.rb index c49dec2a93c..ef305195e22 100644 --- a/app/serializers/note_entity.rb +++ b/app/serializers/note_entity.rb @@ -46,6 +46,10 @@ class NoteEntity < API::Entities::Note SystemNoteHelper.system_note_icon_name(note) end + expose :is_noteable_author do |note| + note.noteable_author?(request.noteable) + end + expose :discussion_id do |note| note.discussion_id(request.noteable) end diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index de1e07139ad..64958b06f1d 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -85,10 +85,6 @@ class PipelineEntity < Grape::Entity pipeline.failed_builds end - expose :tests_total_count do |pipeline| - pipeline.test_report_summary.total[:count] - end - private alias_method :pipeline, :object diff --git a/app/serializers/project_note_entity.rb b/app/serializers/project_note_entity.rb index f6cdea1d8b5..3cd34f6af0d 100644 --- a/app/serializers/project_note_entity.rb +++ b/app/serializers/project_note_entity.rb @@ -5,6 +5,14 @@ class ProjectNoteEntity < NoteEntity note.project.team.human_max_access(note.author_id) end + expose :is_contributor, if: -> (note, _) { note.project.present? } do |note| + note.contributor? + end + + expose :project_name, if: -> (note, _) { note.project.present? } do |note| + note.project.name + end + expose :toggle_award_path, if: -> (note, _) { note.emoji_awardable? } do |note| toggle_award_emoji_project_note_path(note.project, note.id) end diff --git a/app/serializers/test_suite_entity.rb b/app/serializers/test_suite_entity.rb index d04fd5f6a84..15eb2891b22 100644 --- a/app/serializers/test_suite_entity.rb +++ b/app/serializers/test_suite_entity.rb @@ -13,7 +13,7 @@ class TestSuiteEntity < Grape::Entity with_options if: -> (_, opts) { opts[:details] } do |test_suite| expose :suite_error expose :test_cases, using: TestCaseEntity do |test_suite| - test_suite.suite_error ? [] : test_suite.test_cases.values.flat_map(&:values) + test_suite.suite_error ? [] : test_suite.sorted.test_cases.values.flat_map(&:values) end end end |