Skip to content

Commit

Permalink
Merge branch 'main' into feat/dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
pskl committed Sep 16, 2024
2 parents 5321291 + 5a8ccca commit c9e98e0
Show file tree
Hide file tree
Showing 30 changed files with 332 additions and 3,083 deletions.
36 changes: 17 additions & 19 deletions .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,47 @@ APLYPRO_ASP_FTP_PASSWORD=pass
APLYPRO_ASP_FTP_PORT=22
APLYPRO_ASP_FTP_READ_FOLDER=retour
APLYPRO_ASP_FTP_USER=asp
APLYPRO_ASP_MASA_UNITE_SUIVI=asp-masa
APLYPRO_ASP_MENJ_PRIVATE_UNITE_SUIVI=menj-private
APLYPRO_ASP_MENJ_PUBLIC_UNITE_SUIVI=menj-public
APLYPRO_ASP_MER_UNITE_SUIVI=asp-mer
APLYPRO_ASP_OIDC_CLIENT_ID=asp-client-id
APLYPRO_ASP_OIDC_CLIENT_SECRET=asp-client-secret
APLYPRO_ASP_MASA_UNITE_SUIVI=asp masa
APLYPRO_ASP_MENJ_PRIVATE_UNITE_SUIVI=menj private
APLYPRO_ASP_MENJ_PUBLIC_UNITE_SUIVI=menj public
APLYPRO_ASP_MER_UNITE_SUIVI=asp mer
APLYPRO_ASP_OIDC_CLIENT_ID=asp client id
APLYPRO_ASP_OIDC_CLIENT_SECRET=asp client secret
APLYPRO_ASP_OIDC_HOST=localhost:1080
APLYPRO_ASP_OIDC_ISSUER=localhost:3001/realms/aplypro-asp
APLYPRO_ASP_OIDC_REDIRECT_URI=http://localhost:3000/auth/asp/callback
APLYPRO_ASP_OIDC_SCOPE=openid
APLYPRO_ASP_PROGRAM_CODE=asp-program-code
APLYPRO_ASP_SITE_OPERATOR=asp-siteop
APLYPRO_ASP_USER_CODE=asp-user-code
APLYPRO_CAS_CLIENT_ID=aplypro-masa-id
APLYPRO_CAS_CLIENT_SECRET=aplypro-cas-secret
APLYPRO_ASP_PROGRAM_CODE=asp program code
APLYPRO_ASP_SITE_OPERATOR=asp siteop
APLYPRO_ASP_USER_CODE=asp user code
APLYPRO_CAS_CLIENT_ID=aplypro masa id
APLYPRO_CAS_CLIENT_SECRET=aplypro cas secret
APLYPRO_CAS_REDIRECT_URI=nope
APLYPRO_CAS_SITE_ROOT=nope
APLYPRO_DIRECT_SUPPOR_UAIS=0951727L,0680066C,0781069N
APLYPRO_ESTABLISHMENTS_DATA_URL=http://mock:3002/etab-info
APLYPRO_FIM_CLIENT_ID=aplypro-fim-id
APLYPRO_FIM_CLIENT_SECRET=aplypro-fim-secret
APLYPRO_FIM_CLIENT_ID=aplypro fim id
APLYPRO_FIM_CLIENT_SECRET=aplypro fim secret
APLYPRO_FIM_HOST=localhost:1080 # FIXME=keycloak via Docker is a nightmare
APLYPRO_FIM_ISSUER=localhost:3001/realms/aplypro-local
APLYPRO_FIM_REDIRECT_URI=http://localhost:3000/auth/fim/callback
APLYPRO_FIM_SCOPE=openid email profile lescopes
APLYPRO_FREGATA_KEY_ID=aplypro-fregata-key
APLYPRO_FREGATA_SECRET=aplypro-fregata-secret
APLYPRO_FREGATA_URL=http://mock:3002/fregata
APLYPRO_RESTRICTED_ACCESS=
APLYPRO_S3_ACCESS_KEY_ID=s3
APLYPRO_S3_BUCKET=s3
APLYPRO_S3_ENDPOINT=s3
APLYPRO_S3_PAYMENTS_BUCKET=asp s3
APLYPRO_S3_ENDPOINT=s3
APLYPRO_S3_REGION=s3
APLYPRO_S3_SECRET_KEY_ID=s3
APLYPRO_SENTRY_DNS=
APLYPRO_SIDEKIQ_PASSWORD=devpassword
APLYPRO_SIDEKIQ_USER=devteam
APLYPRO_SYGNE_CLIENT_ID=local sygne client id
APLYPRO_SYGNE_SECRET=local sygne secret
APLYPRO_SYGNE_TOKEN_URL=http://mock:3002/sygne/token
APLYPRO_SYGNE_URL=http://mock:3002/sygne/
DATABASE_URL='postgresql://postgres:dummy@db:5433'
APLYPRO_SENTRY_DNS=
APLYPRO_SIDEKIQ_PASSWORD=devpassword
APLYPRO_SIDEKIQ_USER=devteam
REDIS_URL='redis://redis'
RUBY_DEBUG_HOST=0.0.0.0
RUBY_DEBUG_NO_RELINE="true"
Expand Down
35 changes: 34 additions & 1 deletion app/controllers/schoolings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
class SchoolingsController < ApplicationController
include RoleCheck

