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

Retrait des DA (Partie 2) #1303

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions app/controllers/establishments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class EstablishmentsController < ApplicationController
def create_attributive_decisions
mark_attributive_decision_generation!

GenerateAttributiveDecisionsJob.perform_later(schoolings_for_selected_school_year
Generate::AttributiveDecisionsJob.perform_later(schoolings_for_selected_school_year
.without_attributive_decisions
.to_a)

Expand All @@ -23,7 +23,7 @@ def create_attributive_decisions
def reissue_attributive_decisions
mark_attributive_decision_generation_all!

GenerateAttributiveDecisionsJob.perform_later(schoolings_for_selected_school_year.to_a)
Generate::AttributiveDecisionsJob.perform_later(schoolings_for_selected_school_year.to_a)

redirect_to root_path
end
Expand Down
18 changes: 14 additions & 4 deletions app/controllers/schoolings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,29 @@ class SchoolingsController < ApplicationController
before_action :authenticate_user!, :set_classe, :set_schooling
before_action :check_director, :update_confirmed_director!, :check_confirmed_director,
only: %i[abrogate_decision update]
before_action :set_student_breadcrumbs, only: %i[confirm_removal confirm_removal_cancellation confirm_da_extension]
before_action :set_student_breadcrumbs, only: %i[confirm_removal
confirm_removal_cancellation
confirm_da_extension
confirm_cancellation_decision]

def abrogate_decision
GenerateAbrogationDecisionJob.perform_now(@schooling)
Generate::AbrogationDecisionJob.perform_now(@schooling)

retry_incomplete_payment_request!

redirect_to student_path(@schooling.student),
notice: t("flash.da.abrogated", name: @schooling.student.full_name)
redirect_to student_path(@schooling.student), notice: t("flash.da.abrogated", name: @schooling.student.full_name)
end

def confirm_abrogation; end

def cancellation_decision
Generate::CancellationDecisionJob.perform_now(@schooling)

redirect_to student_path(@schooling.student), notice: t("flash.da.cancellation", name: @schooling.student.full_name)
end

def confirm_cancellation_decision; end

def confirm_da_extension; end

def confirm_removal; end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/classes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def closed_schooling_information_tag(schooling, **args)
if schooling.removed?
content_tag(
:div,
"Retiré(e) manuellement de la classe",
"Masqué(e) manuellement de la classe",
class: "fr-badge fr-badge--sm fr-badge--warning #{args[:class]}"
)
elsif schooling.closed?
Expand Down
41 changes: 41 additions & 0 deletions app/jobs/generate/abrogation_decision_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

require "attribute_decision/attributor"

module Generate
class AbrogationDecisionJob < ApplicationJob
include DocumentGeneration

class MissingAttributiveDecisionError < StandardError
end

class MissingSchoolingEndDateError < StandardError
end

after_discard do |job|
self.class.after_discard_callback(job, :generating_attributive_decision)
end

around_perform do |job, block|
self.class.around_perform_callback(job, :generating_attributive_decision, &block)
end

def perform(schooling)
raise MissingAttributiveDecisionError if schooling.attributive_decision.blank?
raise MissingSchoolingEndDateError if schooling.open?

Schooling.transaction do
generate_document(schooling)
schooling.save!
end
end

private

def generate_document(schooling)
schooling.increment(:abrogation_decision_version)
io = AttributeDecision::Abrogator.new(schooling).write
schooling.attach_attributive_document(io, :abrogation_decision)
end
end
end
36 changes: 36 additions & 0 deletions app/jobs/generate/attributive_decision_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

require "attribute_decision/attributor"

module Generate
class AttributiveDecisionJob < ApplicationJob
include DocumentGeneration
include FregataProof

after_discard do |job|
self.class.after_discard_callback(job, :generating_attributive_decision)
end

around_perform do |job, block|
self.class.around_perform_callback(job, :generating_attributive_decision, &block)
end

def perform(schooling)
Sync::StudentJob.new.perform(schooling)

Schooling.transaction do
generate_document(schooling)
schooling.save!
end
end

private

def generate_document(schooling)
schooling.generate_administrative_number
schooling.increment(:attributive_decision_version)
io = AttributeDecision::Attributor.new(schooling).write
schooling.attach_attributive_document(io, :attributive_decision)
end
end
end
11 changes: 11 additions & 0 deletions app/jobs/generate/attributive_decisions_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Generate
class AttributiveDecisionsJob < ApplicationJob
def perform(schoolings)
jobs = schoolings.map { |schooling| Generate::AttributiveDecisionJob.new(schooling) }

ActiveJob.perform_all_later(jobs)
end
end
end
41 changes: 41 additions & 0 deletions app/jobs/generate/cancellation_decision_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

require "attribute_decision/attributor"

module Generate
class CancellationDecisionJob < ApplicationJob
include DocumentGeneration

class MissingAttributiveDecisionError < StandardError
end

class MissingSchoolingEndDateError < StandardError
end

after_discard do |job|
self.class.after_discard_callback(job, :generating_attributive_decision)
end

around_perform do |job, block|
self.class.around_perform_callback(job, :generating_attributive_decision, &block)
end

def perform(schooling)
raise MissingAttributiveDecisionError if schooling.attributive_decision.blank?
raise MissingSchoolingEndDateError if schooling.open?

Schooling.transaction do
generate_document(schooling)
schooling.save!
end
end

private

def generate_document(schooling)
# schooling.increment(:abrogation_decision_version)
io = AttributeDecision::Cancellation.new(schooling).write
schooling.attach_attributive_document(io, :cancellation_decision)
end
end
end
39 changes: 0 additions & 39 deletions app/jobs/generate_abrogation_decision_job.rb

This file was deleted.

34 changes: 0 additions & 34 deletions app/jobs/generate_attributive_decision_job.rb

This file was deleted.

9 changes: 0 additions & 9 deletions app/jobs/generate_attributive_decisions_job.rb

This file was deleted.

14 changes: 11 additions & 3 deletions app/models/schooling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class Schooling < ApplicationRecord # rubocop:disable Metrics/ClassLength
has_one_attached :attributive_decision
has_one_attached :abrogation_decision
has_one_attached :cancellation_decision

enum :status, { student: 0, apprentice: 1, other: 2 }, scopes: false, validate: { allow_nil: true }

Expand Down Expand Up @@ -146,10 +147,17 @@ def attributive_decision_bop_indicator
end

def attach_attributive_document(output, attachment_name)
raise "Unsupported attachment type" unless %i[attributive_decision abrogation_decision].include?(attachment_name)
unless %i[attributive_decision abrogation_decision cancellation_decision].include?(attachment_name)
raise "Unsupported attachment type"
end

descriptions = {
attributive_decision: "décision-d-attribution",
abrogation_decision: "décision-d-abrogation",
cancellation_decision: "décision-de-retrait"
}

description = attachment_name == :attributive_decision ? "décision-d-attribution" : "décision-d-abrogation"
name = attachment_file_name(description)
name = attachment_file_name(descriptions[attachment_name])

attachment = public_send(attachment_name)
attachment.purge if attachment.present?
Expand Down
2 changes: 1 addition & 1 deletion app/views/classes/_students_removed_table.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

.fr-table.fr-table--no-caption
%table
%caption= "Élèves retirés manuellement de la classe"
%caption= "Élèves masqués manuellement de la classe"
%thead
%th{scope: "col"}
Élèves
Expand Down
4 changes: 1 addition & 3 deletions app/views/classes/_students_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
%p
= dsfr_link_to (schooling.extended_end_date.present? ? "Annuler le report" : "Autoriser un report"), confirm_da_extension_school_year_class_schooling_path(selected_school_year, @classe, schooling)
- if schooling.extended_end_date.blank?
%button.fr-btn--tooltip.fr-btn{"aria-describedby" => "tooltip-da_extension-#{student.id}", type: "button"}
%span.fr-tooltip.fr-placement{id: "tooltip-da_extension-#{student.id}", role: "tooltip", "aria-hidden" => "true"}
%em= t("activerecord.tooltips.report")
= render partial: "shared/tooltip", locals: { message: "report", id: "#{student.id}" }
- else
- if schooling.abrogation_decision.present?
= dsfr_badge(status: :error) { "Abrogée" }
Expand Down
2 changes: 1 addition & 1 deletion app/views/classes/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
= render partial: "students_table", locals: { schoolings: @classe_facade.schoolings.former, caption: "Élèves sortis de la classe" }

- if @classe.removed_students.any?
%h2 Élèves retirés manuellement de la classe
%h2 Élèves masqués manuellement de la classe
= render partial: "students_removed_table", locals: { schoolings: @classe_facade.schoolings.with_removed_students }
5 changes: 4 additions & 1 deletion app/views/pfmps/_pfmp_student_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
= button_to "Ajouter une PFMP", new_school_year_class_schooling_pfmp_path(school_year, classe, schooling), class: 'fr-btn', method: :get
- if schooling.attributive_decision.attached?
= button_to "Télécharger la décision d'attribution", url_for(schooling.attributive_decision), class: 'fr-btn fr-btn--secondary', target: :download, method: :get
= button_to "Retirer la décision d'attribution", confirm_cancellation_decision_school_year_class_schooling_path(school_year, classe, schooling), class: 'fr-btn fr-btn--danger', method: :get
= render partial: "shared/tooltip", locals: { message: "cancellation_decision" }
- if schooling.abrogation_decision.attached?
= button_to "Télécharger la décision d'abrogation", url_for(schooling.abrogation_decision), class: 'fr-btn fr-btn--secondary', target: :download, method: :get
- if [email protected]_schooling.nil? && @student.current_schooling.eql?(schooling) && !schooling.removed?
= button_to "Retirer l'élève de la classe", confirm_removal_school_year_class_schooling_path(school_year, classe, schooling), class: 'fr-btn fr-btn--danger', method: :get
= button_to "Masquer l'élève de la classe", confirm_removal_school_year_class_schooling_path(school_year, classe, schooling), class: 'fr-btn fr-btn--danger', method: :get
= render partial: "shared/tooltip", locals: { message: "remove_student" }
5 changes: 1 addition & 4 deletions app/views/ribs/owner_type/_owner_type_horizontal.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
%fieldset.fr-fieldset{id: "radio-inline-#{student_id}", "aria-labelledby": "radio-inline-legend-#{student_id} radio-inline-messages-#{student_id}"}
%legend.fr-fieldset__legend--regular.fr-fieldset__legend{id: "radio-inline-legend-#{student_id}"}
= t("activerecord.attributes.missing.owner_type")
%button.fr-btn--tooltip.fr-btn{"aria-describedby" => "tooltip-owner_type-#{student_id}", type: "button"}
%span.fr-tooltip.fr-placement{id: "tooltip-owner_type-#{student_id}", role: "tooltip", "aria-hidden" => "true"}
%em= t("activerecord.tooltips.rib")
%strong= t("activerecord.attributes.missing.owner_type_mandate")
= render partial: "shared/tooltip", locals: { message: "owner_type", id: "#{student_id}" }

.fr-fieldset__element.fr-fieldset__element--inline
.fr-radio-group
Expand Down
6 changes: 1 addition & 5 deletions app/views/ribs/owner_type/_owner_type_vertical.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
%fieldset.fr-fieldset.fr-input-group{id: "radio", "aria-labelledby": "radio-legend radio-messages"}
%legend.fr-fieldset__legend--regular.fr-fieldset__legend{id: "radio-legend"}
= t("activerecord.attributes.missing.owner_type")

%button.fr-btn--tooltip.fr-btn{"aria-describedby" => "tooltip-owner_type", type: "button"}
%span.fr-tooltip.fr-placement{id: "tooltip-owner_type", role: "tooltip", "aria-hidden" => "true"}
%em= t("activerecord.tooltips.rib")
%strong= t("activerecord.attributes.missing.owner_type_mandate")
= render partial: "shared/tooltip", locals: { message: "owner_type" }

.fr-fieldset__element
.fr-radio-group
Expand Down
23 changes: 23 additions & 0 deletions app/views/schoolings/confirm_cancellation_decision.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.fr-col-md-6
= dsfr_alert(type: :warning, title: "Êtes-vous certain(e) de vouloir retirer cette décision d'attribution ?")

.fr-col-md-6.fr-mt-3w
= form_with url: cancellation_decision_school_year_class_schooling_path(selected_school_year, @classe, @schooling), method: :delete do |form|
%ul
%li
Etudiant :
%span= @schooling.student.full_name

%li
Classe :
%span= @schooling.classe.to_long_s
%li
Fin de scolarité :
%span= @schooling.end_date.to_s

.fr-col-md-6.fr-mt-3w
= render partial: "shared/confirmed_director", locals: { message: t("panels.attributive_decisions.confirm_director") }

.fr-btns-group.fr-btns-group--inline.fr-mt-3w
= link_to "Annuler", school_year_class_path(selected_school_year, @classe), class: 'fr-btn fr-btn--secondary'
= form.submit "Confirmer le retrait", class: 'fr-btn fr-btn--danger fr-btn--secondary'
Loading
Loading