From be834a25982746ffd85252ff502df42bb88cb9d5 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 5 Oct 2020 13:54:15 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-5-stable-ee --- app/serializers/ci/trigger_entity.rb | 42 +++++++++++++++++++ app/serializers/ci/trigger_serializer.rb | 7 ++++ app/serializers/cluster_entity.rb | 2 + app/serializers/cluster_serializer.rb | 1 + app/serializers/container_repository_entity.rb | 1 + app/serializers/diff_file_base_entity.rb | 14 ++++++- app/serializers/diffs_entity.rb | 4 +- app/serializers/feature_flag_entity.rb | 48 ++++++++++++++++++++++ app/serializers/feature_flag_scope_entity.rb | 12 ++++++ app/serializers/feature_flag_serializer.rb | 10 +++++ app/serializers/feature_flag_summary_entity.rb | 19 +++++++++ app/serializers/feature_flag_summary_serializer.rb | 5 +++ app/serializers/feature_flags/scope_entity.rb | 8 ++++ app/serializers/feature_flags/strategy_entity.rb | 11 +++++ app/serializers/feature_flags/user_list_entity.rb | 10 +++++ app/serializers/feature_flags_client_entity.rb | 7 ++++ app/serializers/feature_flags_client_serializer.rb | 9 ++++ app/serializers/group_group_link_entity.rb | 20 +++++++++ app/serializers/merge_request_basic_entity.rb | 1 + .../merge_request_poll_cached_widget_entity.rb | 12 ++++-- .../merge_request_poll_widget_entity.rb | 16 +++----- app/serializers/merge_request_widget_entity.rb | 6 +-- app/serializers/paginated_diff_entity.rb | 2 - app/serializers/pipeline_serializer.rb | 10 ++++- app/serializers/test_case_entity.rb | 1 + 25 files changed, 254 insertions(+), 24 deletions(-) create mode 100644 app/serializers/ci/trigger_entity.rb create mode 100644 app/serializers/ci/trigger_serializer.rb create mode 100644 app/serializers/feature_flag_entity.rb create mode 100644 app/serializers/feature_flag_scope_entity.rb create mode 100644 app/serializers/feature_flag_serializer.rb create mode 100644 app/serializers/feature_flag_summary_entity.rb create mode 100644 app/serializers/feature_flag_summary_serializer.rb create mode 100644 app/serializers/feature_flags/scope_entity.rb create mode 100644 app/serializers/feature_flags/strategy_entity.rb create mode 100644 app/serializers/feature_flags/user_list_entity.rb create mode 100644 app/serializers/feature_flags_client_entity.rb create mode 100644 app/serializers/feature_flags_client_serializer.rb (limited to 'app/serializers') diff --git a/app/serializers/ci/trigger_entity.rb b/app/serializers/ci/trigger_entity.rb new file mode 100644 index 00000000000..005a9b752ed --- /dev/null +++ b/app/serializers/ci/trigger_entity.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +module Ci + class TriggerEntity < Grape::Entity + include Gitlab::Routing + include Gitlab::Allowable + + expose :description + expose :owner, using: UserEntity + expose :last_used + + expose :token do |trigger| + can_admin_trigger?(trigger) ? trigger.token : trigger.short_token + end + + expose :has_token_exposed do |trigger| + can_admin_trigger?(trigger) + end + + expose :can_access_project do |trigger| + trigger.can_access_project? + end + + expose :project_trigger_path, if: -> (trigger) { can_manage_trigger?(trigger) } do |trigger| + project_trigger_path(options[:project], trigger) + end + + expose :edit_project_trigger_path, if: -> (trigger) { can_admin_trigger?(trigger) } do |trigger| + edit_project_trigger_path(options[:project], trigger) + end + + private + + def can_manage_trigger?(trigger) + can?(options[:current_user], :manage_trigger, trigger) + end + + def can_admin_trigger?(trigger) + can?(options[:current_user], :admin_trigger, trigger) + end + end +end diff --git a/app/serializers/ci/trigger_serializer.rb b/app/serializers/ci/trigger_serializer.rb new file mode 100644 index 00000000000..8e42ec12c3f --- /dev/null +++ b/app/serializers/ci/trigger_serializer.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Ci + class TriggerSerializer < BaseSerializer + entity ::Ci::TriggerEntity + end +end diff --git a/app/serializers/cluster_entity.rb b/app/serializers/cluster_entity.rb index eea0acdc11b..b904666971e 100644 --- a/app/serializers/cluster_entity.rb +++ b/app/serializers/cluster_entity.rb @@ -6,6 +6,8 @@ class ClusterEntity < Grape::Entity expose :cluster_type expose :enabled expose :environment_scope + expose :id + expose :namespace_per_environment expose :name expose :nodes expose :provider_type diff --git a/app/serializers/cluster_serializer.rb b/app/serializers/cluster_serializer.rb index 700a46040e3..f71591612a6 100644 --- a/app/serializers/cluster_serializer.rb +++ b/app/serializers/cluster_serializer.rb @@ -12,6 +12,7 @@ class ClusterSerializer < BaseSerializer :environment_scope, :gitlab_managed_apps_logs_path, :enable_advanced_logs_querying, + :id, :kubernetes_errors, :name, :nodes, diff --git a/app/serializers/container_repository_entity.rb b/app/serializers/container_repository_entity.rb index 4c87d1438b0..9a002971bef 100644 --- a/app/serializers/container_repository_entity.rb +++ b/app/serializers/container_repository_entity.rb @@ -4,6 +4,7 @@ class ContainerRepositoryEntity < Grape::Entity include RequestAwareEntity expose :id, :name, :path, :location, :created_at, :status, :tags_count + expose :expiration_policy_started_at, as: :cleanup_policy_started_at expose :tags_path do |repository| project_registry_repository_tags_path(project, repository, format: :json) diff --git a/app/serializers/diff_file_base_entity.rb b/app/serializers/diff_file_base_entity.rb index 9f27191c3c8..596f5d686da 100644 --- a/app/serializers/diff_file_base_entity.rb +++ b/app/serializers/diff_file_base_entity.rb @@ -34,7 +34,7 @@ class DiffFileBaseEntity < Grape::Entity expose :edit_path, if: -> (_, options) { options[:merge_request] } do |diff_file| merge_request = options[:merge_request] - next unless merge_request.merged? || merge_request.source_branch_exists? + next unless has_edit_path?(merge_request) target_project, target_branch = edit_project_branch_options(merge_request) @@ -43,6 +43,14 @@ class DiffFileBaseEntity < Grape::Entity project_edit_blob_path(target_project, tree_join(target_branch, diff_file.new_path), options) end + expose :ide_edit_path, if: -> (_, options) { options[:merge_request] } do |diff_file| + merge_request = options[:merge_request] + + next unless has_edit_path?(merge_request) + + gitlab_ide_merge_request_path(merge_request) + end + expose :old_path_html do |diff_file| old_path, _ = mark_inline_diffs(diff_file.old_path, diff_file.new_path) old_path @@ -125,4 +133,8 @@ class DiffFileBaseEntity < Grape::Entity [merge_request.target_project, merge_request.target_branch] end end + + def has_edit_path?(merge_request) + merge_request.merged? || merge_request.source_branch_exists? + end end diff --git a/app/serializers/diffs_entity.rb b/app/serializers/diffs_entity.rb index 6ef524b5bec..0b4f21c55f4 100644 --- a/app/serializers/diffs_entity.rb +++ b/app/serializers/diffs_entity.rb @@ -78,7 +78,7 @@ class DiffsEntity < Grape::Entity options[:merge_request_diffs] end - expose :definition_path_prefix, if: -> (diff_file) { Feature.enabled?(:code_navigation, merge_request.project, default_enabled: true) } do |diffs| + expose :definition_path_prefix do |diffs| project_blob_path(merge_request.project, diffs.diff_refs&.head_sha) end @@ -89,8 +89,6 @@ class DiffsEntity < Grape::Entity private def code_navigation_path(diffs) - return unless Feature.enabled?(:code_navigation, merge_request.project, default_enabled: true) - Gitlab::CodeNavigationPath.new(merge_request.project, diffs.diff_refs&.head_sha) end diff --git a/app/serializers/feature_flag_entity.rb b/app/serializers/feature_flag_entity.rb new file mode 100644 index 00000000000..80cf869a389 --- /dev/null +++ b/app/serializers/feature_flag_entity.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +class FeatureFlagEntity < Grape::Entity + include RequestAwareEntity + + expose :id + expose :iid + expose :active + expose :created_at + expose :updated_at + expose :name + expose :description + expose :version + + expose :edit_path, if: -> (feature_flag, _) { can_update?(feature_flag) } do |feature_flag| + edit_project_feature_flag_path(feature_flag.project, feature_flag) + end + + expose :update_path, if: -> (feature_flag, _) { can_update?(feature_flag) } do |feature_flag| + project_feature_flag_path(feature_flag.project, feature_flag) + end + + expose :destroy_path, if: -> (feature_flag, _) { can_destroy?(feature_flag) } do |feature_flag| + project_feature_flag_path(feature_flag.project, feature_flag) + end + + expose :scopes, with: FeatureFlagScopeEntity do |feature_flag| + feature_flag.scopes.sort_by(&:id) + end + + expose :strategies, with: FeatureFlags::StrategyEntity do |feature_flag| + feature_flag.strategies.sort_by(&:id) + end + + private + + def can_update?(feature_flag) + can?(current_user, :update_feature_flag, feature_flag) + end + + def can_destroy?(feature_flag) + can?(current_user, :destroy_feature_flag, feature_flag) + end + + def current_user + request.current_user + end +end diff --git a/app/serializers/feature_flag_scope_entity.rb b/app/serializers/feature_flag_scope_entity.rb new file mode 100644 index 00000000000..0450797a545 --- /dev/null +++ b/app/serializers/feature_flag_scope_entity.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class FeatureFlagScopeEntity < Grape::Entity + include RequestAwareEntity + + expose :id + expose :active + expose :environment_scope + expose :created_at + expose :updated_at + expose :strategies +end diff --git a/app/serializers/feature_flag_serializer.rb b/app/serializers/feature_flag_serializer.rb new file mode 100644 index 00000000000..e0ff33cc61a --- /dev/null +++ b/app/serializers/feature_flag_serializer.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class FeatureFlagSerializer < BaseSerializer + include WithPagination + entity FeatureFlagEntity + + def represent(resource, opts = {}) + super(resource, opts) + end +end diff --git a/app/serializers/feature_flag_summary_entity.rb b/app/serializers/feature_flag_summary_entity.rb new file mode 100644 index 00000000000..be4f02dabca --- /dev/null +++ b/app/serializers/feature_flag_summary_entity.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class FeatureFlagSummaryEntity < Grape::Entity + include RequestAwareEntity + + expose :count do + expose :all do |project| + project.operations_feature_flags.count + end + + expose :enabled do |project| + project.operations_feature_flags.enabled.count + end + + expose :disabled do |project| + project.operations_feature_flags.disabled.count + end + end +end diff --git a/app/serializers/feature_flag_summary_serializer.rb b/app/serializers/feature_flag_summary_serializer.rb new file mode 100644 index 00000000000..46f70666e40 --- /dev/null +++ b/app/serializers/feature_flag_summary_serializer.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class FeatureFlagSummarySerializer < BaseSerializer + entity FeatureFlagSummaryEntity +end diff --git a/app/serializers/feature_flags/scope_entity.rb b/app/serializers/feature_flags/scope_entity.rb new file mode 100644 index 00000000000..1c9dd491652 --- /dev/null +++ b/app/serializers/feature_flags/scope_entity.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +module FeatureFlags + class ScopeEntity < Grape::Entity + expose :id + expose :environment_scope + end +end diff --git a/app/serializers/feature_flags/strategy_entity.rb b/app/serializers/feature_flags/strategy_entity.rb new file mode 100644 index 00000000000..73450476869 --- /dev/null +++ b/app/serializers/feature_flags/strategy_entity.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module FeatureFlags + class StrategyEntity < Grape::Entity + expose :id + expose :name + expose :parameters + expose :scopes, with: FeatureFlags::ScopeEntity + expose :user_list, with: FeatureFlags::UserListEntity, expose_nil: false + end +end diff --git a/app/serializers/feature_flags/user_list_entity.rb b/app/serializers/feature_flags/user_list_entity.rb new file mode 100644 index 00000000000..d3fddb4fa7a --- /dev/null +++ b/app/serializers/feature_flags/user_list_entity.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module FeatureFlags + class UserListEntity < Grape::Entity + expose :id + expose :iid + expose :name + expose :user_xids + end +end diff --git a/app/serializers/feature_flags_client_entity.rb b/app/serializers/feature_flags_client_entity.rb new file mode 100644 index 00000000000..4a195c7d759 --- /dev/null +++ b/app/serializers/feature_flags_client_entity.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class FeatureFlagsClientEntity < Grape::Entity + include RequestAwareEntity + + expose :token +end diff --git a/app/serializers/feature_flags_client_serializer.rb b/app/serializers/feature_flags_client_serializer.rb new file mode 100644 index 00000000000..104729b6668 --- /dev/null +++ b/app/serializers/feature_flags_client_serializer.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class FeatureFlagsClientSerializer < BaseSerializer + entity FeatureFlagsClientEntity + + def represent_token(resource, opts = {}) + represent(resource, only: [:token]) + end +end diff --git a/app/serializers/group_group_link_entity.rb b/app/serializers/group_group_link_entity.rb index 7a51e1a9316..491c672233d 100644 --- a/app/serializers/group_group_link_entity.rb +++ b/app/serializers/group_group_link_entity.rb @@ -1,12 +1,22 @@ # 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 @@ -23,4 +33,14 @@ class GroupGroupLinkEntity < Grape::Entity 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/merge_request_basic_entity.rb b/app/serializers/merge_request_basic_entity.rb index ef1177e9967..9e2bce53c8a 100644 --- a/app/serializers/merge_request_basic_entity.rb +++ b/app/serializers/merge_request_basic_entity.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class MergeRequestBasicEntity < Grape::Entity + expose :title expose :public_merge_status, as: :merge_status expose :merge_error expose :state diff --git a/app/serializers/merge_request_poll_cached_widget_entity.rb b/app/serializers/merge_request_poll_cached_widget_entity.rb index 002be8be729..080b6554de1 100644 --- a/app/serializers/merge_request_poll_cached_widget_entity.rb +++ b/app/serializers/merge_request_poll_cached_widget_entity.rb @@ -15,7 +15,7 @@ class MergeRequestPollCachedWidgetEntity < IssuableEntity expose :target_project_id expose :squash expose :rebase_in_progress?, as: :rebase_in_progress - expose :default_squash_commit_message, if: -> (merge_request, _) { merge_request.mergeable? } + expose :default_squash_commit_message expose :commits_count expose :merge_ongoing?, as: :merge_ongoing expose :work_in_progress?, as: :work_in_progress @@ -25,10 +25,10 @@ class MergeRequestPollCachedWidgetEntity < IssuableEntity expose :source_branch_exists?, as: :source_branch_exists expose :branch_missing?, as: :branch_missing - expose :commits_without_merge_commits, using: MergeRequestWidgetCommitEntity, - if: -> (merge_request, _) { merge_request.mergeable? } do |merge_request| + expose :commits_without_merge_commits, using: MergeRequestWidgetCommitEntity do |merge_request| merge_request.recent_commits.without_merge_commits end + expose :diff_head_sha do |merge_request| merge_request.diff_head_sha.presence end @@ -46,6 +46,12 @@ class MergeRequestPollCachedWidgetEntity < IssuableEntity end end + expose :actual_head_pipeline, as: :pipeline, if: -> (mr, _) { + Feature.enabled?(:merge_request_cached_pipeline_serializer, mr.project) && presenter(mr).can_read_pipeline? + } do |merge_request, options| + MergeRequests::PipelineEntity.represent(merge_request.actual_head_pipeline, options) + end + # Paths # expose :target_branch_commits_path do |merge_request| diff --git a/app/serializers/merge_request_poll_widget_entity.rb b/app/serializers/merge_request_poll_widget_entity.rb index 41ab5005091..9609a894e6d 100644 --- a/app/serializers/merge_request_poll_widget_entity.rb +++ b/app/serializers/merge_request_poll_widget_entity.rb @@ -19,20 +19,14 @@ class MergeRequestPollWidgetEntity < Grape::Entity # User entities expose :merge_user, using: UserEntity - 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 + expose :actual_head_pipeline, as: :pipeline, if: -> (mr, _) { + Feature.disabled?(:merge_request_cached_pipeline_serializer, mr.project) && presenter(mr).can_read_pipeline? + } do |merge_request, options| + MergeRequests::PipelineEntity.represent(merge_request.actual_head_pipeline, options) end 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 + MergeRequests::PipelineEntity.represent(merge_request.merge_pipeline, options) 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 494192c8dbb..3fd2edfd425 100644 --- a/app/serializers/merge_request_widget_entity.rb +++ b/app/serializers/merge_request_widget_entity.rb @@ -67,15 +67,15 @@ class MergeRequestWidgetEntity < Grape::Entity ) end - expose :user_callouts_path, if: -> (*) { Feature.enabled?(:suggest_pipeline) } do |merge_request| + expose :user_callouts_path, if: -> (*) { Gitlab::Experimentation.enabled?(:suggest_pipeline) } do |_merge_request| user_callouts_path end - expose :suggest_pipeline_feature_id, if: -> (*) { Feature.enabled?(:suggest_pipeline) } do |merge_request| + expose :suggest_pipeline_feature_id, if: -> (*) { Gitlab::Experimentation.enabled?(:suggest_pipeline) } do |_merge_request| SUGGEST_PIPELINE end - expose :is_dismissed_suggest_pipeline, if: -> (*) { Feature.enabled?(:suggest_pipeline) } do |merge_request| + expose :is_dismissed_suggest_pipeline, if: -> (*) { Gitlab::Experimentation.enabled?(:suggest_pipeline) } do |_merge_request| current_user && current_user.dismissed_callout?(feature_name: SUGGEST_PIPELINE) end diff --git a/app/serializers/paginated_diff_entity.rb b/app/serializers/paginated_diff_entity.rb index 37c48338e55..f24571f7d7d 100644 --- a/app/serializers/paginated_diff_entity.rb +++ b/app/serializers/paginated_diff_entity.rb @@ -37,8 +37,6 @@ class PaginatedDiffEntity < Grape::Entity private def code_navigation_path(diffs) - return unless Feature.enabled?(:code_navigation, merge_request.project, default_enabled: true) - Gitlab::CodeNavigationPath.new(merge_request.project, diffs.diff_refs&.head_sha) end diff --git a/app/serializers/pipeline_serializer.rb b/app/serializers/pipeline_serializer.rb index 45c5a1d3e1c..a45214670fa 100644 --- a/app/serializers/pipeline_serializer.rb +++ b/app/serializers/pipeline_serializer.rb @@ -47,6 +47,7 @@ class PipelineSerializer < BaseSerializer :retryable_builds, :scheduled_actions, :stages, + :latest_statuses, :trigger_requests, :user, { @@ -62,7 +63,14 @@ class PipelineSerializer < BaseSerializer pending_builds: :project, project: [:route, { namespace: :route }], triggered_by_pipeline: [{ project: [:route, { namespace: :route }] }, :user], - triggered_pipelines: [{ project: [:route, { namespace: :route }] }, :user, :source_job] + triggered_pipelines: [ + { + project: [:route, { namespace: :route }] + }, + :source_job, + :latest_statuses, + :user + ] } ] end diff --git a/app/serializers/test_case_entity.rb b/app/serializers/test_case_entity.rb index d2e08590ef0..b44aa62ad73 100644 --- a/app/serializers/test_case_entity.rb +++ b/app/serializers/test_case_entity.rb @@ -6,6 +6,7 @@ class TestCaseEntity < Grape::Entity expose :status expose :name expose :classname + expose :file expose :execution_time expose :system_output expose :stack_trace -- cgit v1.2.3