Skip to content

Commit

Permalink
Gestion de la sélection d'une académie
Browse files Browse the repository at this point in the history
  • Loading branch information
tnicolas1 committed Feb 14, 2025
1 parent 2594ae5 commit 98ad64f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
12 changes: 12 additions & 0 deletions app/controllers/academic/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module Academic
class UsersController < ApplicationController

before_action :infer_page_title

def select_academy
@academic_user = current_user
end
end
end
12 changes: 10 additions & 2 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,19 @@ def academic

add_auth_breadcrumb(data: { user_id: @academic_user.id }, message: "Successfully parsed academic user")

raise IdentityMappers::Errors::NoLimitedAccessError if @mapper.attributes["AplyproAcademieResp"].nil?
academies = @mapper.aplypro_academies

raise IdentityMappers::Errors::NoLimitedAccessError if academies.empty?

sign_in(:academic_user, @academic_user)

redirect_to academic_home_path
if academies.many?
render action: :select_academy
else
@academic_user.update!(selected_academy: academies.first)

redirect_to academic_home_path, notice: t("auth.success")
end
end

def asp
Expand Down
4 changes: 4 additions & 0 deletions app/models/concerns/identity_mappers/fim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ def responsibility_uais
def aplypro_responsibilities
Array(attributes["AplyproResp"]).compact
end

def aplypro_academies
Array(attributes["AplyproAcademieResp"]).compact
end
end
end
12 changes: 12 additions & 0 deletions app/views/academic/users/select_academy.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.fr-grid-row
.fr-col-md-7
%p
Veuillez sélectionner l'académie que vous désirez piloter dans la liste ci-dessous.

.fr-select-group.fr-col-md-7
= form_with model: @academic_user, builder: DsfrFormBuilder do |form|
.fr-input-group
= form.label :selected_academy, "Académie", class: 'fr-label'
= form.select :selected_academy, @academic_user.establishments.map { |e| [e.academy_code, e.academy_code] }, {}, { class: 'fr-select' }

= form.submit "Continuez avec cette académie", class: 'fr-btn'
7 changes: 7 additions & 0 deletions db/migrate/20250214124041_add_selected_academy_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddSelectedAcademyToUsers < ActiveRecord::Migration[8.0]
def change
add_column :users, :selected_academy, :string
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.

0 comments on commit 98ad64f

Please sign in to comment.