Merge pull request #5299 from betagouv/add-private-pj-to-export
Instructeur : ajoute les fichiers joints des annotations privées à l'export
This commit is contained in:
commit
29d3d58645
6 changed files with 48 additions and 28 deletions
|
@ -21,7 +21,7 @@ class ApplicationController < ActionController::Base
|
||||||
before_action :setup_tracking
|
before_action :setup_tracking
|
||||||
|
|
||||||
helper_method :multiple_devise_profile_connect?, :instructeur_signed_in?, :current_instructeur,
|
helper_method :multiple_devise_profile_connect?, :instructeur_signed_in?, :current_instructeur,
|
||||||
:administrateur_signed_in?, :current_administrateur
|
:administrateur_signed_in?, :current_administrateur, :current_account
|
||||||
|
|
||||||
def staging_authenticate
|
def staging_authenticate
|
||||||
if StagingAuthService.enabled? && !authenticate_with_http_basic { |username, password| StagingAuthService.authenticate(username, password) }
|
if StagingAuthService.enabled? && !authenticate_with_http_basic { |username, password| StagingAuthService.authenticate(username, password) }
|
||||||
|
@ -49,14 +49,6 @@ class ApplicationController < ActionController::Base
|
||||||
user_signed_in? && administrateur_signed_in?
|
user_signed_in? && administrateur_signed_in?
|
||||||
end
|
end
|
||||||
|
|
||||||
def pundit_user
|
|
||||||
{
|
|
||||||
administrateur: current_administrateur,
|
|
||||||
instructeur: current_instructeur,
|
|
||||||
user: current_user
|
|
||||||
}.compact
|
|
||||||
end
|
|
||||||
|
|
||||||
def current_instructeur
|
def current_instructeur
|
||||||
current_user&.instructeur
|
current_user&.instructeur
|
||||||
end
|
end
|
||||||
|
@ -73,6 +65,16 @@ class ApplicationController < ActionController::Base
|
||||||
current_administrateur.present?
|
current_administrateur.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def current_account
|
||||||
|
{
|
||||||
|
administrateur: current_administrateur,
|
||||||
|
instructeur: current_instructeur,
|
||||||
|
user: current_user
|
||||||
|
}.compact
|
||||||
|
end
|
||||||
|
|
||||||
|
alias_method :pundit_user, :current_account
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def feature_enabled?(feature_name)
|
def feature_enabled?(feature_name)
|
||||||
|
|
|
@ -701,7 +701,8 @@ class Dossier < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def attachments_downloadable?
|
def attachments_downloadable?
|
||||||
!PiecesJustificativesService.liste_pieces_justificatives(self).empty? && PiecesJustificativesService.pieces_justificatives_total_size(self) < Dossier::TAILLE_MAX_ZIP
|
PiecesJustificativesService.liste_pieces_justificatives(self).present? \
|
||||||
|
&& PiecesJustificativesService.pieces_justificatives_total_size(self) < Dossier::TAILLE_MAX_ZIP
|
||||||
end
|
end
|
||||||
|
|
||||||
def linked_dossiers_for(instructeur)
|
def linked_dossiers_for(instructeur)
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
class ChampPolicy < ApplicationPolicy
|
class ChampPolicy < ApplicationPolicy
|
||||||
|
# Scope for WRITING to a champ.
|
||||||
|
#
|
||||||
|
# (If the need for a scope to READ a champ emerges, we can implement another scope
|
||||||
|
# in this file, following this example: https://github.com/varvet/pundit/issues/368#issuecomment-196111115)
|
||||||
class Scope < ApplicationScope
|
class Scope < ApplicationScope
|
||||||
def resolve
|
def resolve
|
||||||
if user.blank?
|
if user.blank?
|
||||||
|
|
|
@ -1,16 +1,10 @@
|
||||||
class PiecesJustificativesService
|
class PiecesJustificativesService
|
||||||
def self.liste_pieces_justificatives(dossier)
|
def self.liste_pieces_justificatives(dossier)
|
||||||
pjs_commentaires = dossier.commentaires
|
pjs_champs = pjs_for_champs(dossier)
|
||||||
.map(&:piece_jointe)
|
pjs_commentaires = pjs_for_commentaires(dossier)
|
||||||
|
|
||||||
|
(pjs_champs + pjs_commentaires)
|
||||||
.filter(&:attached?)
|
.filter(&:attached?)
|
||||||
|
|
||||||
champs_blocs_repetables = dossier.champs
|
|
||||||
.filter { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:repetition) }
|
|
||||||
.flat_map(&:champs)
|
|
||||||
|
|
||||||
pjs_commentaires + champs_pieces_justificatives_with_attachments(
|
|
||||||
champs_blocs_repetables + dossier.champs
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.pieces_justificatives_total_size(dossier)
|
def self.pieces_justificatives_total_size(dossier)
|
||||||
|
@ -48,10 +42,21 @@ class PiecesJustificativesService
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def self.champs_pieces_justificatives_with_attachments(champs)
|
def self.pjs_for_champs(dossier)
|
||||||
champs
|
allowed_champs = dossier.champs + dossier.champs_private
|
||||||
|
|
||||||
|
allowed_child_champs = allowed_champs
|
||||||
|
.filter { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:repetition) }
|
||||||
|
.flat_map(&:champs)
|
||||||
|
|
||||||
|
(allowed_champs + allowed_child_champs)
|
||||||
.filter { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) }
|
.filter { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) }
|
||||||
.filter { |pj| pj.piece_justificative_file.attached? }
|
|
||||||
.map(&:piece_justificative_file)
|
.map(&:piece_justificative_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.pjs_for_commentaires(dossier)
|
||||||
|
dossier
|
||||||
|
.commentaires
|
||||||
|
.map(&:piece_jointe)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
%li
|
%li
|
||||||
= link_to "Export GeoJSON", geo_data_instructeur_dossier_path(dossier.procedure, dossier), target: "_blank", rel: "noopener", class: "menu-item menu-link"
|
= link_to "Export GeoJSON", geo_data_instructeur_dossier_path(dossier.procedure, dossier), target: "_blank", rel: "noopener", class: "menu-item menu-link"
|
||||||
|
|
||||||
- if !PiecesJustificativesService.liste_pieces_justificatives(dossier).empty?
|
- if PiecesJustificativesService.liste_pieces_justificatives(dossier).present?
|
||||||
%span.dropdown.print-menu-opener
|
%span.dropdown.print-menu-opener
|
||||||
%button.button.dropdown-button.icon-only
|
%button.button.dropdown-button.icon-only
|
||||||
%span.icon.attached
|
%span.icon.attached
|
||||||
|
|
|
@ -13,7 +13,15 @@ describe ActiveStorage::DownloadableFile do
|
||||||
dossier.champs << create(:champ, :piece_justificative, :with_piece_justificative_file)
|
dossier.champs << create(:champ, :piece_justificative, :with_piece_justificative_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(list.length).to be 1 }
|
it { expect(list.length).to eq 1 }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when there is a private piece_justificative' do
|
||||||
|
before do
|
||||||
|
dossier.champs_private << create(:champ, :piece_justificative, :with_piece_justificative_file, private: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(list.length).to eq 1 }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when there is a repetition bloc' do
|
context 'when there is a repetition bloc' do
|
||||||
|
@ -21,7 +29,7 @@ describe ActiveStorage::DownloadableFile do
|
||||||
let(:dossier) { create(:dossier, :en_construction, champs: [champ]) }
|
let(:dossier) { create(:dossier, :en_construction, champs: [champ]) }
|
||||||
|
|
||||||
it 'should have 4 piece_justificatives' do
|
it 'should have 4 piece_justificatives' do
|
||||||
expect(list.size).to eq(4)
|
expect(list.size).to eq 4
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -29,14 +37,14 @@ describe ActiveStorage::DownloadableFile do
|
||||||
let(:commentaire) { create(:commentaire) }
|
let(:commentaire) { create(:commentaire) }
|
||||||
let(:dossier) { commentaire.dossier }
|
let(:dossier) { commentaire.dossier }
|
||||||
|
|
||||||
it { expect(list.length).to be 0 }
|
it { expect(list.length).to eq 0 }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when there is a message with an attachment' do
|
context 'when there is a message with an attachment' do
|
||||||
let(:commentaire) { create(:commentaire, :with_file) }
|
let(:commentaire) { create(:commentaire, :with_file) }
|
||||||
let(:dossier) { commentaire.dossier }
|
let(:dossier) { commentaire.dossier }
|
||||||
|
|
||||||
it { expect(list.length).to be 1 }
|
it { expect(list.length).to eq 1 }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue