From 319fb177b040d89dba1c43a3d5d5c10888025914 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Wed, 16 Feb 2022 10:18:26 +0100
Subject: [PATCH] ids, not slugs in json

---
 app/models/communication/website/block.rb                  | 6 +++---
 .../blocks/templates/organization_chart/_edit.html.erb     | 6 +++---
 .../blocks/templates/organization_chart/_show.html.erb     | 2 +-
 .../blocks/templates/organization_chart/_static.html.erb   | 7 +++++--
 4 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/app/models/communication/website/block.rb b/app/models/communication/website/block.rb
index 8a32f1759..abf3e5e6e 100644
--- a/app/models/communication/website/block.rb
+++ b/app/models/communication/website/block.rb
@@ -60,9 +60,9 @@ class Communication::Website::Block < ApplicationRecord
     dependencies = []
     data['elements'].each do |element|
       element['persons'].each do |person|
-        slug = person['slug']
-        next if slug.blank?
-        person = university.people.find_by slug: slug
+        id = person['id']
+        next if id.blank?
+        person = university.people.find id
         next if person.nil?
         dependencies += [person]
         dependencies += person.active_storage_blobs
diff --git a/app/views/admin/communication/website/blocks/templates/organization_chart/_edit.html.erb b/app/views/admin/communication/website/blocks/templates/organization_chart/_edit.html.erb
index 6e715eeb2..a7859c93f 100644
--- a/app/views/admin/communication/website/blocks/templates/organization_chart/_edit.html.erb
+++ b/app/views/admin/communication/website/blocks/templates/organization_chart/_edit.html.erb
@@ -18,15 +18,15 @@
             <p>People</p>
           </div>
           <div class="col-md-4 text-end">
-            <a class="<%= button_classes %>" ng-click="element.persons.push({slug: ''})">Add person</a>
+            <a class="<%= button_classes %>" ng-click="element.persons.push({id: '', role: ''})">Add person</a>
           </div>
         </div>
         <div ng-repeat="person in element.persons" class="mb-2">
           <div class="row">
             <div class="col-md-5">
-              <select class="form-select select" ng-model="person.slug">
+              <select class="form-select select" ng-model="person.id">
                 <% @website.university.people.ordered.each_with_index do |person, index| %>
-                <option value="<%= person.slug %>"><%= person %></option>
+                <option value="<%= person.id %>"><%= person %></option>
                 <% end %>
               </select>
             </div>
diff --git a/app/views/admin/communication/website/blocks/templates/organization_chart/_show.html.erb b/app/views/admin/communication/website/blocks/templates/organization_chart/_show.html.erb
index d099275bf..cdee4815f 100644
--- a/app/views/admin/communication/website/blocks/templates/organization_chart/_show.html.erb
+++ b/app/views/admin/communication/website/blocks/templates/organization_chart/_show.html.erb
@@ -3,7 +3,7 @@
   <div class="row">
     <% element['persons'].each do |person| %>
       <%
-      p = current_university.people.find_by slug: person['slug']
+      p = current_university.people.find person['id']
       next if p.nil?
       %>
       <div class="col-md-3">
diff --git a/app/views/admin/communication/website/blocks/templates/organization_chart/_static.html.erb b/app/views/admin/communication/website/blocks/templates/organization_chart/_static.html.erb
index 3aa0a781d..4829d02c5 100644
--- a/app/views/admin/communication/website/blocks/templates/organization_chart/_static.html.erb
+++ b/app/views/admin/communication/website/blocks/templates/organization_chart/_static.html.erb
@@ -3,8 +3,11 @@
       - title: >
           <%= element['title'] %>
         persons:
-<% element['persons'].each do |person| %>
-          - slug: "<%= person['slug'] %>"
+<%
+element['persons'].each do |person|
+  p = block.university.people.find person['id']
+%>
+          - slug: "<%= p.slug %>"
             role: >
               <%= person['role'] %>
 <% end %>
-- 
GitLab