Skip to content

Commit

Permalink
Empêche la soumission d'une demande de réouverture si aucun changemen…
Browse files Browse the repository at this point in the history
…t n'a été effectué
  • Loading branch information
jbfeldis committed Oct 1, 2024
1 parent 9c76b6d commit 11fde5e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/models/authorization_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ def reopening?
last_validated_at.present?
end

def changed_since_authorization?
data != latest_authorization&.data
end

def contact_types_for(user)
contact_type_key_values = data.select do |key, value|
key =~ /.*_email$/ && value == user.email
Expand Down
5 changes: 5 additions & 0 deletions app/policies/authorization_request_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def cancel_reopening?
record.can_cancel_reopening? && !record.submitted?
end

def submit_reopening?
same_user_and_organization? &&
record.changed_since_authorization?
end

def messages?
record.persisted? &&
record.applicant == user
Expand Down
2 changes: 1 addition & 1 deletion app/views/authorization_request_forms/summary.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
<%= dsfr_main_modal_button(t('authorization_request_forms.form.cancel_reopening'), new_authorization_request_cancel_reopening_path(@authorization_request), class: %w(fr-btn fr-btn--secondary fr-icon-arrow-left-s-line-double fr-btn--icon-left)) %>
</li>
<li class="fr-ml-auto">
<%= f.button t('authorization_request_forms.form.submit_reopening'), type: :submit, name: :submit, id: :submit_authorization_request, class: %w(fr-btn fr-icon-checkbox-line fr-btn--icon-left) %>
<%= f.button t('authorization_request_forms.form.submit_reopening'), disabled: !policy(@authorization_request).submit_reopening?, type: :submit, name: :submit, id: :submit_authorization_request, class: %w(fr-btn fr-icon-checkbox-line fr-btn--icon-left) %>
</li>
</ul>
</div>
Expand Down
15 changes: 14 additions & 1 deletion features/reouverture_habilitation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,24 @@ Fonctionnalité: Réouverture d'une habilitation validée
Et que je clique sur "Annuler ma demande de modification"
Alors il y a un message de succès contenant "a été annulée"

Scénario: Soumission d'une habilitation fraîchement réouverte
Scénario: Soumission impossible d'une habilitation fraîchement réouverte
Quand j'ai 1 demande d'habilitation "API Entreprise" réouverte
Et que je vais sur la page tableau de bord
Et que je clique sur le dernier "Consulter"
Alors il y a un bouton "Annuler ma demande de modification"
Et il n'y a pas de bouton "Envoyer ma demande de modification"

Scénario: Soumission d'une habilitation réouverte avec des modifications
Quand j'ai 1 demande d'habilitation "API Entreprise" réouverte
Et que je vais sur la page tableau de bord
Et que je clique sur le dernier "Consulter"
Alors il y a un bouton "Annuler ma demande de modification"
Et il n'y a pas de bouton "Envoyer ma demande de modification"
Quand je clique sur "Modifier" dans le bloc de résumé "Les personnes impliquées"
Et que je remplis les informations du contact "Responsable de traitement" avec :
| Nom | Prénom | Email | Téléphone | Fonction |
|Jean | Louis | nouveau.louis@gouv.fr | 0836656560 | Directeur associé d'exploitation |
Et que je clique sur "Enregistrer les modifications"
Et que je clique sur "Envoyer ma demande de modification"
Alors il y a un message de succès contenant "soumise avec succès"
Et il y a un badge "Validée"
Expand Down
18 changes: 18 additions & 0 deletions spec/models/authorization_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,22 @@
it { is_expected.not_to be_valid(:submit) }
end
end

describe '#changed_since_authorization?' do
subject { authorization_request.changed_since_authorization? }

let(:authorization_request) { create(:authorization_request, :api_entreprise, :validated) }

context 'when data has not changed' do
it { is_expected.to be false }
end

context 'when data has changed' do
before do
authorization_request.data['intitule'] = 'Meilleur titre'
end

it { is_expected.to be true }
end
end
end

0 comments on commit 11fde5e

Please sign in to comment.