From 280e1d9b5bf5f05c5f1a849e6f66f1d25bd85886 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Thu, 23 Dec 2021 10:26:18 +0100
Subject: [PATCH] featured image alt

---
 .../communication/website/home_controller.rb  |  5 ++-
 .../communication/website/pages_controller.rb |  2 +-
 .../communication/website/posts_controller.rb |  7 ++++-
 .../admin/education/programs_controller.rb    |  2 +-
 .../research/journal/volumes_controller.rb    |  5 ++-
 app/models/communication/website/home.rb      |  1 +
 app/models/communication/website/page.rb      |  1 +
 app/models/communication/website/post.rb      |  1 +
 app/models/education/program.rb               | 31 ++++++++++---------
 app/models/research/journal/volume.rb         |  1 +
 .../communication/website/home/edit.html.erb  |  1 +
 .../website/home/jekyll.html.erb              |  1 +
 .../website/pages/_form.html.erb              |  1 +
 .../website/pages/jekyll.html.erb             |  1 +
 .../website/posts/_form.html.erb              |  1 +
 .../website/posts/jekyll.html.erb             |  1 +
 .../admin/education/programs/_form.html.erb   |  1 +
 .../admin/education/programs/jekyll.html.erb  |  1 +
 .../research/journal/volumes/_form.html.erb   |  1 +
 .../research/journal/volumes/jekyll.html.erb  |  3 ++
 config/locales/communication/en.yml           |  3 ++
 config/locales/communication/fr.yml           |  3 ++
 config/locales/education/en.yml               |  1 +
 config/locales/education/fr.yml               |  1 +
 config/locales/research/en.yml                |  1 +
 config/locales/research/fr.yml                |  1 +
 ...085935_add_featured_image_alt_to_models.rb |  9 ++++++
 db/schema.rb                                  |  7 ++++-
 test/fixtures/education/program/members.yml   |  1 -
 29 files changed, 73 insertions(+), 22 deletions(-)
 create mode 100644 db/migrate/20211223085935_add_featured_image_alt_to_models.rb

diff --git a/app/controllers/admin/communication/website/home_controller.rb b/app/controllers/admin/communication/website/home_controller.rb
index 59ce01e0a..abad549c1 100644
--- a/app/controllers/admin/communication/website/home_controller.rb
+++ b/app/controllers/admin/communication/website/home_controller.rb
@@ -24,6 +24,9 @@ class Admin::Communication::Website::HomeController < Admin::Communication::Webs
 
   def home_params
     params.require(:communication_website_home)
-          .permit(:text, :featured_image, :featured_image_delete, :featured_image_infos)
+          .permit(
+            :text, :featured_image, :featured_image_delete,
+            :featured_image_infos, :featured_image_alt
+          )
   end
 end
diff --git a/app/controllers/admin/communication/website/pages_controller.rb b/app/controllers/admin/communication/website/pages_controller.rb
index d996b0be4..013902149 100644
--- a/app/controllers/admin/communication/website/pages_controller.rb
+++ b/app/controllers/admin/communication/website/pages_controller.rb
@@ -85,7 +85,7 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web
     params.require(:communication_website_page)
           .permit(:communication_website_id, :title,
             :description, :text, :about_type, :about_id, :slug, :published,
-            :featured_image, :featured_image_delete, :featured_image_infos,
+            :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt,
             :parent_id, :related_category_id)
           .merge(university_id: current_university.id)
   end
diff --git a/app/controllers/admin/communication/website/posts_controller.rb b/app/controllers/admin/communication/website/posts_controller.rb
index f5bc2541f..8e5e72a86 100644
--- a/app/controllers/admin/communication/website/posts_controller.rb
+++ b/app/controllers/admin/communication/website/posts_controller.rb
@@ -61,7 +61,12 @@ class Admin::Communication::Website::PostsController < Admin::Communication::Web
 
   def post_params
     params.require(:communication_website_post)
-          .permit(:university_id, :website_id, :title, :description, :text, :published, :published_at, :featured_image, :featured_image_delete, :featured_image_infos, :slug, :author_id, :pinned, category_ids: [])
+          .permit(
+            :university_id, :website_id, :title, :description, :text,
+            :published, :published_at, :featured_image, :featured_image_delete,
+            :featured_image_infos, :featured_image_alt, :slug, :pinned,
+            :author_id, category_ids: []
+          )
           .merge(university_id: current_university.id)
   end
 end
