From 0e35404073dee977f5f91a83eaa50179863a979f Mon Sep 17 00:00:00 2001 From: pabois <pierreandre.boissinot@noesya.coop> Date: Mon, 9 Oct 2023 18:40:24 +0200 Subject: [PATCH] factorize default images formats --- app/controllers/media_controller.rb | 2 +- app/helpers/application_helper.rb | 4 ++++ app/services/importers/hash_to_person.rb | 2 +- app/views/admin/application/featured_image/_edit.html.erb | 4 ++-- .../communication/blocks/components/image/_edit.html.erb | 4 ++-- .../blocks/templates/image/_snippet.html.erb | 8 ++------ .../blocks/templates/persons/_snippet.html.erb | 2 +- app/views/admin/communication/extranets/_form.html.erb | 3 ++- .../communication/websites/agenda/events/_list.html.erb | 2 +- app/views/admin/education/schools/_form.html.erb | 2 +- app/views/admin/layouts/themes/appstack/_top.html.erb | 2 +- app/views/admin/layouts/themes/pure/_nav.html.erb | 2 +- app/views/admin/layouts/themes/pure/_panel.html.erb | 2 +- app/views/admin/university/organizations/_form.html.erb | 4 ++-- app/views/admin/university/people/_form.html.erb | 2 +- app/views/admin/users/_form.html.erb | 2 +- app/views/devise/registrations/edit.html.erb | 2 +- app/views/devise/registrations/new.html.erb | 2 +- app/views/extranet/account/edit.html.erb | 2 +- app/views/extranet/organizations/_form.html.erb | 4 ++-- app/views/server/application/_top.html.erb | 2 +- app/views/server/universities/_form.html.erb | 2 +- config/application.rb | 1 + config/locales/communication/contents/en.yml | 2 -- config/locales/communication/contents/fr.yml | 2 -- config/locales/communication/en.yml | 5 +++-- config/locales/communication/fr.yml | 5 +++-- config/locales/en.yml | 1 + config/locales/fr.yml | 1 + config/locales/research/en.yml | 2 -- config/locales/research/fr.yml | 2 -- 31 files changed, 40 insertions(+), 42 deletions(-) diff --git a/app/controllers/media_controller.rb b/app/controllers/media_controller.rb index 6b2de06f3..0065ebbb8 100644 --- a/app/controllers/media_controller.rb +++ b/app/controllers/media_controller.rb @@ -5,7 +5,7 @@ class MediaController < ApplicationController def show @size = @blob.byte_size - if @blob.representable? + if @blob.variable? variant_service = VariantService.compute(@blob, params[:filename_with_transformations], params[:format]) transformations = variant_service.transformations if transformations.empty? diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0acd1311e..0f7bd9455 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -61,4 +61,8 @@ module ApplicationHelper I18nData.languages(I18n.locale)[iso_code.to_s.upcase].titleize end + def default_images_formats_accepted + Rails.application.config.default_images_formats.join(', ') + end + end diff --git a/app/services/importers/hash_to_person.rb b/app/services/importers/hash_to_person.rb index 2b110e241..273b9394d 100644 --- a/app/services/importers/hash_to_person.rb +++ b/app/services/importers/hash_to_person.rb @@ -101,7 +101,7 @@ module Importers def add_picture_if_possible!(person) return if @photo.nil? return if @person.picture.attached? - return unless @photo.end_with?('.jpg') || @photo.end_with?('.png') || @photo.end_with?('.svg') + return unless @photo.end_with?(*Rails.application.config.default_images_formats) begin file = URI.open @photo filename = File.basename @photo diff --git a/app/views/admin/application/featured_image/_edit.html.erb b/app/views/admin/application/featured_image/_edit.html.erb index 775b15954..2abb7b21d 100644 --- a/app/views/admin/application/featured_image/_edit.html.erb +++ b/app/views/admin/application/featured_image/_edit.html.erb @@ -3,8 +3,8 @@ as: :single_deletable_file, direct_upload: true, label: false, - hint: '5 Mo max, .jpg, .jpeg, .png, .svg', - input_html: { accept: '.jpg,.jpeg,.png,.svg' }, + hint: t('default_images_hint', formats: default_images_formats_accepted), + input_html: { accept: default_images_formats_accepted }, preview: true, resize: true %> <%= f.input :featured_image_alt, diff --git a/app/views/admin/communication/blocks/components/image/_edit.html.erb b/app/views/admin/communication/blocks/components/image/_edit.html.erb index d82dbabc8..1aa10f55f 100644 --- a/app/views/admin/communication/blocks/components/image/_edit.html.erb +++ b/app/views/admin/communication/blocks/components/image/_edit.html.erb @@ -1,7 +1,7 @@ <% label = t('admin.communication.blocks.components.image.input.label') remove = t('admin.communication.blocks.components.image.input.remove') -hint = t('admin.communication.blocks.components.image.input.hint') +hint = t('default_images_hint', formats: default_images_formats_accepted) %> <div class="mb-3"> <div v-if="!<%= model %>.<%= property %>.id"> @@ -11,7 +11,7 @@ hint = t('admin.communication.blocks.components.image.input.hint') </label> <input class="form-control" type="file" - accept="image/*" + accept="<%= default_images_formats_accepted %>" @change="onFileImageChange( $event, <%= model %>, '<%= property %>' )" data-size-limit="<%= Communication::Block::IMAGE_MAX_SIZE %>" :id="<%= dom_id.html_safe %>" diff --git a/app/views/admin/communication/blocks/templates/image/_snippet.html.erb b/app/views/admin/communication/blocks/templates/image/_snippet.html.erb index 98620f020..61ce1e43f 100644 --- a/app/views/admin/communication/blocks/templates/image/_snippet.html.erb +++ b/app/views/admin/communication/blocks/templates/image/_snippet.html.erb @@ -1,6 +1,2 @@ -<% -blob = block.template.image_component.blob -object = blob&.representable? ? blob.representation(resize: 'x180') - : blob -%> -<%= kamifusen_tag object, height: 90, alt: '', class: 'me-2' if object %> +<% blob = block.template.image_component.blob %> +<%= kamifusen_tag blob, height: 90, alt: '', class: 'me-2' if blob %> diff --git a/app/views/admin/communication/blocks/templates/persons/_snippet.html.erb b/app/views/admin/communication/blocks/templates/persons/_snippet.html.erb index 29ecbaa17..3e0c82046 100644 --- a/app/views/admin/communication/blocks/templates/persons/_snippet.html.erb +++ b/app/views/admin/communication/blocks/templates/persons/_snippet.html.erb @@ -4,7 +4,7 @@ %> <span class="me-2"> <% if person.best_picture.attached? %> - <%= kamifusen_tag person.best_picture, width: 90, class: 'img-fluid rounded-circle' %> + <%= kamifusen_tag person.best_picture, width: 90, height: 90, class: 'img-fluid rounded-circle' %> <% else %> <%= element.person %> <% end %> diff --git a/app/views/admin/communication/extranets/_form.html.erb b/app/views/admin/communication/extranets/_form.html.erb index 5d1895677..a21c722cf 100644 --- a/app/views/admin/communication/extranets/_form.html.erb +++ b/app/views/admin/communication/extranets/_form.html.erb @@ -15,7 +15,8 @@ <%= osuny_panel t('look_feel') do %> <%= f.input :logo, as: :single_deletable_file, - input_html: { accept: '.jpg,.jpeg,.png,.svg' }, + hint: t('default_images_hint', formats: default_images_formats_accepted), + input_html: { accept: default_images_formats_accepted }, preview: 200, direct_upload: true %> <%= f.input :favicon, diff --git a/app/views/admin/communication/websites/agenda/events/_list.html.erb b/app/views/admin/communication/websites/agenda/events/_list.html.erb index 055cea7a9..98cdcba21 100644 --- a/app/views/admin/communication/websites/agenda/events/_list.html.erb +++ b/app/views/admin/communication/websites/agenda/events/_list.html.erb @@ -20,7 +20,7 @@ </td> <td class="small"><%= render 'admin/communication/websites/agenda/events/dates', event: event %></td> <td> - <%= kamifusen_tag event.featured_image, width: 200 if event.featured_image.attached? %> + <%= kamifusen_tag event.featured_image, width: 100 if event.featured_image.attached? %> </td> </tr> <% end %> diff --git a/app/views/admin/education/schools/_form.html.erb b/app/views/admin/education/schools/_form.html.erb index 90e3d4368..1ec5198c7 100644 --- a/app/views/admin/education/schools/_form.html.erb +++ b/app/views/admin/education/schools/_form.html.erb @@ -20,7 +20,7 @@ <%= f.input :url %> <%= f.input :logo, as: :single_deletable_file, - input_html: { accept: '.jpg,.jpeg,.png,.svg' }, + input_html: { accept: default_images_formats_accepted }, preview: 200, direct_upload: true %> <% end %> diff --git a/app/views/admin/layouts/themes/appstack/_top.html.erb b/app/views/admin/layouts/themes/appstack/_top.html.erb index 075348819..7b6697277 100644 --- a/app/views/admin/layouts/themes/appstack/_top.html.erb +++ b/app/views/admin/layouts/themes/appstack/_top.html.erb @@ -22,7 +22,7 @@ <li> <a class="nav-link nav-link--last js-user-button" href="#"> <% if current_user.picture.attached? %> - <%= kamifusen_tag current_user.picture, width: 40, class: 'avatar img-fluid rounded-circle' %> + <%= kamifusen_tag current_user.picture, width: 40, height: 40, class: 'avatar img-fluid rounded-circle' %> <% else %> <%= image_tag 'avatar.jpg', class: 'avatar img-fluid rounded-circle' %> <% end %> diff --git a/app/views/admin/layouts/themes/pure/_nav.html.erb b/app/views/admin/layouts/themes/pure/_nav.html.erb index 0e2edd453..5b150ade5 100644 --- a/app/views/admin/layouts/themes/pure/_nav.html.erb +++ b/app/views/admin/layouts/themes/pure/_nav.html.erb @@ -45,7 +45,7 @@ context ||= :admin <div class="col-sm-6 col-md-4 col-lg-3"> <%= link_to admin_user_path(current_user) do %> <% if current_user.picture.attached? %> - <%= kamifusen_tag current_user.picture, width: 100, class: 'image' %> + <%= kamifusen_tag current_user.picture, width: 100, height: 100, class: 'image' %> <% else %> <%= image_tag 'avatar.jpg', class: 'image', loading: :lazy %> <% end %> diff --git a/app/views/admin/layouts/themes/pure/_panel.html.erb b/app/views/admin/layouts/themes/pure/_panel.html.erb index a0b5ce45b..46f1b8834 100644 --- a/app/views/admin/layouts/themes/pure/_panel.html.erb +++ b/app/views/admin/layouts/themes/pure/_panel.html.erb @@ -1,5 +1,5 @@ <section class="pure__section flex-fill position-relative <%= classes %>"> - <%= kamifusen_tag image, class: 'img-fluid mb-3', loading: :lazy if image %> + <%= image_tag image, class: 'img-fluid mb-3', loading: :lazy if image %> <div class="d-lg-flex me-4 <%= 'mb-3' if small %>"> <% if title %> <% if small %> diff --git a/app/views/admin/university/organizations/_form.html.erb b/app/views/admin/university/organizations/_form.html.erb index 5119d876f..290735503 100644 --- a/app/views/admin/university/organizations/_form.html.erb +++ b/app/views/admin/university/organizations/_form.html.erb @@ -91,13 +91,13 @@ <%= osuny_panel University::Organization.human_attribute_name('logos') do %> <%= f.input :logo, as: :single_deletable_file, - input_html: { accept: '.jpg,.jpeg,.png,.svg' }, + input_html: { accept: default_images_formats_accepted }, preview: 200, resize: false, direct_upload: true %> <%= f.input :logo_on_dark_background, as: :single_deletable_file, - input_html: { accept: '.jpg,.jpeg,.png,.svg' }, + input_html: { accept: default_images_formats_accepted }, preview: 200, resize: false, direct_upload: true %> diff --git a/app/views/admin/university/people/_form.html.erb b/app/views/admin/university/people/_form.html.erb index 1beeef56c..157cb8266 100644 --- a/app/views/admin/university/people/_form.html.erb +++ b/app/views/admin/university/people/_form.html.erb @@ -114,7 +114,7 @@ <%= f.input :picture, as: :single_deletable_file, label: false, - input_html: { accept: '.jpg,.jpeg,.png,.svg' }, + input_html: { accept: default_images_formats_accepted }, preview: 200, resize: 1, direct_upload: true %> diff --git a/app/views/admin/users/_form.html.erb b/app/views/admin/users/_form.html.erb index ca83eefc3..e00b89b2e 100644 --- a/app/views/admin/users/_form.html.erb +++ b/app/views/admin/users/_form.html.erb @@ -45,7 +45,7 @@ <div class="col-md-4"> <%= f.input :picture, as: :single_deletable_file, - input_html: { accept: '.jpg,.jpeg,.png,.svg' }, + input_html: { accept: default_images_formats_accepted }, preview: 200, resize: 1, direct_upload: true %> diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index b4142762e..0120f5a8e 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -36,7 +36,7 @@ <%= f.input :mobile_phone %> <%= f.input :picture, as: :single_deletable_file, - input_html: { accept: '.jpg,.jpeg,.png,.svg' }, + input_html: { accept: default_images_formats_accepted }, preview: 200, resize: 1, direct_upload: true %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index ac997c416..e0840a6cb 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -45,7 +45,7 @@ <%= f.input :mobile_phone %> <%= f.input :picture, as: :single_deletable_file, - input_html: { accept: '.jpg,.jpeg,.png,.svg' }, + input_html: { accept: default_images_formats_accepted }, preview: 200, resize: 1, direct_upload: true %> diff --git a/app/views/extranet/account/edit.html.erb b/app/views/extranet/account/edit.html.erb index 1bec66f13..68ea4442d 100644 --- a/app/views/extranet/account/edit.html.erb +++ b/app/views/extranet/account/edit.html.erb @@ -14,7 +14,7 @@ label_method: lambda { |l| t("languages.#{l.iso_code.to_s}") } %> <%= f.input :picture, as: :single_deletable_file, - input_html: { accept: '.jpg,.jpeg,.png,.svg' }, + input_html: { accept: default_images_formats_accepted }, preview: 200, resize: 1, direct_upload: true %> diff --git a/app/views/extranet/organizations/_form.html.erb b/app/views/extranet/organizations/_form.html.erb index 21d1904fc..3dee125b4 100644 --- a/app/views/extranet/organizations/_form.html.erb +++ b/app/views/extranet/organizations/_form.html.erb @@ -75,13 +75,13 @@ <h2><%= University::Organization.human_attribute_name('logos') %></h2> <%= f.input :logo, as: :single_deletable_file, - input_html: { accept: '.jpg,.jpeg,.png,.svg' }, + input_html: { accept: default_images_formats_accepted }, preview: 200, resize: false, direct_upload: true %> <%= f.input :logo_on_dark_background, as: :single_deletable_file, - input_html: { accept: '.jpg,.jpeg,.png,.svg' }, + input_html: { accept: default_images_formats_accepted }, preview: 200, resize: false, direct_upload: true %> diff --git a/app/views/server/application/_top.html.erb b/app/views/server/application/_top.html.erb index adb25cf1f..3d4b125a9 100644 --- a/app/views/server/application/_top.html.erb +++ b/app/views/server/application/_top.html.erb @@ -18,7 +18,7 @@ <li> <a class="nav-link nav-link--last js-user-button" href="#"> <% if current_user.picture.attached? %> - <%= kamifusen_tag current_user.picture, widht: 40, class: 'avatar img-fluid rounded-circle' %> + <%= kamifusen_tag current_user.picture, width: 40, height: 40, class: 'avatar img-fluid rounded-circle' %> <% else %> <%= image_tag 'avatar.jpg', class: 'avatar img-fluid rounded-circle' %> <% end %> diff --git a/app/views/server/universities/_form.html.erb b/app/views/server/universities/_form.html.erb index f8cdb2a5e..ddc64561c 100644 --- a/app/views/server/universities/_form.html.erb +++ b/app/views/server/universities/_form.html.erb @@ -27,7 +27,7 @@ <div class="col-md-4"> <%= f.input :logo, as: :single_deletable_file, - input_html: { accept: '.jpg,.jpeg,.png,.svg' }, + input_html: { accept: default_images_formats_accepted }, preview: false, direct_upload: true %> </div> diff --git a/config/application.rb b/config/application.rb index 61e858885..56211b00f 100644 --- a/config/application.rb +++ b/config/application.rb @@ -61,6 +61,7 @@ module Osuny ] config.allowed_special_chars = '#?!,_@$%^&*+:;£µ-' + config.default_images_formats = ['.jpg', '.jpeg', '.png', '.svg'] config.generators do |g| g.orm :active_record, primary_key_type: :uuid diff --git a/config/locales/communication/contents/en.yml b/config/locales/communication/contents/en.yml index bad502f6f..648bfb840 100644 --- a/config/locales/communication/contents/en.yml +++ b/config/locales/communication/contents/en.yml @@ -33,7 +33,6 @@ en: input: label: Image remove: Remove image - hint: 5 MB max, .png, .jpg, .svg alt: label: Alternative text placeholder: Enter alternative text @@ -203,7 +202,6 @@ en: image: label: Image remove: Remove image - hint: 5 MB max, .png, .jpg, .svg alt: label: Alternative text placeholder: Enter text description diff --git a/config/locales/communication/contents/fr.yml b/config/locales/communication/contents/fr.yml index aa35715c2..a16c67cb1 100644 --- a/config/locales/communication/contents/fr.yml +++ b/config/locales/communication/contents/fr.yml @@ -33,7 +33,6 @@ fr: input: label: Image remove: Enlever l'image - hint: 5 Mo max, .png, .jpg, .svg alt: label: Texte alternatif placeholder: Entrer la description textuelle @@ -203,7 +202,6 @@ fr: image: label: Image remove: Enlever l'image - hint: 5 Mo max, .png, .jpg, .svg alt: label: Texte alternatif placeholder: Entrer la description textuelle diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index 6cd50c56b..e9dd8b929 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -73,7 +73,7 @@ en: about_type: About color: Couleur cookies_policy: Cookies policy - favicon: Favicon (.png) + favicon: Favicon feature_alumni: Alumni feature_contacts: Directory feature_jobs: Job board @@ -82,7 +82,7 @@ en: has_sso: Has SSO? home_sentence: Sentence displayed on homepage host: Domain - logo: Logo (.png, .jpg, .svg) + logo: Logo name: Name privacy_policy: Privacy policy registration_contact: Contact mail for registrations problems @@ -403,6 +403,7 @@ en: simple_form: hints: communication_extranet: + favicon: '.png file only' host: Sans le protocole sso_button_label: "Default: Sign in via SSO" communication_website: diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index a61369e14..3a129d357 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -73,7 +73,7 @@ fr: about_type: Type d'extranet color: Couleur cookies_policy: Politique de cookies - favicon: Favicon (.png) + favicon: Favicon feature_alumni: Alumni feature_contacts: Annuaire feature_jobs: Offres d'emploi @@ -82,7 +82,7 @@ fr: has_sso: A un SSO ? home_sentence: Phrase affichée sur la home host: Domaine - logo: Logo (.png, .jpg, .svg) + logo: Logo name: Nom privacy_policy: Politique de confidentialité registration_contact: Mail de contact pour les problèmes d'inscription @@ -403,6 +403,7 @@ fr: simple_form: hints: communication_extranet: + favicon: 'Fichier .png uniquement' host: Sans le protocole sso_button_label: "Par défaut : Se connecter en SSO" communication_website: diff --git a/config/locales/en.yml b/config/locales/en.yml index 2ec222ce2..c4d40f270 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -162,6 +162,7 @@ en: formats: birthday: "%B %d" delete: Delete + default_images_hint: "5 Mb max, %{formats}" devise: failure: invalid: "Invalid email or password." diff --git a/config/locales/fr.yml b/config/locales/fr.yml index c49275048..bd8323c6f 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -161,6 +161,7 @@ fr: date: formats: birthday: "%d %B" + default_images_hint: "5 Mo max, %{formats}" delete: Supprimer devise: failure: diff --git a/config/locales/research/en.yml b/config/locales/research/en.yml index 8d19acee4..da5bce563 100644 --- a/config/locales/research/en.yml +++ b/config/locales/research/en.yml @@ -131,5 +131,3 @@ en: research_journal_paper: authors_list: Type the authors list directly in this field if you don't want to use the checkboxes above doi: "You can type the DOI identifier without https://, for example “10.19182/perspective/31918â€" - research_journal_volume: - cover: JPG or PNG file diff --git a/config/locales/research/fr.yml b/config/locales/research/fr.yml index 915c14779..bb29775ad 100644 --- a/config/locales/research/fr.yml +++ b/config/locales/research/fr.yml @@ -130,5 +130,3 @@ fr: research_journal_paper: authors_list: Tapez la liste des auteurs si vous n'utilisez pas les cases à cocher “Auteur·e·s†ci-dessus doi: "Vous pouvez saisir l'identifiant DOI sans https://, par exemple “10.19182/perspective/31918â€" - research_journal_volume: - cover: Fichier JPG ou PNG -- GitLab