Skip to content

Commit

Permalink
feat(hubspot): Remove obsolete private app token from Hubspot
Browse files Browse the repository at this point in the history
  • Loading branch information
ivannovosad committed Oct 15, 2024
1 parent e3c19d6 commit b5b1e25
Show file tree
Hide file tree
Showing 24 changed files with 1,408 additions and 204 deletions.
1 change: 0 additions & 1 deletion app/graphql/types/integrations/hubspot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class Hubspot < Types::BaseObject
field :default_targeted_object, Types::Integrations::Hubspot::TargetedObjectsEnum, null: false
field :id, ID, null: false
field :name, String, null: false
field :private_app_token, String, null: false
field :sync_invoices, Boolean
field :sync_subscriptions, Boolean
end
Expand Down
1 change: 0 additions & 1 deletion app/graphql/types/integrations/hubspot/create_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class CreateInput < Types::BaseInputObject

argument :connection_id, String, required: true
argument :default_targeted_object, Types::Integrations::Hubspot::TargetedObjectsEnum, required: true
argument :private_app_token, String, required: true
argument :sync_invoices, Boolean, required: false
argument :sync_subscriptions, Boolean, required: false
end
Expand Down
1 change: 0 additions & 1 deletion app/graphql/types/integrations/hubspot/update_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class UpdateInput < Types::BaseInputObject

argument :connection_id, String, required: false
argument :default_targeted_object, Types::Integrations::Hubspot::TargetedObjectsEnum, required: false
argument :private_app_token, String, required: false
argument :sync_invoices, Boolean, required: false
argument :sync_subscriptions, Boolean, required: false
end
Expand Down
16 changes: 0 additions & 16 deletions app/jobs/integrations/aggregator/send_private_app_token_job.rb

This file was deleted.

4 changes: 2 additions & 2 deletions app/models/integrations/hubspot_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

module Integrations
class HubspotIntegration < BaseIntegration
validates :connection_id, :private_app_token, :default_targeted_object, presence: true
validates :connection_id, :default_targeted_object, presence: true

settings_accessors :default_targeted_object, :sync_subscriptions, :sync_invoices, :subscriptions_object_type_id,
:invoices_object_type_id, :companies_properties_version, :contacts_properties_version,
:subscriptions_properties_version, :invoices_properties_version, :portal_id
secrets_accessors :connection_id, :private_app_token
secrets_accessors :connection_id

TARGETED_OBJECTS = %w[companies contacts].freeze

Expand Down
41 changes: 41 additions & 0 deletions app/services/integrations/aggregator/custom_object_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

module Integrations
module Aggregator
class CustomObjectService < BaseService
def initialize(integration:, name:)
@name = name
super(integration:)
end

def action_path
"v1/#{provider}/custom-object"
end

def call
response = http_client.get(headers:, params:)

result.custom_object = OpenStruct.new(response)
result
end

private

attr_reader :name

def headers
{
'Connection-Id' => integration.connection_id,
'Authorization' => "Bearer #{secret_key}",
'Provider-Config-Key' => provider_key
}
end

def params
{
'name' => name
}
end
end
end
end

This file was deleted.

2 changes: 0 additions & 2 deletions app/services/integrations/hubspot/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def call
name: params[:name],
code: params[:code],
connection_id: params[:connection_id],
private_app_token: params[:private_app_token],
default_targeted_object: params[:default_targeted_object],
sync_invoices: ActiveModel::Type::Boolean.new.cast(params[:sync_invoices]),
sync_subscriptions: ActiveModel::Type::Boolean.new.cast(params[:sync_subscriptions])
Expand All @@ -31,7 +30,6 @@ def call
integration.save!

if integration.type == 'Integrations::HubspotIntegration'
Integrations::Aggregator::SendPrivateAppTokenJob.perform_later(integration:)
Integrations::Aggregator::SyncCustomObjectsAndPropertiesJob.perform_later(integration:)
Integrations::Hubspot::SavePortalIdJob.perform_later(integration:)
end
Expand Down
7 changes: 0 additions & 7 deletions app/services/integrations/hubspot/update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,14 @@ def call
return result.not_allowed_failure!(code: 'premium_integration_missing')
end

old_private_app_token = integration.private_app_token

integration.name = params[:name] if params.key?(:name)
integration.code = params[:code] if params.key?(:code)
integration.private_app_token = params[:private_app_token] if params.key?(:private_app_token)
integration.default_targeted_object = params[:default_targeted_object] if params.key?(:default_targeted_object)
integration.sync_invoices = params[:sync_invoices] if params.key?(:sync_invoices)
integration.sync_subscriptions = params[:sync_subscriptions] if params.key?(:sync_subscriptions)

integration.save!

if integration.type == 'Integrations::HubspotIntegration' && integration.private_app_token != old_private_app_token
Integrations::Aggregator::SendPrivateAppTokenJob.perform_later(integration:)
end

result.integration = integration
result
rescue ActiveRecord::RecordInvalid => e
Expand Down
3 changes: 0 additions & 3 deletions schema.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 0 additions & 46 deletions schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion spec/factories/integrations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
end

secrets do
{connection_id: SecureRandom.uuid, private_app_token: SecureRandom.uuid}.to_json
{connection_id: SecureRandom.uuid}.to_json
end
end
end
Loading

0 comments on commit b5b1e25

Please sign in to comment.