diff --git a/app/controllers/admin/education/programs_controller.rb b/app/controllers/admin/education/programs_controller.rb
index 36c0b863a..818067ddf 100644
--- a/app/controllers/admin/education/programs_controller.rb
+++ b/app/controllers/admin/education/programs_controller.rb
@@ -80,7 +80,7 @@ class Admin::Education::ProgramsController < Admin::Education::ApplicationContro
   def program_params
     params.require(:education_program).permit(
       :name, :slug, :level, :capacity, :ects, :continuing, :description, :published,
-      :featured_image, :featured_image_delete, :featured_image_infos,
+      :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt,
       :prerequisites, :objectives, :duration, :registration, :pedagogy,
       :evaluation, :accessibility, :pricing, :contacts, :opportunities, :other,
       :parent_id, school_ids: [], teacher_ids: [],
diff --git a/app/controllers/admin/research/journal/volumes_controller.rb b/app/controllers/admin/research/journal/volumes_controller.rb
index ed2b0699c..5156eced8 100644
--- a/app/controllers/admin/research/journal/volumes_controller.rb
+++ b/app/controllers/admin/research/journal/volumes_controller.rb
@@ -54,7 +54,10 @@ class Admin::Research::Journal::VolumesController < Admin::Research::Journal::Ap
 
   def volume_params
     params.require(:research_journal_volume)
-          .permit(:title, :slug, :number, :cover, :cover_infos, :cover_delete, :keywords, :published_at, :description)
+          .permit(
+            :title, :slug, :number, :keywords, :published_at, :description,
+            :cover, :cover_infos, :cover_delete, :cover_alt
+          )
           .merge(university_id: current_university.id)
   end
 end
diff --git a/app/models/communication/website/home.rb b/app/models/communication/website/home.rb
index 835e6f3cc..e1bca10f9 100644
--- a/app/models/communication/website/home.rb
+++ b/app/models/communication/website/home.rb
@@ -3,6 +3,7 @@
 # Table name: communication_website_homes
 #
 #  id                       :uuid             not null, primary key
+#  featured_image_alt       :string
 #  github_path              :text
 #  created_at               :datetime         not null
 #  updated_at               :datetime         not null
diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb
index 472599c29..cd5041fc4 100644
--- a/app/models/communication/website/page.rb
+++ b/app/models/communication/website/page.rb
@@ -5,6 +5,7 @@
 #  id                       :uuid             not null, primary key
 #  about_type               :string
 #  description              :text
+#  featured_image_alt       :string
 #  github_path              :text
 #  old_text                 :text
 #  path                     :text
diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb
index 5dfedbc68..0267de840 100644
--- a/app/models/communication/website/post.rb
+++ b/app/models/communication/website/post.rb
@@ -4,6 +4,7 @@
 #
 #  id                       :uuid             not null, primary key
 #  description              :text
+#  featured_image_alt       :string
 #  github_path              :text
 #  old_text                 :text
 #  pinned                   :boolean          default(FALSE)
diff --git a/app/models/education/program.rb b/app/models/education/program.rb
index 75f1e2574..115b08d0c 100644
--- a/app/models/education/program.rb
+++ b/app/models/education/program.rb
@@ -2,21 +2,22 @@
 #
 # Table name: education_programs
 #
-#  id            :uuid             not null, primary key
-#  capacity      :integer
-#  continuing    :boolean
-#  description   :text
-#  ects          :integer
-#  level         :integer
-#  name          :string
-#  path          :string
-#  position      :integer          default(0)
-#  published     :boolean          default(FALSE)
-#  slug          :string
-#  created_at    :datetime         not null
-#  updated_at    :datetime         not null
-#  parent_id     :uuid
-#  university_id :uuid             not null
+#  id                 :uuid             not null, primary key
+#  capacity           :integer
+#  continuing         :boolean
+#  description        :text
+#  ects               :integer
+#  featured_image_alt :string
+#  level              :integer
+#  name               :string
+#  path               :string
+#  position           :integer          default(0)
+#  published          :boolean          default(FALSE)
+#  slug               :string
+#  created_at         :datetime         not null
+#  updated_at         :datetime         not null
+#  parent_id          :uuid
+#  university_id      :uuid             not null
 #
 # Indexes
 #
diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb
index f2dc30611..e57f5edac 100644
--- a/app/models/research/journal/volume.rb
+++ b/app/models/research/journal/volume.rb
@@ -3,6 +3,7 @@
 # Table name: research_journal_volumes
 #
 #  id                  :uuid             not null, primary key
+#  cover_alt           :string
 #  description         :text
 #  keywords            :text
 #  number              :integer
diff --git a/app/views/admin/communication/website/home/edit.html.erb b/app/views/admin/communication/website/home/edit.html.erb
index 9677b2abe..03289829b 100644
--- a/app/views/admin/communication/website/home/edit.html.erb
+++ b/app/views/admin/communication/website/home/edit.html.erb
@@ -26,6 +26,7 @@
                         input_html: { accept: '.jpg,.jpeg,.png' },
                         preview: true
              %>
+             <%= f.input :featured_image_alt %>
           </div>
         </div>
       </div>
diff --git a/app/views/admin/communication/website/home/jekyll.html.erb b/app/views/admin/communication/website/home/jekyll.html.erb
index 363a532fa..7910e69ed 100644
--- a/app/views/admin/communication/website/home/jekyll.html.erb
+++ b/app/views/admin/communication/website/home/jekyll.html.erb
@@ -4,6 +4,7 @@ permalink: "/"
 title: ""
 <% if @home.featured_image.attached? %>
 image: "<%= @home.featured_image.blob.id %>"
+image_alt: "<%= @home.featured_image_alt %>"
 <% end %>
 description: >
   <%= prepare_for_github @home.text, @home.university %>
diff --git a/app/views/admin/communication/website/pages/_form.html.erb b/app/views/admin/communication/website/pages/_form.html.erb
index 7c7f0ed26..a750e89d7 100644
--- a/app/views/admin/communication/website/pages/_form.html.erb
+++ b/app/views/admin/communication/website/pages/_form.html.erb
@@ -49,6 +49,7 @@
                       input_html: { accept: '.jpg,.jpeg,.png' },
                       preview: true
            %>
+           <%= f.input :featured_image_alt %>
         </div>
       </div>
     </div>
diff --git a/app/views/admin/communication/website/pages/jekyll.html.erb b/app/views/admin/communication/website/pages/jekyll.html.erb
index 619921c91..55377413e 100644
--- a/app/views/admin/communication/website/pages/jekyll.html.erb
+++ b/app/views/admin/communication/website/pages/jekyll.html.erb
@@ -7,6 +7,7 @@ related_category: "<%= @page.related_category_id %>"
 position: <%= @page.position %>
 <% if @page.best_featured_image.attached? %>
 image: "<%= @page.best_featured_image.blob.id %>"
+image_alt: "<%= @page.featured_image_alt %>"
 <% end %>
 description: >
   <%= prepare_for_github @page.description, @page.university %>
diff --git a/app/views/admin/communication/website/posts/_form.html.erb b/app/views/admin/communication/website/posts/_form.html.erb
index 057fb390d..e2d1226be 100644
--- a/app/views/admin/communication/website/posts/_form.html.erb
+++ b/app/views/admin/communication/website/posts/_form.html.erb
@@ -49,6 +49,7 @@
                       input_html: { accept: '.jpg,.jpeg,.png' },
                       preview: true
            %>
+           <%= f.input :featured_image_alt %>
         </div>
       </div>
     </div>
diff --git a/app/views/admin/communication/website/posts/jekyll.html.erb b/app/views/admin/communication/website/posts/jekyll.html.erb
index 3cab08858..94a08c877 100644
--- a/app/views/admin/communication/website/posts/jekyll.html.erb
+++ b/app/views/admin/communication/website/posts/jekyll.html.erb
@@ -16,6 +16,7 @@ tags:
 <% end %>
 <% if @post.featured_image.attached? %>
 image: "<%= @post.featured_image.blob.id %>"
+image_alt: "<%= @post.featured_image_alt %>"
 <% end %>
 description: >
   <%= prepare_for_github @post.description, @post.university %>
diff --git a/app/views/admin/education/programs/_form.html.erb b/app/views/admin/education/programs/_form.html.erb
index 9c430556d..ab9ea9fba 100644
--- a/app/views/admin/education/programs/_form.html.erb
+++ b/app/views/admin/education/programs/_form.html.erb
@@ -39,6 +39,7 @@
                       input_html: { accept: '.jpg,.jpeg,.png' },
                       preview: true
            %>
+           <%= f.input :featured_image_alt %>
         </div>
       </div>
     </div>
diff --git a/app/views/admin/education/programs/jekyll.html.erb b/app/views/admin/education/programs/jekyll.html.erb
index 9a1484051..d9a369f86 100644
--- a/app/views/admin/education/programs/jekyll.html.erb
+++ b/app/views/admin/education/programs/jekyll.html.erb
@@ -10,6 +10,7 @@ position: <%= @program.position %>
 related_category: "<%= @github_file.website.categories.find_by(program_id: @program.id)&.id %>"
 <% if @program.best_featured_image.attached? %>
 image: "<%= @program.best_featured_image.blob.id %>"
+image_alt: "<%= @program.featured_image_alt %>"
 <% end %>
 <% if @program.teachers.any? %>
 teachers:
diff --git a/app/views/admin/research/journal/volumes/_form.html.erb b/app/views/admin/research/journal/volumes/_form.html.erb
index 2ebadb099..dff3da118 100644
--- a/app/views/admin/research/journal/volumes/_form.html.erb
+++ b/app/views/admin/research/journal/volumes/_form.html.erb
@@ -18,6 +18,7 @@
                       input_html: { accept: '.jpg,.jpeg,.png' },
                       preview: 200,
                       direct_upload: true %>
+          <%= f.input :cover_alt %>
           <%= f.input :description, input_html: { rows: 10 } %>
         </div>
       </div>
diff --git a/app/views/admin/research/journal/volumes/jekyll.html.erb b/app/views/admin/research/journal/volumes/jekyll.html.erb
index 9619bed7f..b7f348279 100644
--- a/app/views/admin/research/journal/volumes/jekyll.html.erb
+++ b/app/views/admin/research/journal/volumes/jekyll.html.erb
@@ -4,7 +4,10 @@ number: <%= @volume.number %>
 issn: "<%= @volume.journal.issn %>"
 keywords: "<%= @volume.keywords %>"
 date: "<%= @volume.published_at %>"
+<% if @volume.cover.attached? %>
 image: "<%= @volume.cover_path %>"
+image_alt: "<%= @volume.cover_alt %>"
+<% end %>
 articles:
 <% @volume.articles.each do |article| %>
 - <%= article.id %>
diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml
index 0fc87e398..8928fa86f 100644
--- a/config/locales/communication/en.yml
+++ b/config/locales/communication/en.yml
@@ -63,6 +63,7 @@ en:
       communication/website/home:
         text: Text
         featured_image: Featured image
+        featured_image_alt: Alt text
       communication/website/imported/category:
         original: Original
       communication/website/imported/medium:
@@ -82,6 +83,7 @@ en:
         children: Children pages
         description: Description (SEO)
         featured_image: Featured image
+        featured_image_alt: Alt text
         parent: Parent page
         published: Published?
         slug: Slug
@@ -94,6 +96,7 @@ en:
         categories: Categories
         description: Description (SEO)
         featured_image: Featured image
+        featured_image_alt: Alt text
         pinned: Pinned?
         published: Published?
         published_at: Publication date
diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml
index 43725064e..57be17030 100644
--- a/config/locales/communication/fr.yml
+++ b/config/locales/communication/fr.yml
@@ -53,6 +53,7 @@ fr:
       communication/website/home:
         text: Texte
         featured_image: Image à la une
+        featured_image_alt: Texte alternatif
       communication/website/imported/category:
         original: Original
       communication/website/imported/medium:
@@ -72,6 +73,7 @@ fr:
         children: Pages enfants
         description: Description (SEO)
         featured_image: Image à la une
+        featured_image_alt: Texte alternatif
         parent: Page parente
         published: Publié ?
         slug: Slug
@@ -84,6 +86,7 @@ fr:
         categories: Catégories
         description: Description (SEO)
         featured_image: Image à la une
+        featured_image_alt: Texte alternatif
         pinned: Mis en avant ?
         published: Publié ?
         published_at: Date de publication
diff --git a/config/locales/education/en.yml b/config/locales/education/en.yml
index 4a8df2002..b5632491f 100644
--- a/config/locales/education/en.yml
+++ b/config/locales/education/en.yml
@@ -21,6 +21,7 @@ en:
         ects: Crédits ECTS
         evaluation: Modalités d’évaluation
         featured_image: Featured image
+        featured_image_alt: Alt text
         level: Level
         name: Name
         objectives: Objectifs
diff --git a/config/locales/education/fr.yml b/config/locales/education/fr.yml
index c29355c5d..87fe2b06b 100644
--- a/config/locales/education/fr.yml
+++ b/config/locales/education/fr.yml
@@ -21,6 +21,7 @@ fr:
         ects: Crédits ECTS
         evaluation: Modalités d’évaluation
         featured_image: Image à la une
+        featured_image_alt: Texte alternatif
         level: Niveau
         name: Nom
         objectives: Objectifs
diff --git a/config/locales/research/en.yml b/config/locales/research/en.yml
index 43651a895..eeb3d4532 100644
--- a/config/locales/research/en.yml
+++ b/config/locales/research/en.yml
@@ -28,6 +28,7 @@ en:
         title: Title
       research/journal/volume:
         cover: Cover
+        featured_image_alt: Alt text
         description: Description
         keywords: Keywords
         number: Number
diff --git a/config/locales/research/fr.yml b/config/locales/research/fr.yml
index 345543bf2..10719c2d3 100644
--- a/config/locales/research/fr.yml
+++ b/config/locales/research/fr.yml
@@ -28,6 +28,7 @@ fr:
         title: Titre
       research/journal/volume:
         cover: Couverture
+        cover_alt: Texte alternatif
         description: Description
         keywords: Mots clés
         number: Numéro
diff --git a/db/migrate/20211223085935_add_featured_image_alt_to_models.rb b/db/migrate/20211223085935_add_featured_image_alt_to_models.rb
new file mode 100644
index 000000000..14262fe63
--- /dev/null
+++ b/db/migrate/20211223085935_add_featured_image_alt_to_models.rb
@@ -0,0 +1,9 @@
+class AddFeaturedImageAltToModels < ActiveRecord::Migration[6.1]
+  def change
+    add_column :communication_website_homes, :featured_image_alt, :string
+    add_column :communication_website_pages, :featured_image_alt, :string
+    add_column :communication_website_posts, :featured_image_alt, :string
+    add_column :education_programs, :featured_image_alt, :string
+    add_column :research_journal_volumes, :cover_alt, :string
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 73760d36b..ba4496448 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 2021_12_20_085352) do
+ActiveRecord::Schema.define(version: 2021_12_23_085935) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "pgcrypto"
@@ -140,6 +140,7 @@ ActiveRecord::Schema.define(version: 2021_12_20_085352) do
     t.datetime "created_at", precision: 6, null: false
     t.datetime "updated_at", precision: 6, null: false
     t.text "github_path"
