diff options
Diffstat (limited to 'app/serializers')
-rw-r--r-- | app/serializers/concerns/user_status_tooltip.rb | 2 | ||||
-rw-r--r-- | app/serializers/environment_serializer.rb | 21 | ||||
-rw-r--r-- | app/serializers/group_access_token_entity.rb | 26 | ||||
-rw-r--r-- | app/serializers/group_access_token_serializer.rb | 7 | ||||
-rw-r--r-- | app/serializers/integrations/project_entity.rb | 1 | ||||
-rw-r--r-- | app/serializers/issue_entity.rb | 4 | ||||
-rw-r--r-- | app/serializers/merge_request_poll_widget_entity.rb | 13 | ||||
-rw-r--r-- | app/serializers/merge_request_user_entity.rb | 4 | ||||
-rw-r--r-- | app/serializers/personal_access_token_entity.rb | 11 | ||||
-rw-r--r-- | app/serializers/personal_access_token_serializer.rb | 7 | ||||
-rw-r--r-- | app/serializers/project_access_token_entity.rb | 27 | ||||
-rw-r--r-- | app/serializers/project_access_token_serializer.rb | 7 | ||||
-rw-r--r-- | app/serializers/rollout_status_entity.rb | 2 |
13 files changed, 100 insertions, 32 deletions
diff --git a/app/serializers/concerns/user_status_tooltip.rb b/app/serializers/concerns/user_status_tooltip.rb index ca2854224a7..38b3c16dd2a 100644 --- a/app/serializers/concerns/user_status_tooltip.rb +++ b/app/serializers/concerns/user_status_tooltip.rb @@ -13,7 +13,7 @@ module UserStatusTooltip end expose :show_status do |user| - status_loaded? && show_status_emoji?(user.status) + status_loaded? && !!user.status&.customized? end expose :availability, if: -> (*) { status_loaded? } do |user| diff --git a/app/serializers/environment_serializer.rb b/app/serializers/environment_serializer.rb index 3f236fa55df..6363d6276a7 100644 --- a/app/serializers/environment_serializer.rb +++ b/app/serializers/environment_serializer.rb @@ -34,8 +34,8 @@ class EnvironmentSerializer < BaseSerializer # rubocop: disable CodeReuse/ActiveRecord def itemize(resource) items = resource.order('folder ASC') - .group('COALESCE(environment_type, name)') - .select('COALESCE(environment_type, name) AS folder', + .group('COALESCE(environment_type, id::text)', 'COALESCE(environment_type, name)') + .select('COALESCE(environment_type, id::text), COALESCE(environment_type, name) AS folder', 'COUNT(*) AS size', 'MAX(id) AS last_id') # It makes a difference when you call `paginate` method, because @@ -54,11 +54,7 @@ class EnvironmentSerializer < BaseSerializer def batch_load(resource) temp_deployment_associations = deployment_associations - resource = resource.preload(environment_associations.except(:last_deployment, :upcoming_deployment)) - - if ::Feature.enabled?(:batch_load_environment_last_deployment_group, resource.first&.project) - temp_deployment_associations[:deployable][:pipeline][:latest_successful_builds] = [] - end + resource = resource.preload(environment_associations) Preloaders::Environments::DeploymentPreloader.new(resource) .execute_with_union(:last_deployment, temp_deployment_associations) @@ -72,18 +68,14 @@ class EnvironmentSerializer < BaseSerializer environment.last_deployment&.commit&.try(:lazy_author) environment.upcoming_deployment&.commit&.try(:lazy_author) - if ::Feature.enabled?(:batch_load_environment_last_deployment_group, environment.project) - # Batch loading last_deployment_group which is called later by environment.stop_actions - environment.last_deployment_group - end + # Batch loading last_deployment_group which is called later by environment.stop_actions + environment.last_deployment_group end end end def environment_associations { - last_deployment: deployment_associations, - upcoming_deployment: deployment_associations, project: project_associations } end @@ -101,7 +93,8 @@ class EnvironmentSerializer < BaseSerializer metadata: [], pipeline: { manual_actions: [:metadata, :deployment], - scheduled_actions: [:metadata] + scheduled_actions: [:metadata], + latest_successful_builds: [] }, project: project_associations, deployment: [] diff --git a/app/serializers/group_access_token_entity.rb b/app/serializers/group_access_token_entity.rb new file mode 100644 index 00000000000..e832eef1188 --- /dev/null +++ b/app/serializers/group_access_token_entity.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +# rubocop: disable Gitlab/NamespacedClass +class GroupAccessTokenEntity < API::Entities::PersonalAccessToken + include Gitlab::Routing + + expose :revoke_path do |token, options| + group = options.fetch(:group) + + next unless group + + revoke_group_settings_access_token_path( + id: token, + group_id: group.path) + end + + expose :access_level do |token, options| + group = options.fetch(:group) + + next unless group + next unless token.user + + group.member(token.user)&.access_level + end +end +# rubocop: enable Gitlab/NamespacedClass diff --git a/app/serializers/group_access_token_serializer.rb b/app/serializers/group_access_token_serializer.rb new file mode 100644 index 00000000000..55f6de77844 --- /dev/null +++ b/app/serializers/group_access_token_serializer.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +# rubocop: disable Gitlab/NamespacedClass +class GroupAccessTokenSerializer < BaseSerializer + entity GroupAccessTokenEntity +end +# rubocop: enable Gitlab/NamespacedClass diff --git a/app/serializers/integrations/project_entity.rb b/app/serializers/integrations/project_entity.rb index ee28c7c19c1..c091133eb39 100644 --- a/app/serializers/integrations/project_entity.rb +++ b/app/serializers/integrations/project_entity.rb @@ -4,6 +4,7 @@ module Integrations class ProjectEntity < Grape::Entity include RequestAwareEntity + expose :id expose :avatar_url expose :full_name expose :name diff --git a/app/serializers/issue_entity.rb b/app/serializers/issue_entity.rb index ea43ed87d22..7ff75927fcd 100644 --- a/app/serializers/issue_entity.rb +++ b/app/serializers/issue_entity.rb @@ -47,6 +47,10 @@ class IssueEntity < IssuableEntity can?(request.current_user, :update_issue, issue) end + expose :can_set_issue_metadata do |issue| + can?(request.current_user, :set_issue_metadata, issue) + end + expose :can_award_emoji do |issue| can?(request.current_user, :award_emoji, issue) end diff --git a/app/serializers/merge_request_poll_widget_entity.rb b/app/serializers/merge_request_poll_widget_entity.rb index fc1534a88aa..40bb905c5c9 100644 --- a/app/serializers/merge_request_poll_widget_entity.rb +++ b/app/serializers/merge_request_poll_widget_entity.rb @@ -33,18 +33,7 @@ class MergeRequestPollWidgetEntity < Grape::Entity # Booleans expose :mergeable_discussions_state?, as: :mergeable_discussions_state do |merge_request| - if Feature.enabled?(:change_response_code_merge_status, merge_request.project) - merge_request.mergeable_discussions_state? - else - # This avoids calling MergeRequest#mergeable_discussions_state without - # considering the state of the MR first. If a MR isn't mergeable, we can - # safely short-circuit it. - if merge_request.mergeable_state?(skip_ci_check: true, skip_discussions_check: true) - merge_request.mergeable_discussions_state? - else - false - end - end + merge_request.mergeable_discussions_state? end expose :project_archived do |merge_request| diff --git a/app/serializers/merge_request_user_entity.rb b/app/serializers/merge_request_user_entity.rb index 12c573d1a13..2e875af6531 100644 --- a/app/serializers/merge_request_user_entity.rb +++ b/app/serializers/merge_request_user_entity.rb @@ -20,10 +20,6 @@ class MergeRequestUserEntity < ::API::Entities::UserBasic find_reviewer_or_assignee(user, options)&.reviewed? end - expose :attention_requested, if: ->(_, options) { options[:merge_request].present? && options[:merge_request].allows_reviewers? && request.current_user&.mr_attention_requests_enabled? } do |user, options| - find_reviewer_or_assignee(user, options)&.attention_requested? - end - expose :approved, if: satisfies(:present?) do |user, options| # This approach is preferred over MergeRequest#approved_by? since this # makes one query per merge request, whereas #approved_by? makes one per user diff --git a/app/serializers/personal_access_token_entity.rb b/app/serializers/personal_access_token_entity.rb new file mode 100644 index 00000000000..acd06fecd12 --- /dev/null +++ b/app/serializers/personal_access_token_entity.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +# rubocop: disable Gitlab/NamespacedClass +class PersonalAccessTokenEntity < API::Entities::PersonalAccessToken + include Gitlab::Routing + + expose :revoke_path do |token, options| + revoke_profile_personal_access_token_path(token) + end +end +# rubocop: enable Gitlab/NamespacedClass diff --git a/app/serializers/personal_access_token_serializer.rb b/app/serializers/personal_access_token_serializer.rb new file mode 100644 index 00000000000..0a59fa117f9 --- /dev/null +++ b/app/serializers/personal_access_token_serializer.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +# rubocop: disable Gitlab/NamespacedClass +class PersonalAccessTokenSerializer < BaseSerializer + entity PersonalAccessTokenEntity +end +# rubocop: enable Gitlab/NamespacedClass diff --git a/app/serializers/project_access_token_entity.rb b/app/serializers/project_access_token_entity.rb new file mode 100644 index 00000000000..b317057c952 --- /dev/null +++ b/app/serializers/project_access_token_entity.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +# rubocop: disable Gitlab/NamespacedClass +class ProjectAccessTokenEntity < API::Entities::PersonalAccessToken + include Gitlab::Routing + + expose :revoke_path do |token, options| + project = options.fetch(:project) + + next unless project + + revoke_namespace_project_settings_access_token_path( + id: token, + namespace_id: project.namespace.path, + project_id: project.path) + end + + expose :access_level do |token, options| + project = options.fetch(:project) + + next unless project + next unless token.user + + project.member(token.user)&.access_level + end +end +# rubocop: enable Gitlab/NamespacedClass diff --git a/app/serializers/project_access_token_serializer.rb b/app/serializers/project_access_token_serializer.rb new file mode 100644 index 00000000000..97db088cf64 --- /dev/null +++ b/app/serializers/project_access_token_serializer.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +# rubocop: disable Gitlab/NamespacedClass +class ProjectAccessTokenSerializer < BaseSerializer + entity ProjectAccessTokenEntity +end +# rubocop: enable Gitlab/NamespacedClass diff --git a/app/serializers/rollout_status_entity.rb b/app/serializers/rollout_status_entity.rb index 9f4c844859b..f432fe98289 100644 --- a/app/serializers/rollout_status_entity.rb +++ b/app/serializers/rollout_status_entity.rb @@ -14,5 +14,5 @@ class RolloutStatusEntity < Grape::Entity expose :completion, if: -> (rollout_status, _) { rollout_status.found? } expose :complete?, as: :is_completed, if: -> (rollout_status, _) { rollout_status.found? } expose :canary_ingress, using: RolloutStatuses::IngressEntity, expose_nil: false, - if: -> (rollout_status, _) { rollout_status.found? && rollout_status.canary_ingress_exists? } + if: -> (rollout_status, _) { rollout_status.found? && rollout_status.canary_ingress_exists? } end |