Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajoute le service provider aux données des webhooks #476

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/authorization_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ def form
@form ||= AuthorizationRequestForm.find(form_uid)
end

delegate :service_provider, to: :form

def name
data['intitule'].presence ||
definition.name.to_s
Expand Down
10 changes: 6 additions & 4 deletions app/models/service_provider.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class ServiceProvider < StaticApplicationRecord
include ActiveModel::Serialization

attr_accessor :id,
:name,
:siret,
Expand Down Expand Up @@ -26,14 +28,14 @@ def self.build(uid, hash)
)
end

def already_integrated?(scope:)
Array(already_integrated).include?(scope.to_s)
end

def self.editors
all.select(&:editor?)
end

def already_integrated?(scope:)
Array(already_integrated).include?(scope.to_s)
end

def editor?
type == TYPES[:editor]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class WebhookAuthorizationRequestSerializer < ApplicationSerializer

has_one :organization, serializer: WebhookOrganizationSerializer
has_one :applicant, serializer: WebhookUserSerializer
has_one :service_provider, serializer: WebhookServiceProviderSerializer

def data
object.data.keys.index_with { |key|
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/webhook_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def now

def authorization_request_serialized
WebhookAuthorizationRequestSerializer.new(authorization_request).serializable_hash(
include: %w[applicant organization]
include: %w[applicant organization service_provider]
)
end
end
5 changes: 5 additions & 0 deletions app/serializers/webhook_service_provider_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class WebhookServiceProviderSerializer < ApplicationSerializer
attributes :id,
:siret,
:type
end
28 changes: 14 additions & 14 deletions config/service_providers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,71 +164,71 @@ shared:
achatpublic:
type: editor
name: "Achatpublic - achatpublic.com"
already_integrated:
already_integrated:
- api_entreprise
actradis:
type: editor
name: "Actradis"
already_integrated:
already_integrated:
- api_entreprise

arnia:
type: editor
name: "Arnia - Pack commande publique"
already_integrated:
already_integrated:
- api_entreprise
atline_services:
type: editor
name: "Atline Services - marches-securises.fr"
already_integrated:
already_integrated:
- api_entreprise
aws_achat:
type: editor
name: "AWS - AWS-achat"
already_integrated:
already_integrated:
- api_entreprise
axyus:
type: editor
name: "Axyus"
already_integrated:
already_integrated:
- api_entreprise
dematis:
type: editor
name: "Dematis - e-marchespublics.com"
already_integrated:
already_integrated:
- api_entreprise
entr_ouvert:
type: editor
name: "Entr'ouvert - Publik"
already_integrated:
already_integrated:
- api_entreprise
klekoon:
type: editor
name: "Klekoon - klekoon.com"
already_integrated:
already_integrated:
- api_entreprise
maximilien:
type: editor
name: "Maximilien"
already_integrated:
already_integrated:
- api_entreprise
megalis_bretagne:
type: editor
name: "Megalis Bretagne"
already_integrated:
already_integrated:
- api_entreprise
pictav_informatique:
type: editor
name: "PICTAV Informatique"
already_integrated:
already_integrated:
- api_entreprise
smartglobal:
type: editor
name: "SmartGlobal - Smart Global Governance"
already_integrated:
already_integrated:
- api_entreprise
solution_attestations:
type: editor
name: "Solution Attestations"
already_integrated:
already_integrated:
- api_entreprise
4 changes: 3 additions & 1 deletion spec/serializers/webhook_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
subject(:serializable_hash) { webhook_serializer.serializable_hash }

let(:webhook_serializer) { described_class.new(authorization_request, 'whatever') }
let(:authorization_request) { create(:authorization_request, :api_entreprise, :validated) }
let(:authorization_request) { create(:authorization_request, :api_entreprise_mgdis, :validated) }

it 'contains valid keys/values' do
expect(serializable_hash).to include(
Expand All @@ -27,6 +27,8 @@
)
)
)

expect(serializable_hash[:data][:service_provider][:siret]).to eq(authorization_request.service_provider.siret)
end
end
end
Loading