before_action :set_schooling, only: [:update]
before_action :authenticate_user!, :set_classe, :set_schooling
before_action :check_director, :update_confirmed_director!, :check_confirmed_director, only: %i[abrogate_decision]
before_action :check_director, :update_confirmed_director!, :check_confirmed_director,
only: %i[abrogate_decision update]

def abrogate_decision
GenerateAbrogationDecisionJob.perform_now(@schooling)
Expand All @@ -17,6 +19,27 @@ def abrogate_decision

def confirm_abrogation; end

def confirm_da_extension
add_breadcrumb t("pages.titles.students.show", name: @schooling.student.full_name),
school_year_class_path(selected_school_year, @classe)
infer_page_title(name: t("pages.titles.schoolings.confirm_da_extension"))
end

def update # rubocop:disable Metrics/AbcSize
extended_end_date = schooling_params[:extended_end_date]
if extended_end_date.blank? && any_extended_pfmp?
redirect_to school_year_class_path(selected_school_year, @classe),
alert: t("flash.da.cant_remove_extension", name: @schooling.student.full_name)
elsif @schooling.update(extended_end_date: extended_end_date)
redirect_to school_year_class_path(selected_school_year, @classe),
notice: t(extended_end_date.blank? ? "flash.da.extension_removed" : "flash.da.extended",
name: @schooling.student.full_name)
else
@schooling.extended_end_date = nil
render :confirm_da_extension, status: :unprocessable_entity
end
end

private

def set_schooling
Expand All @@ -25,6 +48,10 @@ def set_schooling
redirect_to @classe, alert: t("errors.schoolings.not_found")
end

def schooling_params
params.require(:schooling).permit(:extended_end_date)
end

def set_classe
@classe = Classe
.where(establishment: current_establishment)
Expand All @@ -40,4 +67,10 @@ def retry_eligibile_payment_requests!
payment_request.mark_ready! if payment_request&.eligible_for_auto_retry?
end
end

def any_extended_pfmp?
@schooling.pfmps.any? do |pfmp|
pfmp.end_date > @schooling.end_date
end
end
end
2 changes: 1 addition & 1 deletion app/models/application_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ApplicationRecord < ActiveRecord::Base
class << self
attr_accessor :updatable_attributes

def updatable(*args)
def sourced_from_external_api(*args)
self.updatable_attributes ||= []

self.updatable_attributes += args
Expand Down
5 changes: 3 additions & 2 deletions app/models/establishment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ def accepted_type?(type)

# NOTE: this method could fetch the actual data per academie if we stored that information
# this was implemented as a hotfix for La Réunion and Mayotte
def school_year_range(year = SchoolYear.current.start_year)
def school_year_range(year = SchoolYear.current.start_year, extended_end_date = nil)
school_year_range_exceptions = {
"43" => Date.new(year, 8, 23), # Mayotte
"28" => Date.new(year, 8, 16) # La Réunion
}

start_date = school_year_range_exceptions.fetch(academy_code, Date.new(year, 9, 1))
(start_date..start_date >> 12)
end_date = extended_end_date.presence || (start_date >> 12)
(start_date..end_date)
end

def to_s
Expand Down
11 changes: 9 additions & 2 deletions app/models/pfmp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ class Pfmp < ApplicationRecord # rubocop:disable Metrics/ClassLength
validates :end_date,
:start_date,
if: ->(pfmp) { pfmp.schooling.present? },
inclusion: { in: ->(pfmp) { pfmp.schooling.establishment.school_year_range(pfmp.school_year.start_year) } }
inclusion: {
in: lambda { |pfmp|
pfmp.schooling.establishment.school_year_range(
pfmp.school_year.start_year,
pfmp.schooling.extended_end_date
)
}
}

validates :end_date,
comparison: { greater_than_or_equal_to: :start_date },
Expand Down Expand Up @@ -107,7 +114,7 @@ def locked?
def within_schooling_dates?
return true if (schooling.open? && start_date >= schooling.start_date) || schooling.no_dates?

(schooling.start_date..schooling.end_date).cover?(start_date..end_date)
(schooling.start_date..schooling.max_end_date).cover?(start_date..end_date)
end

