From fc6cd7114f4a927abac934a8b9c1c9095bcb6bc8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Thu, 3 Feb 2022 14:42:36 +0100
Subject: [PATCH] handle errors in teacher programs

---
 app/models/university/person/involvement.rb      | 1 +
 app/views/admin/education/teachers/edit.html.erb | 2 ++
 app/views/admin/education/teachers/show.html.erb | 2 +-
 config/locales/education/en.yml                  | 4 ++++
 config/locales/education/fr.yml                  | 1 +
 config/locales/university/en.yml                 | 3 +++
 config/locales/university/fr.yml                 | 3 +++
 7 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/app/models/university/person/involvement.rb b/app/models/university/person/involvement.rb
index 457e15f30..8cc875a66 100644
--- a/app/models/university/person/involvement.rb
+++ b/app/models/university/person/involvement.rb
@@ -34,6 +34,7 @@ class University::Person::Involvement < ApplicationRecord
   belongs_to :target, polymorphic: true
 
   validates :person_id, uniqueness: { scope: [:target_id, :target_type] }
+  validates :target_id, uniqueness: { scope: [:person_id, :target_type] }
 
   before_validation :set_kind, on: :create
   before_validation :set_university_id, on: :create
diff --git a/app/views/admin/education/teachers/edit.html.erb b/app/views/admin/education/teachers/edit.html.erb
index 397ecd8c8..769b9ea4c 100644
--- a/app/views/admin/education/teachers/edit.html.erb
+++ b/app/views/admin/education/teachers/edit.html.erb
@@ -1,3 +1,5 @@
+<% content_for :title, @teacher %>
+
 <%= simple_form_for [:admin, @teacher], url: admin_education_teacher_path(@teacher) do |f| %>
   <div class="card flex-fill w-100">
     <div class="card-header">
diff --git a/app/views/admin/education/teachers/show.html.erb b/app/views/admin/education/teachers/show.html.erb
index 8b87f0281..6430d8c3d 100644
--- a/app/views/admin/education/teachers/show.html.erb
+++ b/app/views/admin/education/teachers/show.html.erb
@@ -44,5 +44,5 @@
 <% end %>
 
 <% content_for :action_bar_right do %>
-  <%= link_to t('edit'), edit_admin_education_teacher_path(@teacher), class: button_classes if can?(:manage, University::Person::Involvement) %>
+  <%= link_to t('education.manage_programs'), edit_admin_education_teacher_path(@teacher), class: button_classes if can?(:manage, University::Person::Involvement) %>
 <% end %>
diff --git a/config/locales/education/en.yml b/config/locales/education/en.yml
index 9b3b6540c..ae6526354 100644
--- a/config/locales/education/en.yml
+++ b/config/locales/education/en.yml
@@ -50,6 +50,8 @@ en:
         websites: Associated websites
         zipcode: Zipcode
   education:
+    manage_programs: Manage programs
+    manage_roles: Manage roles
     manage_teachers: Manage teachers
     number_of_programs: Number of programs
     program:
@@ -59,6 +61,8 @@ en:
     roles:
       one: Role
       other: Roles
+    schools:
+      manage_roles: Manage the team
     teachers:
       one: Teacher
       other: Teachers
diff --git a/config/locales/education/fr.yml b/config/locales/education/fr.yml
index 8e4f1f77b..132a500f7 100644
--- a/config/locales/education/fr.yml
+++ b/config/locales/education/fr.yml
@@ -50,6 +50,7 @@ fr:
         websites: Sites webs associés
         zipcode: Code postal
   education:
+    manage_programs: Gérer les formations
     manage_roles: Gérer les rôles
     manage_teachers: Gérer les enseignants·es
     number_of_programs: Nombre de formations
diff --git a/config/locales/university/en.yml b/config/locales/university/en.yml
index 7a266ed3c..2a332ee98 100644
--- a/config/locales/university/en.yml
+++ b/config/locales/university/en.yml
@@ -35,6 +35,9 @@ en:
         slug: Slug
         tenure: Have tenure?
         user: User
+      university/person/involvement:
+        person: Person
+        target_id: ''
       university/role:
         description: Description
         people: People
diff --git a/config/locales/university/fr.yml b/config/locales/university/fr.yml
index bee1ae6c4..5bb3fa4fe 100644
--- a/config/locales/university/fr.yml
+++ b/config/locales/university/fr.yml
@@ -35,6 +35,9 @@ fr:
         slug: Slug
         tenure: Titulaire ?
         user: Utilisateur
+      university/person/involvement:
+        person: Personne
+        target_id: ''
       university/role:
         description: Description
         people: Personnes
-- 
GitLab