diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-10 15:09:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-10 15:09:36 +0300 |
commit | 948023c9c900344aa1e2f334bcaae5a194873b0d (patch) | |
tree | 846c5dbcec70436bca337d970bd11082f91eeb66 /app/serializers | |
parent | f42c4be1c0d5247fac0c059ec41c9a1961485aed (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/serializers')
-rw-r--r-- | app/serializers/integrations/event_entity.rb | 46 | ||||
-rw-r--r-- | app/serializers/integrations/event_serializer.rb | 7 | ||||
-rw-r--r-- | app/serializers/integrations/field_entity.rb | 49 | ||||
-rw-r--r-- | app/serializers/integrations/field_serializer.rb | 7 | ||||
-rw-r--r-- | app/serializers/service_event_entity.rb | 44 | ||||
-rw-r--r-- | app/serializers/service_event_serializer.rb | 5 | ||||
-rw-r--r-- | app/serializers/service_field_entity.rb | 47 | ||||
-rw-r--r-- | app/serializers/service_field_serializer.rb | 5 |
8 files changed, 109 insertions, 101 deletions
diff --git a/app/serializers/integrations/event_entity.rb b/app/serializers/integrations/event_entity.rb new file mode 100644 index 00000000000..170f660f334 --- /dev/null +++ b/app/serializers/integrations/event_entity.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +module Integrations + class EventEntity < Grape::Entity + include RequestAwareEntity + + expose :title do |event| + IntegrationsHelper.integration_event_title(event) + end + + expose :event_field_name, as: :name + + expose :value do |event| + integration[event_field_name] + end + + expose :description do |event| + IntegrationsHelper.integration_event_description(integration, event) + end + + expose :field, if: ->(_, _) { event_field } do + expose :name do |event| + event_field[:name] + end + expose :value do |event| + integration.public_send(event_field[:name]) # rubocop:disable GitlabSecurity/PublicSend + end + end + + private + + alias_method :event, :object + + def event_field_name + IntegrationsHelper.integration_event_field_name(event) + end + + def event_field + @event_field ||= integration.event_field(event) + end + + def integration + request.integration + end + end +end diff --git a/app/serializers/integrations/event_serializer.rb b/app/serializers/integrations/event_serializer.rb new file mode 100644 index 00000000000..fab7f9d459f --- /dev/null +++ b/app/serializers/integrations/event_serializer.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Integrations + class EventSerializer < BaseSerializer + entity Integrations::EventEntity + end +end diff --git a/app/serializers/integrations/field_entity.rb b/app/serializers/integrations/field_entity.rb new file mode 100644 index 00000000000..697b53a737e --- /dev/null +++ b/app/serializers/integrations/field_entity.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +module Integrations + class FieldEntity < Grape::Entity + include RequestAwareEntity + include Gitlab::Utils::StrongMemoize + + expose :section, :type, :name, :placeholder, :required, :choices, :checkbox_label + + expose :title do |field| + non_empty_password?(field) ? field[:non_empty_password_title] : field[:title] + end + + expose :help do |field| + non_empty_password?(field) ? field[:non_empty_password_help] : field[:help] + end + + expose :value do |field| + value = value_for(field) + + if non_empty_password?(field) + 'true' + elsif field[:type] == 'checkbox' + ActiveRecord::Type::Boolean.new.deserialize(value).to_s + else + value + end + end + + private + + def integration + request.integration + end + + def value_for(field) + strong_memoize(:value_for) do + # field[:name] is not user input and so can assume is safe + integration.public_send(field[:name]) # rubocop:disable GitlabSecurity/PublicSend + end + end + + def non_empty_password?(field) + strong_memoize(:non_empty_password) do + field[:type] == 'password' && value_for(field).present? + end + end + end +end diff --git a/app/serializers/integrations/field_serializer.rb b/app/serializers/integrations/field_serializer.rb new file mode 100644 index 00000000000..c8f9823e997 --- /dev/null +++ b/app/serializers/integrations/field_serializer.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Integrations + class FieldSerializer < BaseSerializer + entity Integrations::FieldEntity + end +end diff --git a/app/serializers/service_event_entity.rb b/app/serializers/service_event_entity.rb deleted file mode 100644 index 49a4944b2b0..00000000000 --- a/app/serializers/service_event_entity.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -class ServiceEventEntity < Grape::Entity - include RequestAwareEntity - - expose :title do |event| - IntegrationsHelper.integration_event_title(event) - end - - expose :event_field_name, as: :name - - expose :value do |event| - integration[event_field_name] - end - - expose :description do |event| - IntegrationsHelper.integration_event_description(integration, event) - end - - expose :field, if: -> (_, _) { event_field } do - expose :name do |event| - event_field[:name] - end - expose :value do |event| - integration.public_send(event_field[:name]) # rubocop:disable GitlabSecurity/PublicSend - end - end - - private - - alias_method :event, :object - - def event_field_name - IntegrationsHelper.integration_event_field_name(event) - end - - def event_field - @event_field ||= integration.event_field(event) - end - - def integration - request.service - end -end diff --git a/app/serializers/service_event_serializer.rb b/app/serializers/service_event_serializer.rb deleted file mode 100644 index 7f5fe36e571..00000000000 --- a/app/serializers/service_event_serializer.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -class ServiceEventSerializer < BaseSerializer - entity ServiceEventEntity -end diff --git a/app/serializers/service_field_entity.rb b/app/serializers/service_field_entity.rb deleted file mode 100644 index b13f2c0e217..00000000000 --- a/app/serializers/service_field_entity.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -class ServiceFieldEntity < Grape::Entity - include RequestAwareEntity - include Gitlab::Utils::StrongMemoize - - expose :section, :type, :name, :placeholder, :required, :choices, :checkbox_label - - expose :title do |field| - non_empty_password?(field) ? field[:non_empty_password_title] : field[:title] - end - - expose :help do |field| - non_empty_password?(field) ? field[:non_empty_password_help] : field[:help] - end - - expose :value do |field| - value = value_for(field) - - if non_empty_password?(field) - 'true' - elsif field[:type] == 'checkbox' - ActiveRecord::Type::Boolean.new.deserialize(value).to_s - else - value - end - end - - private - - def service - request.service - end - - def value_for(field) - strong_memoize(:value_for) do - # field[:name] is not user input and so can assume is safe - service.public_send(field[:name]) # rubocop:disable GitlabSecurity/PublicSend - end - end - - def non_empty_password?(field) - strong_memoize(:non_empty_password) do - field[:type] == 'password' && value_for(field).present? - end - end -end diff --git a/app/serializers/service_field_serializer.rb b/app/serializers/service_field_serializer.rb deleted file mode 100644 index 120d0f5820e..00000000000 --- a/app/serializers/service_field_serializer.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -class ServiceFieldSerializer < BaseSerializer - entity ServiceFieldEntity -end |