From 08a6e7fbd711fa3c94a172851ab430b189610f8e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Thu, 9 Feb 2023 14:46:56 +0100
Subject: [PATCH] feedback

---
 .../education/programs/roles_controller.rb     |  6 +++++-
 .../people/translations_controller.rb          | 18 ------------------
 .../admin/university/people_controller.rb      |  6 ++++++
 .../website/with_program_categories.rb         |  1 +
 .../admin/application/i18n/_widget.html.erb    |  2 +-
 config/routes/admin/university.rb              |  2 +-
 6 files changed, 14 insertions(+), 21 deletions(-)
 delete mode 100644 app/controllers/admin/university/people/translations_controller.rb

diff --git a/app/controllers/admin/education/programs/roles_controller.rb b/app/controllers/admin/education/programs/roles_controller.rb
index ea509c432..fa6a9d122 100644
--- a/app/controllers/admin/education/programs/roles_controller.rb
+++ b/app/controllers/admin/education/programs/roles_controller.rb
@@ -70,6 +70,10 @@ class Admin::Education::Programs::RolesController < Admin::Education::Programs::
   end
 
   def load_administration_people
-    @administration_people = current_university.people.for_language_id(current_university.default_language_id).administration.accessible_by(current_ability).ordered
+    @administration_people =  current_university.people
+                                                .for_language_id(current_university.default_language_id)
+                                                .administration
+                                                .accessible_by(current_ability)
+                                                .ordered
   end
 end
diff --git a/app/controllers/admin/university/people/translations_controller.rb b/app/controllers/admin/university/people/translations_controller.rb
deleted file mode 100644
index c400e9027..000000000
--- a/app/controllers/admin/university/people/translations_controller.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-class Admin::University::People::TranslationsController < Admin::University::ApplicationController
-  load_and_authorize_resource :person,
-                              class: University::Person,
-                              id_param: :person_id,
-                              through: :current_university,
-                              through_association: :people,
-                              parent: false
-
-  def show
-    language = Language.find_by!(iso_code: params[:lang])
-    # Early return if language is correct
-    return [:admin, @person] if @person.language_id == language.id
-    # Look up for translation or translate (with blocks and all) from person
-    translation = @person.find_or_translate!(language)
-    # Redirect to the translation
-    redirect_to [:admin, translation.becomes(translation.class.base_class)]
-  end
-end
diff --git a/app/controllers/admin/university/people_controller.rb b/app/controllers/admin/university/people_controller.rb
index 8b9fbd1ff..3f1bd1958 100644
--- a/app/controllers/admin/university/people_controller.rb
+++ b/app/controllers/admin/university/people_controller.rb
@@ -18,6 +18,12 @@ class Admin::University::PeopleController < Admin::University::ApplicationContro
     breadcrumb
   end
 
+  def in_language
+    language = Language.find_by!(iso_code: params[:lang])
+    translation = @person.find_or_translate!(language)
+    redirect_to [:admin, translation.becomes(translation.class.base_class)]
+  end
+
   def static
     @about = @person
     @website = @person.websites&.first
diff --git a/app/models/communication/website/with_program_categories.rb b/app/models/communication/website/with_program_categories.rb
index 2c56713fc..a2f9bd468 100644
--- a/app/models/communication/website/with_program_categories.rb
+++ b/app/models/communication/website/with_program_categories.rb
@@ -6,6 +6,7 @@ module Communication::Website::WithProgramCategories
   end
 
   # TODO : I18n
+  # Actuellement, on ne crée que dans la langue par défaut du website, on ne gère pas les autres langues
   def set_programs_categories!
     programs_root_category = categories.for_language_id(default_language_id).where(is_programs_root: true).first_or_create(
       name: 'Offre de formation',
diff --git a/app/views/admin/application/i18n/_widget.html.erb b/app/views/admin/application/i18n/_widget.html.erb
index 9b646599f..716cb26bd 100644
--- a/app/views/admin/application/i18n/_widget.html.erb
+++ b/app/views/admin/application/i18n/_widget.html.erb
@@ -1,7 +1,7 @@
 <% if about.available_languages.many? %>
   <%
     route_args = about.respond_to?(:website)  ? [:admin, about.becomes(about.class.base_class)]
-                                              : [:admin, about.becomes(about.class.base_class), :translation]
+                                              : [:show_in_language, :admin, about.becomes(about.class.base_class)]
   %>
   <%= osuny_panel t('internationalization.label') do %>
     <ol class="list-unstyled">
diff --git a/config/routes/admin/university.rb b/config/routes/admin/university.rb
index 8f397cc6f..5da1efdf4 100644
--- a/config/routes/admin/university.rb
+++ b/config/routes/admin/university.rb
@@ -20,9 +20,9 @@ namespace :university do
     end
   end
   resources :people do
-    resources :translations, only: :show, param: :lang, controller: "people/translations"
     member do
       get :static
+      get "/translations/:lang" => "people#in_language", as: :show_in_language
     end
   end
   resources :organizations do
-- 
GitLab