+    t.string "featured_image_alt"
     t.index ["communication_website_id"], name: "idx_comm_website_homes_on_communication_website_id"
     t.index ["university_id"], name: "index_communication_website_homes_on_university_id"
   end
@@ -301,6 +302,7 @@ ActiveRecord::Schema.define(version: 2021_12_20_085352) do
     t.boolean "published", default: false
     t.text "github_path"
     t.uuid "related_category_id"
+    t.string "featured_image_alt"
     t.index ["about_type", "about_id"], name: "index_communication_website_pages_on_about"
     t.index ["communication_website_id"], name: "index_communication_website_pages_on_communication_website_id"
     t.index ["parent_id"], name: "index_communication_website_pages_on_parent_id"
@@ -322,6 +324,7 @@ ActiveRecord::Schema.define(version: 2021_12_20_085352) do
     t.text "github_path"
     t.uuid "author_id"
     t.boolean "pinned", default: false
+    t.string "featured_image_alt"
     t.index ["author_id"], name: "index_communication_website_posts_on_author_id"
     t.index ["communication_website_id"], name: "index_communication_website_posts_on_communication_website_id"
     t.index ["university_id"], name: "index_communication_website_posts_on_university_id"
@@ -385,6 +388,7 @@ ActiveRecord::Schema.define(version: 2021_12_20_085352) do
     t.string "path"
     t.text "description"
     t.boolean "published", default: false
+    t.string "featured_image_alt"
     t.index ["parent_id"], name: "index_education_programs_on_parent_id"
     t.index ["university_id"], name: "index_education_programs_on_university_id"
   end
@@ -463,6 +467,7 @@ ActiveRecord::Schema.define(version: 2021_12_20_085352) do
     t.text "description"
     t.text "keywords"
     t.string "slug"
+    t.string "cover_alt"
     t.index ["research_journal_id"], name: "index_research_journal_volumes_on_research_journal_id"
     t.index ["university_id"], name: "index_research_journal_volumes_on_university_id"
   end
diff --git a/test/fixtures/education/program/members.yml b/test/fixtures/education/program/members.yml
index d9c701b91..1b1ab21f9 100644
--- a/test/fixtures/education/program/members.yml
+++ b/test/fixtures/education/program/members.yml
@@ -19,7 +19,6 @@
 #  fk_rails_...  (member_id => administration_members.id)
 #  fk_rails_...  (program_id => education_programs.id)
 #
-# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
 
 one:
   role: MyString
-- 
GitLab