feat(gallery): display right tag for annotation privée

This commit is contained in:
Eric Leroy-Terquem 2024-10-10 10:49:33 +02:00
parent 2e2d2afecb
commit 17aaa7b32c
No known key found for this signature in database
GPG key ID: 53D8FAECEF207605
2 changed files with 53 additions and 8 deletions

View file

@ -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

View file

@ -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 }