def paid?
Expand Down
12 changes: 10 additions & 2 deletions app/models/schooling.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Schooling < ApplicationRecord
class Schooling < ApplicationRecord # rubocop:disable Metrics/ClassLength
has_one_attached :attributive_decision
has_one_attached :abrogation_decision

Expand Down Expand Up @@ -35,7 +35,11 @@ class Schooling < ApplicationRecord
comparison: { greater_than_or_equal_to: :start_date },
if: -> { start_date && end_date }

updatable :start_date, :end_date, :status
validates :extended_end_date,
comparison: { greater_than: :end_date },
if: -> { end_date && extended_end_date }

sourced_from_external_api :start_date, :end_date, :status

def generate_administrative_number
return if administrative_number.present?
Expand Down Expand Up @@ -67,6 +71,10 @@ def no_dates?
start_date.blank? && end_date.blank?
end

def max_end_date
extended_end_date || end_date
end

def excluded?
Exclusion.excluded?(establishment.uai, mef.code)
end
Expand Down
14 changes: 7 additions & 7 deletions app/models/student.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ class Student < ApplicationRecord # rubocop:disable Metrics/ClassLength
)
}

updatable :address_line1,
:address_postal_code,
:address_city_insee_code,
:address_country_code,
:birthplace_city_insee_code,
:birthplace_country_insee_code,
:biological_sex
sourced_from_external_api :address_line1,
:address_postal_code,
:address_city_insee_code,
:address_country_code,
:birthplace_city_insee_code,
:birthplace_country_insee_code,
:biological_sex

# NOTE: used in stats for column "Données d'élèves nécessaires présentes"
def self.asp_ready
Expand Down
11 changes: 8 additions & 3 deletions app/views/classes/_students_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@
- if schooling.attributive_decision.present? && !schooling.abrogation_decision.present?
%p= dsfr_badge(status: :success) { "Éditée" }
- if schooling.closed?
%p= dsfr_link_to "Abroger", confirm_abrogation_school_year_class_schooling_path(selected_school_year, @classe, schooling)
= dsfr_link_to "Abroger", confirm_abrogation_school_year_class_schooling_path(selected_school_year, @classe, schooling)
- if schooling.extended_end_date.present?
= dsfr_badge(status: :info) { "Reportée" }
- if schooling.end_date.present?
%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)
- else
- if schooling.abrogation_decision.present?
%p= dsfr_badge(status: :error) { "Abrogée" }
= dsfr_badge(status: :error) { "Abrogée" }
- else
%p= dsfr_badge(status: :error) { "Manquante" }
= dsfr_badge(status: :error) { "Manquante" }
%td
- if student.rib.present?
%p= dsfr_badge(status: :success) { "Saisies" }
Expand Down
23 changes: 23 additions & 0 deletions app/views/ribs/_owner_type.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- student_id = local_assigns.fetch(:student_id)
- field_name = local_assigns.fetch(:field_name)
- current_value = local_assigns.fetch(:current_value)

%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}"}
Les coordonnées bancaires appartiennent à :
.fr-fieldset__element.fr-fieldset__element--inline
.fr-radio-group
%input{id: "radio-inline-1-#{student_id}", type: "radio", value: "personal", name: field_name, checked: current_value == "personal"}
%label.fr-label{for: "radio-inline-1-#{student_id}"}
l'élève
.fr-fieldset__element.fr-fieldset__element--inline
.fr-radio-group
%input{id: "radio-inline-2-#{student_id}", type: "radio", value: "other_person", name: field_name, checked: current_value == "other_person"}
%label.fr-label{for: "radio-inline-2-#{student_id}"}
un représentant légal ou à un tiers
.fr-fieldset__element.fr-fieldset__element--inline
.fr-radio-group
%input{id: "radio-inline-3-#{student_id}", type: "radio", value: "moral_person", name: field_name, checked: current_value == "moral_person"}
%label.fr-label{for: "radio-inline-3-#{student_id}"}
une personne morale
.fr-messages-group{id: "radio-inline-messages-#{student_id}", "aria-live": "assertive"}
10 changes: 5 additions & 5 deletions app/views/ribs/missing.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
%h2.fr-mb-1w= dsfr_link_to rib.student.index_name, student_path(rib.student), title: t("links.students.show", name: rib.student), tabindex: "1", class: 'fr-h3'
= closed_schooling_information_tag(@classe.closed_schooling_of rib.student_id)
= form.hidden_field :student_id

.fr-checkbox-group
= form.check_box :owner_type, {}, "personal", "other_person"
= form.label :owner_type, t("activerecord.attributes.rib.owner_type_personal"), classe: "fr-label"

