diff options
Diffstat (limited to 'app/serializers')
25 files changed, 153 insertions, 67 deletions
diff --git a/app/serializers/README.md b/app/serializers/README.md index 89721f572e0..97e9625eb6f 100644 --- a/app/serializers/README.md +++ b/app/serializers/README.md @@ -99,7 +99,7 @@ create a JSON response according to your needs. ```ruby class PipelineSerializer < BaseSerializer - entity PipelineEntity + entity Ci::PipelineEntity def represent_details(resource) represent(resource, only: [:details]) diff --git a/app/serializers/admin/user_entity.rb b/app/serializers/admin/user_entity.rb index ad96c101822..8908d610046 100644 --- a/app/serializers/admin/user_entity.rb +++ b/app/serializers/admin/user_entity.rb @@ -10,6 +10,7 @@ module Admin expose :email expose :last_activity_on expose :avatar_url + expose :note expose :badges do |user| user_badges_in_admin_section(user) end diff --git a/app/serializers/admin/user_serializer.rb b/app/serializers/admin/user_serializer.rb index 09036428bab..edd28e88553 100644 --- a/app/serializers/admin/user_serializer.rb +++ b/app/serializers/admin/user_serializer.rb @@ -2,6 +2,6 @@ module Admin class UserSerializer < BaseSerializer - entity UserEntity + entity Admin::UserEntity end end diff --git a/app/serializers/base_discussion_entity.rb b/app/serializers/base_discussion_entity.rb index 5ca4d1d6cc9..8d4c3906847 100644 --- a/app/serializers/base_discussion_entity.rb +++ b/app/serializers/base_discussion_entity.rb @@ -15,6 +15,7 @@ class BaseDiscussionEntity < Grape::Entity expose :for_commit?, as: :for_commit expose :individual_note?, as: :individual_note expose :resolvable?, as: :resolvable + expose :resolved_by_push?, as: :resolved_by_push expose :truncated_diff_lines, using: DiffLineEntity, if: -> (d, _) { d.diff_discussion? && d.on_text? && (d.expanded? || render_truncated_diff_lines?) } diff --git a/app/serializers/build_details_entity.rb b/app/serializers/build_details_entity.rb index 2432a6a0e4d..ea72b2b89e7 100644 --- a/app/serializers/build_details_entity.rb +++ b/app/serializers/build_details_entity.rb @@ -9,7 +9,7 @@ class BuildDetailsEntity < JobEntity expose :user, using: UserEntity expose :runner, using: RunnerEntity expose :metadata, using: BuildMetadataEntity - expose :pipeline, using: PipelineEntity + expose :pipeline, using: Ci::PipelineEntity expose :deployment_status, if: -> (*) { build.starts_environment? } do expose :deployment_status, as: :status diff --git a/app/serializers/ci/codequality_mr_diff_entity.rb b/app/serializers/ci/codequality_mr_diff_entity.rb new file mode 100644 index 00000000000..99e7cc54017 --- /dev/null +++ b/app/serializers/ci/codequality_mr_diff_entity.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Ci + class CodequalityMrDiffEntity < Grape::Entity + expose :files + end +end diff --git a/app/serializers/ci/codequality_mr_diff_report_serializer.rb b/app/serializers/ci/codequality_mr_diff_report_serializer.rb new file mode 100644 index 00000000000..e9b51930b99 --- /dev/null +++ b/app/serializers/ci/codequality_mr_diff_report_serializer.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Ci + class CodequalityMrDiffReportSerializer < BaseSerializer + entity CodequalityMrDiffEntity + end +end diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/ci/pipeline_entity.rb index 2d278f0e30d..86f93929a5d 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/ci/pipeline_entity.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class PipelineEntity < Grape::Entity +class Ci::PipelineEntity < Grape::Entity include RequestAwareEntity include Gitlab::Utils::StrongMemoize @@ -120,3 +120,5 @@ class PipelineEntity < Grape::Entity end end end + +Ci::PipelineEntity.prepend_if_ee('EE::Ci::PipelineEntity') diff --git a/app/serializers/concerns/user_status_tooltip.rb b/app/serializers/concerns/user_status_tooltip.rb index fcf6700cb59..ca2854224a7 100644 --- a/app/serializers/concerns/user_status_tooltip.rb +++ b/app/serializers/concerns/user_status_tooltip.rb @@ -16,6 +16,10 @@ module UserStatusTooltip status_loaded? && show_status_emoji?(user.status) end + expose :availability, if: -> (*) { status_loaded? } do |user| + user.status&.availability + end + private def status_loaded? diff --git a/app/serializers/diff_file_metadata_entity.rb b/app/serializers/diff_file_metadata_entity.rb index 460f4967e99..70a5b266be1 100644 --- a/app/serializers/diff_file_metadata_entity.rb +++ b/app/serializers/diff_file_metadata_entity.rb @@ -7,6 +7,7 @@ class DiffFileMetadataEntity < Grape::Entity expose :old_path expose :new_file?, as: :new_file expose :deleted_file?, as: :deleted_file + expose :submodule?, as: :submodule expose :file_identifier_hash expose :file_hash end diff --git a/app/serializers/diffs_entity.rb b/app/serializers/diffs_entity.rb index f573bbe8385..4bc6644a5cb 100644 --- a/app/serializers/diffs_entity.rb +++ b/app/serializers/diffs_entity.rb @@ -79,7 +79,9 @@ class DiffsEntity < Grape::Entity end expose :definition_path_prefix do |diffs| - project_blob_path(merge_request.project, diffs.diff_refs&.head_sha) + next unless merge_request.diff_head_sha + + project_blob_path(merge_request.project, merge_request.diff_head_sha) end def merge_request diff --git a/app/serializers/group_child_entity.rb b/app/serializers/group_child_entity.rb index a7fe4d3f9b9..adbda790dee 100644 --- a/app/serializers/group_child_entity.rb +++ b/app/serializers/group_child_entity.rb @@ -20,7 +20,7 @@ class GroupChildEntity < Grape::Entity # We know `type` will be one either `project` or `group`. # The `edit_polymorphic_path` helper would try to call the path helper # with a plural: `edit_groups_path(instance)` or `edit_projects_path(instance)` - # while our methods are `edit_group_path` or `edit_group_path` + # while our methods are `edit_group_path` or `edit_project_path` public_send("edit_#{type}_path", instance) # rubocop:disable GitlabSecurity/PublicSend end diff --git a/app/serializers/group_group_link_entity.rb b/app/serializers/group_group_link_entity.rb deleted file mode 100644 index 1e736214f54..00000000000 --- a/app/serializers/group_group_link_entity.rb +++ /dev/null @@ -1,50 +0,0 @@ -# frozen_string_literal: true - -class GroupGroupLinkEntity < Grape::Entity - include RequestAwareEntity - - expose :id - expose :created_at - expose :expires_at do |group_link| - group_link.expires_at&.to_time - end - - expose :can_update do |group_link| - can_manage?(group_link) - end - - expose :can_remove do |group_link| - can_manage?(group_link) - end - - expose :access_level do - expose :human_access, as: :string_value - expose :group_access, as: :integer_value - end - - expose :valid_roles do |group_link| - group_link.class.access_options - 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 - - private - - def current_user - options[:current_user] - end - - def can_manage?(group_link) - can?(current_user, :admin_group_member, group_link.shared_group) - end -end diff --git a/app/serializers/group_group_link_serializer.rb b/app/serializers/group_group_link_serializer.rb deleted file mode 100644 index 6ae8daf9207..00000000000 --- a/app/serializers/group_group_link_serializer.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -class GroupGroupLinkSerializer < BaseSerializer - entity GroupGroupLinkEntity -end diff --git a/app/serializers/group_link/group_group_link_entity.rb b/app/serializers/group_link/group_group_link_entity.rb new file mode 100644 index 00000000000..cedc8bd8582 --- /dev/null +++ b/app/serializers/group_link/group_group_link_entity.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module GroupLink + class GroupGroupLinkEntity < GroupLink::GroupLinkEntity + include RequestAwareEntity + + expose :can_update do |group_link| + can_manage?(group_link) + end + + expose :can_remove do |group_link| + can_manage?(group_link) + end + + private + + def current_user + options[:current_user] + end + + def can_manage?(group_link) + can?(current_user, :admin_group_member, group_link.shared_group) + end + end +end diff --git a/app/serializers/group_link/group_group_link_serializer.rb b/app/serializers/group_link/group_group_link_serializer.rb new file mode 100644 index 00000000000..1e3f861f09a --- /dev/null +++ b/app/serializers/group_link/group_group_link_serializer.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module GroupLink + class GroupGroupLinkSerializer < BaseSerializer + entity GroupLink::GroupGroupLinkEntity + end +end diff --git a/app/serializers/group_link/group_link_entity.rb b/app/serializers/group_link/group_link_entity.rb new file mode 100644 index 00000000000..12349320b6f --- /dev/null +++ b/app/serializers/group_link/group_link_entity.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +module GroupLink + class GroupLinkEntity < Grape::Entity + include RequestAwareEntity + + 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 :valid_roles do |group_link| + group_link.class.access_options + end + + expose :shared_with_group do + expose :avatar_url do |group_link| + group_link.shared_with_group.avatar_url(only_path: false, size: Member::AVATAR_SIZE) + 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 +end diff --git a/app/serializers/group_link/project_group_link_entity.rb b/app/serializers/group_link/project_group_link_entity.rb new file mode 100644 index 00000000000..2ff275fff01 --- /dev/null +++ b/app/serializers/group_link/project_group_link_entity.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module GroupLink + class ProjectGroupLinkEntity < GroupLink::GroupLinkEntity + include RequestAwareEntity + include Projects::ProjectMembersHelper + + expose :can_update do |group_link| + can_manage_project_members?(group_link.project) + end + + expose :can_remove do |group_link| + can_manage_project_members?(group_link.project) + end + + private + + def current_user + options[:current_user] + end + end +end diff --git a/app/serializers/group_link/project_group_link_serializer.rb b/app/serializers/group_link/project_group_link_serializer.rb new file mode 100644 index 00000000000..b2559e61e31 --- /dev/null +++ b/app/serializers/group_link/project_group_link_serializer.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module GroupLink + class ProjectGroupLinkSerializer < BaseSerializer + entity GroupLink::ProjectGroupLinkEntity + end +end diff --git a/app/serializers/member_entity.rb b/app/serializers/member_entity.rb index 584ba4c62de..e8f2bb28d60 100644 --- a/app/serializers/member_entity.rb +++ b/app/serializers/member_entity.rb @@ -23,6 +23,10 @@ class MemberEntity < Grape::Entity member.can_remove? end + expose :is_direct_member do |member, options| + member.source == options[:source] + end + expose :access_level do expose :human_access, as: :string_value expose :access_level, as: :integer_value diff --git a/app/serializers/merge_request_basic_entity.rb b/app/serializers/merge_request_basic_entity.rb index 9e2bce53c8a..7d45484fc2f 100644 --- a/app/serializers/merge_request_basic_entity.rb +++ b/app/serializers/merge_request_basic_entity.rb @@ -10,7 +10,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 :reviewers, using: API::Entities::UserBasic expose :task_status, :task_status_short expose :lock_version, :lock_version end diff --git a/app/serializers/merge_request_sidebar_extras_entity.rb b/app/serializers/merge_request_sidebar_extras_entity.rb index 261b6e8e519..1a0111fe5d0 100644 --- a/app/serializers/merge_request_sidebar_extras_entity.rb +++ b/app/serializers/merge_request_sidebar_extras_entity.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true class MergeRequestSidebarExtrasEntity < IssuableSidebarExtrasEntity - expose :assignees do |merge_request| - MergeRequestUserEntity.represent(merge_request.assignees, merge_request: merge_request) + expose :assignees do |merge_request, options| + MergeRequestUserEntity.represent(merge_request.assignees, options.merge(merge_request: merge_request)) end - expose :reviewers, if: -> (m) { m.allows_reviewers? } do |merge_request| - MergeRequestUserEntity.represent(merge_request.reviewers, merge_request: merge_request) + expose :reviewers do |merge_request, options| + MergeRequestUserEntity.represent(merge_request.reviewers, options.merge(merge_request: merge_request)) end end diff --git a/app/serializers/merge_request_user_entity.rb b/app/serializers/merge_request_user_entity.rb index 604c9cabd50..edb7e10bac5 100644 --- a/app/serializers/merge_request_user_entity.rb +++ b/app/serializers/merge_request_user_entity.rb @@ -1,9 +1,22 @@ # frozen_string_literal: true class MergeRequestUserEntity < ::API::Entities::UserBasic + include UserStatusTooltip + include RequestAwareEntity + expose :can_merge do |reviewer, options| options[:merge_request]&.can_be_merged_by?(reviewer) end + + expose :can_update_merge_request do |reviewer, options| + request.current_user&.can?(:update_merge_request, options[:merge_request]) + end + + expose :reviewed, if: -> (_, options) { options[:merge_request] && options[:merge_request].allows_reviewers? } do |reviewer, options| + reviewer = options[:merge_request].find_reviewer(reviewer) + + reviewer&.reviewed? + end end MergeRequestUserEntity.prepend_if_ee('EE::MergeRequestUserEntity') diff --git a/app/serializers/merge_request_widget_entity.rb b/app/serializers/merge_request_widget_entity.rb index ca4e16bc5ff..560dd2ea08b 100644 --- a/app/serializers/merge_request_widget_entity.rb +++ b/app/serializers/merge_request_widget_entity.rb @@ -133,6 +133,10 @@ class MergeRequestWidgetEntity < Grape::Entity help_page_path('user/application_security/index.md', anchor: 'viewing-security-scan-information-in-merge-requests') end + expose :enabled_reports do |merge_request| + merge_request.enabled_reports + end + private delegate :current_user, to: :request diff --git a/app/serializers/pipeline_details_entity.rb b/app/serializers/pipeline_details_entity.rb index e53fa7873ac..4fec543eca8 100644 --- a/app/serializers/pipeline_details_entity.rb +++ b/app/serializers/pipeline_details_entity.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class PipelineDetailsEntity < PipelineEntity +class PipelineDetailsEntity < Ci::PipelineEntity expose :project, using: ProjectEntity expose :flags do |