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

API Particulier reporters: add direct link to public DataPass pages #1659

Merged
merged 2 commits into from
Sep 11, 2024
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
1 change: 1 addition & 0 deletions app/interactors/datapass_webhook/adapt_v2_to_v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def build_data
{
'pass' => {
'id' => context.model_id,
'public_id' => context.public_id,
'intitule' => generic_data['intitule'],
'description' => generic_data['description'],
'demarche' => context.data['form_uid'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def extract_user_from_contact_payload(contact_payload)

def authorization_request_attributes
context.data['pass'].slice(
'public_id',
'intitule',
'description',
'demarche',
Expand Down
17 changes: 17 additions & 0 deletions app/mailers/api_particulier/reporters_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class APIParticulier::ReportersMailer < APIParticulierMailer
skip_before_action :attach_logos

helper_method :datapass_v2_public_authorization_request_url

%w[
submit
approve
Expand All @@ -23,6 +25,21 @@ class APIParticulier::ReportersMailer < APIParticulierMailer

private

def datapass_v2_public_authorization_request_url(authorization_request)
"#{datapass_v2_base_url(authorization_request.api)}/public/demandes/#{authorization_request.public_id}"
end

def datapass_v2_base_url(api)
case Rails.env
when 'staging'
"https://staging.api-#{api}.v2.datapass.api.gouv.fr"
when 'sandbox'
"https://sandbox.api-#{api}.v2.datapass.api.gouv.fr"
else
"https://api-#{api}.v2.datapass.api.gouv.fr"
end
end

def reporter_emails(groups)
reporters_config.values_at(*groups).flatten
end
Expand Down
2 changes: 2 additions & 0 deletions app/views/api_particulier/reporters_mailer/approve.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Bonjour,

La demande déposée sur DataPass par <%= @authorization_request.demandeur.full_name %> (<%= @authorization_request.demandeur.email %>) pour le compte de l'organisation https://annuaire-entreprises.data.gouv.fr/etablissement/<%= @authorization_request.siret %> a été validée.

Vous pouvez consulter cette demande sur le lien suivant: <%= datapass_v2_public_authorization_request_url(@authorization_request) %>

Vous pouvez consulter la liste des demandes relatives aux données associé aux groupes où vous êtes abonné sur le lien suivant : <%= api_particulier_dashboard_reporter_url %>

Cordialement,
Expand Down
2 changes: 2 additions & 0 deletions app/views/api_particulier/reporters_mailer/submit.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Bonjour,

<%= @authorization_request.demandeur.full_name %> (<%= @authorization_request.demandeur.email %>) a soumis une nouvelle demande d'habilitation sur DataPass pour le compte de l'organisation https://annuaire-entreprises.data.gouv.fr/etablissement/<%= @authorization_request.siret %>.

Vous pouvez consulter cette demande sur le lien suivant: <%= datapass_v2_public_authorization_request_url(@authorization_request) %>

Vous pouvez consulter la liste des demandes relatives aux données associé aux groupes où vous êtes abonné sur le lien suivant : <%= api_particulier_dashboard_reporter_url %>

Cordialement,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPublicIdToAuthorizationRequests < ActiveRecord::Migration[7.2]
def change
add_column :authorization_requests, :public_id, :uuid
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

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

1 change: 1 addition & 0 deletions spec/factories/authorization_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
status { 'draft' }
api { 'entreprise' }
siret { '13002526500013' }
public_id { SecureRandom.uuid }

trait :without_external_id do
external_id { nil }
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/datapass_webhooks_v2.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FactoryBot.define do
sequence(:datapass_webhook_v2_id, &:to_i)
sequence(:datapass_webhook_v2_public_id) { SecureRandom.uuid }

factory :datapass_webhook_v2, class: Hash do
initialize_with { attributes.stringify_keys }

event { %w[refuse_application refuse].sample }
public_id { generate(:datapass_webhook_v2_public_id) }
model_id { generate(:datapass_webhook_v2_id) }
model_type { 'authorization_request/api_entreprise' }
fired_at { Time.zone.now.to_i }
Expand Down
8 changes: 7 additions & 1 deletion spec/mailers/api_particulier/reporters_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
end

describe '#submit' do
let(:authorization_request) { create(:authorization_request, :with_demandeur) }

subject(:mail) do
described_class.with(groups: %w[cnaf_ men_], authorization_request: create(:authorization_request, :with_demandeur)).submit
described_class.with(groups: %w[cnaf_ men_], authorization_request:).submit
end

it 'has a link to public id' do
expect(mail.body.encoded).to include(authorization_request.public_id)
end

it 'sends an email to reporters associated to these groups' do
Expand Down
3 changes: 2 additions & 1 deletion spec/organizers/datapass_webhook/v2/api_entreprise_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
expect { subject }.to change(UserAuthorizationRequestRole.where(role: 'contact_metier'), :count).by(1)
end

it 'creates an authorization request with entreprise api and demarche' do
it 'creates an authorization request with entreprise api, demarche and public id' do
expect(subject.authorization_request.api).to eq('entreprise')
expect(subject.authorization_request.demarche).to eq('api-entreprise')
expect(subject.authorization_request.public_id).to be_present
end

describe 'when contact metier is empty (non-regression test)' do
Expand Down
Loading