From 17aaa7b32cf664060edf0be12212a5c061a29fad Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Thu, 10 Oct 2024 10:49:33 +0200 Subject: [PATCH] =?UTF-8?q?feat(gallery):=20display=20right=20tag=20for=20?= =?UTF-8?q?annotation=20priv=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../attachment/gallery_item_component.rb | 18 ++++++-- .../attachment/gallery_item_component_spec.rb | 43 +++++++++++++++++-- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/app/components/attachment/gallery_item_component.rb b/app/components/attachment/gallery_item_component.rb index 3319ad3d9..e3d4f86e3 100644 --- a/app/components/attachment/gallery_item_component.rb +++ b/app/components/attachment/gallery_item_component.rb @@ -17,7 +17,7 @@ class Attachment::GalleryItemComponent < ApplicationComponent def gallery_demande? = @gallery_demande def libelle - if from_dossier? + if from_champ? attachment.record.libelle elsif from_messagerie? 'Pièce jointe au message' @@ -28,8 +28,10 @@ class Attachment::GalleryItemComponent < ApplicationComponent def origin case - when from_dossier? + when from_public_champ? 'Dossier usager' + when from_private_champ? + 'Annotation privée' when from_messagerie_expert? 'Messagerie (expert)' when from_messagerie_instructeur? @@ -64,7 +66,7 @@ class Attachment::GalleryItemComponent < ApplicationComponent end def updated? - from_dossier? && updated_at > attachment.record.dossier.depose_at + from_public_champ? && updated_at > attachment.record.dossier.depose_at end def updated_at @@ -80,10 +82,18 @@ class Attachment::GalleryItemComponent < ApplicationComponent private - def from_dossier? + def from_champ? attachment.record.class.in?([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp]) end + def from_public_champ? + from_champ? && !attachment.record.private? + end + + def from_private_champ? + from_champ? && attachment.record.private? + end + def from_messagerie? attachment.record.is_a?(Commentaire) end diff --git a/spec/components/attachment/gallery_item_component_spec.rb b/spec/components/attachment/gallery_item_component_spec.rb index e9fda3802..df09db179 100644 --- a/spec/components/attachment/gallery_item_component_spec.rb +++ b/spec/components/attachment/gallery_item_component_spec.rb @@ -4,9 +4,10 @@ require 'rails_helper' RSpec.describe Attachment::GalleryItemComponent, type: :component do let(:instructeur) { create(:instructeur) } - let(:procedure) { create(:procedure, :published, types_de_champ_public:) } + let(:procedure) { create(:procedure, :published, types_de_champ_public:, types_de_champ_private:) } let(:types_de_champ_public) { [{ type: :piece_justificative }] } - let(:dossier) { create(:dossier, :with_populated_champs, :en_construction, procedure:) } + let(:types_de_champ_private) { [{ type: :piece_justificative }] } + let(:dossier) { create(:dossier, :with_populated_champs, :with_populated_annotations, :en_construction, procedure:) } let(:filename) { attachment.blob.filename.to_s } let(:gallery_demande) { false } let(:seen_at) { nil } @@ -16,8 +17,10 @@ RSpec.describe Attachment::GalleryItemComponent, type: :component do subject { render_inline(component).to_html } - context "when attachment is from a piece justificative champ" do - let(:champ) { dossier.champs.first } + context "when attachment is from a public piece justificative champ" do + let(:champ) do + dossier.champs.where(private: false).first + end let(:libelle) { champ.libelle } let(:attachment) { champ.piece_justificative_file.attachments.first } @@ -56,6 +59,38 @@ RSpec.describe Attachment::GalleryItemComponent, type: :component do end end + context "when attachment is from a private piece justificative champ" do + let(:annotation) do + dossier.champs.where(private: true).first + end + let(:libelle) { annotation.libelle } + let(:attachment) { annotation.piece_justificative_file.attachments.first } + + # Correspond au cas standard où le blob est créé avant le dépôt du dossier + before { dossier.touch(:depose_at) } + + it "displays libelle, link, tag and renders title" do + expect(subject).to have_text(libelle) + expect(subject).to have_link(filename) + expect(subject).to have_text('Annotation privée') + expect(component.title).to eq("#{libelle} -- #{filename}") + end + + it "displays when gallery item has been added" do + expect(subject).to have_text('Ajoutée le') + expect(subject).not_to have_css('.highlighted') + expect(subject).to have_text(component.helpers.try_format_datetime(attachment.record.created_at, format: :veryshort)) + end + + context "when gallery item is in page Demande" do + let(:gallery_demande) { true } + + it "does not display libelle" do + expect(subject).not_to have_text(libelle) + end + end + end + context "when attachment is from a commentaire" do let(:commentaire) { create(:commentaire, :with_file, dossier: dossier) } let(:attachment) { commentaire.piece_jointe.first }