.fr-col-md-7.fr-col-12
.fr-mb-2w
= form.label :name, "Titulaire du compte", class: "hidden"
Expand All @@ -37,4 +32,9 @@
= form.text_field :bic, class: "fr-input fr-input--code", placeholder: "BIC"
- rib.errors.full_messages_for(:bic).each do |error_message|
%p.fr-error-text= error_message
.fr-grid-row.fr-grid-row--middle.fr-grid-row--gutters
.fr-col-md-12.fr-col-12
.fr-mb-2w
= render partial: 'ribs/owner_type', locals: { student_id: rib.student_id, field_name: "ribs[#{rib.student_id}][owner_type]", current_value: rib.owner_type }

= f.submit "Enregistrer les coordonnées bancaires saisies", class: "fr-btn fr-btn-primary"
37 changes: 37 additions & 0 deletions app/views/schoolings/confirm_da_extension.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.fr-container
.fr-grid-row
.fr-col-md-6.fr-mb-3w
- if @schooling.extended_end_date.present?
= dsfr_alert(type: :warning, title: "Êtes-vous certain(e) de vouloir supprimer le report de cette décision d'attribution ?")
- else
= dsfr_alert(type: :warning, title: "Êtes-vous certain(e) de vouloir reporter cette décision d'attribution ?")

.fr-grid-row
.fr-col-md-6.fr-mb-3w
= form_with model: @schooling, url: school_year_class_schooling_path(selected_school_year, @classe, @schooling), method: :patch, builder: DsfrFormBuilder, data: { turbo: false } do |form|
%ul
%li
Etudiant :
%span= @schooling.student.full_name

%li
Classe :
%span= @schooling.classe.to_long_s

%li
Date de fin initiale :
%span= @schooling.end_date.to_s

.fr-col-md-6
= form.dsfr_date_field :extended_end_date, value: @schooling.extended_end_date, disabled: @schooling.extended_end_date.present?

.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'
- if @schooling.extended_end_date.present?
= form.hidden_field :extended_end_date, value: nil
= form.submit "Supprimer le report", class: 'fr-btn fr-btn--danger fr-btn--secondary'
- else
= form.submit "Confirmer le report", class: 'fr-btn fr-btn--danger fr-btn--secondary'
2 changes: 1 addition & 1 deletion config/initializers/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Aplypro
VERSION = "1.18.1"
VERSION = "1.18.2"
end
11 changes: 10 additions & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ fr:
readonly: Les coordonnées bancaires de %{name} ne peuvent pas être supprimées
da:
abrogated: La décision d'attribution de %{name} a bien été abrogée
extended: La décision d'attribution de %{name} a bien été prolongée
extension_removed: Le report de la décision d'attribution de %{name} a bien été supprimé
cant_remove_extension: Le report de la décision d'attribution de %{name} n'a pas pu être supprimé car celui ci contient une PFMP
extension_failure: La décision d'attribution de %{name} n'a pas pu être modifiée
helpers:
submit:
rib:
Expand Down Expand Up @@ -100,8 +104,9 @@ fr:
adult_without_personal_rib: "Les étudiants majeurs doivent avoir être payés sur leurs propres coordonnées bancaires"
pfmp_amount: "La PFMP associée doit avoir un montant positif"
missing_attributive_decision: "Il manque une décision attributive"
needs_abrogated_attributive_decision: "Les élèves ayant changé de formation, de statut ou d'établissement doivent avoir une abrogation de leur décision d'attribution passée. Ce document peut être généré dans la liste des élèves."
needs_abrogated_attributive_decision: "Les élèves ayant changés de formation, de statut ou d'établissement doivent avoir une abrogation de leur décision d'attribution passée. Ce document peut être généré dans la liste des élèves."
overlaps: "Une autre PFMP existe avec des dates intersectantes de fin et de début. Veuillez supprimer ou modifier l'une des deux."
cannot_extend_attributive_decision_with_pfmps: "Les élèves ayant changé de formation, de statut ou d'établissement doivent avoir une abrogation de leur décision d'attribution passée. Ce document peut être généré dans la liste des élèves."

hints:
rib:
Expand All @@ -111,6 +116,8 @@ fr:
pfmp:
day_count: "Le nombre de jours présent sur l'attestation. Il doit être entier (pas de demi-journées)."
attributes:
schooling:
extended_end_date: "Date de report"
pfmp:
start_date: "Date de début"
end_date: "Date de fin"
Expand Down Expand Up @@ -194,6 +201,8 @@ fr:
index: "Paiements"
classes: "Classes avec PFMPs à valider pour envoi en paiement"
show: Envoyer en paiement les PFMPs de %{name}
schoolings:
confirm_da_extension: "Autoriser un report de décision d'attribution"

global:
sponsor: "Direction\nInterministérielle\ndu Numérique"
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@
end
end

resources :schoolings, only: [] do
resources :schoolings, only: [:update] do
member do
get "confirm_abrogation"
delete "abrogate_decision"
get "confirm_da_extension"
end

resources :pfmps, except: :index do
Expand Down
Loading

0 comments on commit c9e98e0

Please sign in to comment.