Merge branch 'dev'

This commit is contained in:
Simon Lehericey 2017-10-19 16:53:47 +02:00
commit 305bf05c35
14 changed files with 127 additions and 14 deletions

View file

@ -1,7 +1,9 @@
$(document).on('turbolinks:load', link_init);
function link_init() {
$('#dossiers-list tr').on('click', function () {
$(location).attr('href', $(this).data('dossier_url'))
$('#dossiers-list tr').on('click', function (event) {
if (event.target.className !== 'btn-sm btn-danger') {
$(location).attr('href', $(this).data('dossier_url'));
}
});
}

View file

@ -161,7 +161,7 @@ class Users::DossiersController < UsersController
dossier.destroy
flash.notice = 'Brouillon supprimé'
end
redirect_to url_for users_dossiers_path
redirect_to url_for users_dossiers_path(liste: 'brouillon')
end
def text_summary

View file

@ -3,8 +3,8 @@ class AttestationTemplate < ApplicationRecord
belongs_to :procedure
mount_uploader :logo, AttestationTemplateImageUploader
mount_uploader :signature, AttestationTemplateImageUploader
mount_uploader :logo, AttestationTemplateLogoUploader
mount_uploader :signature, AttestationTemplateSignatureUploader
validate :logo_signature_file_size
validates :footer, length: { maximum: 190 }

View file

@ -1,4 +1,4 @@
class AttestationTemplateImageUploader < BaseUploader
class AttestationTemplateLogoUploader < BaseUploader
def root
File.join(Rails.root, 'public')
end
@ -23,4 +23,16 @@ class AttestationTemplateImageUploader < BaseUploader
def extension_white_list
%w(jpg jpeg png)
end
def filename
if file.present?
"attestation-template-logo-#{secure_token}.#{file.extension.downcase}"
end
end
private
def secure_token
model.logo_secure_token ||= SecureRandom.uuid
end
end

View file

@ -0,0 +1,38 @@
class AttestationTemplateSignatureUploader < BaseUploader
def root
File.join(Rails.root, 'public')
end
# Choose what kind of storage to use for this uploader:
if Features.remote_storage
storage :fog
else
storage :file
end
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
unless Features.remote_storage
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
%w(jpg jpeg png)
end
def filename
if file.present?
"attestation-template-signature-#{secure_token}.#{file.extension.downcase}"
end
end
private
def secure_token
model.signature_secure_token ||= SecureRandom.uuid
end
end

View file

@ -17,4 +17,14 @@ class AttestationUploader < BaseUploader
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
def filename
"attestation-#{secure_token}.pdf"
end
private
def secure_token
model.content_secure_token ||= SecureRandom.uuid
end
end

View file

@ -27,7 +27,7 @@
%td{ id: "dossier_#{dossier.id}_state" }= dossier.display_state
%td= dossier.last_update
%td= link_to('X', url_for(controller: 'dossiers', action: :destroy, id: dossier.id), 'data-method' => :delete, class: 'btn-sm btn-danger') if @liste == "brouillon"
%td= link_to('X', url_for(controller: 'dossiers', action: :destroy, id: dossier.id), 'data-confirm' => "Voulez-vous supprimer la brouillon ?", 'data-method' => :delete, class: 'btn-sm btn-danger') if @liste == "brouillon"
= smart_listing.paginate
= smart_listing.pagination_per_page_links

View file

@ -0,0 +1,5 @@
class AddContentSecureTokenColumnToAttestation < ActiveRecord::Migration[5.0]
def change
add_column :attestations, :content_secure_token, :string
end
end

View file

@ -0,0 +1,5 @@
class AddLogoSecureTokenColumnToAttestationTemplate < ActiveRecord::Migration[5.0]
def change
add_column :attestation_templates, :logo_secure_token, :string
end
end

View file

@ -0,0 +1,5 @@
class AddSignatureSecureTokenColumnToAttestationTemplate < ActiveRecord::Migration[5.0]
def change
add_column :attestation_templates, :signature_secure_token, :string
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170927092716) do
ActiveRecord::Schema.define(version: 20171019113610) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -81,15 +81,18 @@ ActiveRecord::Schema.define(version: 20170927092716) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "procedure_id"
t.string "logo_secure_token"
t.string "signature_secure_token"
t.index ["procedure_id"], name: "index_attestation_templates_on_procedure_id", unique: true, using: :btree
end
create_table "attestations", force: :cascade do |t|
t.string "pdf"
t.string "title"
t.integer "dossier_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "dossier_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "content_secure_token"
t.index ["dossier_id"], name: "index_attestations_on_dossier_id", using: :btree
end

View file

@ -0,0 +1,29 @@
namespace :'2017_10_18_regenerate_attestation' do
task set: :environment do
include ActiveSupport::Testing::TimeHelpers
if ENV['ATTESTATION_ID'].present?
regenerate_attestations(Attestation.find(ENV['ATTESTATION_ID']))
else
Attestation.all.each { |attestation| regenerate_attestations(attestation) }
end
end
def regenerate_attestations(attestation)
Procedure.unscoped do
Dossier.unscoped do
dossier = attestation.dossier
procedure = dossier.procedure
puts "processing dossier #{dossier.id}"
travel_to(dossier.processed_at) do
new_attestation = procedure.attestation_template.attestation_for(dossier)
attestation.delete
dossier.attestation = new_attestation
dossier.save
end
end
end
end
end

View file

@ -83,4 +83,8 @@ EOF
Rake::Task["db:migrate"].invoke
Rake::Task["db:environment:set"].invoke("RAILS_ENV=development")
end
task :console do
exec("ssh tps@sgmap_production1 -t 'source /etc/profile && cd current && bundle exec rails c production'")
end
end

View file

@ -2,8 +2,8 @@ describe AttestationTemplate, type: :model do
describe 'validate' do
let(:logo_size) { AttestationTemplate::FILE_MAX_SIZE_IN_MB.megabyte }
let(:signature_size) { AttestationTemplate::FILE_MAX_SIZE_IN_MB.megabyte }
let(:fake_logo) { double(AttestationTemplateImageUploader, file: double(size: logo_size)) }
let(:fake_signature) { double(AttestationTemplateImageUploader, file: double(size: signature_size)) }
let(:fake_logo) { double(AttestationTemplateLogoUploader, file: double(size: logo_size)) }
let(:fake_signature) { double(AttestationTemplateSignatureUploader, file: double(size: signature_size)) }
let(:attestation_template) { AttestationTemplate.new }
before do
@ -142,7 +142,7 @@ describe AttestationTemplate, type: :model do
it 'provides a pseudo file' do
expect(attestation.pdf.file).to exist
expect(attestation.pdf.filename).to eq('attestation')
expect(attestation.pdf.filename).to start_with('attestation')
end
context 'when the dossier and the procedure has an individual' do