Merge branch 'dev'

This commit is contained in:
gregoirenovel 2018-03-19 11:42:22 +01:00
commit 0ee0f135f7
10 changed files with 30 additions and 8 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

View file

@ -13,7 +13,7 @@ class API::V1::DossiersController < APIController
error code: 404, desc: "Procédure inconnue"
def index
procedure = current_administrateur.procedures.find(params[:procedure_id])
procedure = administrateur.procedures.find(params[:procedure_id])
dossiers = procedure.dossiers.state_not_brouillon.page(params[:page]).per(per_page)
render json: { dossiers: dossiers.map{ |dossier| DossiersSerializer.new(dossier) }, pagination: pagination(dossiers) }, status: 200
@ -28,7 +28,7 @@ class API::V1::DossiersController < APIController
error code: 404, desc: "Procédure ou dossier inconnu"
def show
procedure = current_administrateur.procedures.find(params[:procedure_id])
procedure = administrateur.procedures.find(params[:procedure_id])
dossier = procedure.dossiers.find(params[:id])
respond_to do |format|

View file

@ -9,7 +9,7 @@ class API::V1::ProceduresController < APIController
error code: 404, desc: "Procédure inconnue"
def show
procedure = current_administrateur.procedures.find(params[:id]).decorate
procedure = administrateur.procedures.find(params[:id]).decorate
render json: { procedure: ProcedureSerializer.new(procedure).as_json }
rescue ActiveRecord::RecordNotFound => e

View file

@ -19,10 +19,10 @@ class APIController < ApplicationController
protected
def valid_token?
current_administrateur.present?
administrateur.present?
end
def current_administrateur
def administrateur
@administrateur ||= (authenticate_with_bearer_token || authenticate_with_param_token)
end

View file

@ -175,7 +175,7 @@ module NewGestionnaire
def download_dossiers
export = procedure.generate_export
filename = "dossiers_#{procedure.procedure_path.path}_#{Time.now.strftime('%Y-%m-%d_%H-%M')}"
filename = procedure.export_filename
respond_to do |format|
format.csv { send_data(SpreadsheetArchitect.to_csv(data: export[:data], headers: export[:headers]), filename: "#{filename}.csv") }

View file

@ -157,6 +157,11 @@ class Procedure < ApplicationRecord
self.dossiers.state_not_brouillon.size
end
def export_filename
procedure_identifier = procedure_path&.path || "procedure-#{id}"
"dossiers_#{procedure_identifier}_#{Time.now.strftime('%Y-%m-%d_%H-%M')}"
end
def generate_export
exportable_dossiers = dossiers.downloadable_sorted

View file

@ -1,6 +1,6 @@
Un nouvel administrateur a été créé sur demarches-simplifiees.fr.
Plateforme : <%= TPS::Application::URL %>
Plateforme : <%= root_url %>
Login : <%= @admin.email %>

View file

@ -61,7 +61,6 @@ set :shared_paths, [
'config/initializers/features.yml',
"config/environments/#{rails_env}.rb",
"config/initializers/token.rb",
"config/initializers/super_admin.rb",
"config/unicorn.rb",
"config/initializers/raven.rb",
'config/france_connect.yml',

View file

@ -494,4 +494,22 @@ describe Procedure do
describe ".default_sort" do
it { expect(Procedure.default_sort).to eq("{\"table\":\"self\",\"column\":\"id\",\"order\":\"desc\"}") }
end
describe ".export_filename" do
before { Timecop.freeze(Time.new(2018, 1, 2, 23, 11, 14)) }
subject { procedure.export_filename }
context "with a path" do
let(:procedure) { create(:procedure, :published) }
it { is_expected.to eq("dossiers_#{procedure.procedure_path.path}_2018-01-02_23-11") }
end
context "without a path" do
let(:procedure) { create(:procedure) }
it { is_expected.to eq("dossiers_procedure-#{procedure.id}_2018-01-02_23-11") }
end
end
end