Merge branch 'dev'

This commit is contained in:
Mathieu Magnin 2017-07-11 11:41:37 +02:00
commit f0273d6512
21 changed files with 284 additions and 185 deletions

View file

@ -6,7 +6,7 @@ class Admin::ProceduresController < AdminController
def index def index
@procedures = smart_listing_create :procedures, @procedures = smart_listing_create :procedures,
current_administrateur.procedures.where(published: true, archived: false).order(created_at: :desc), current_administrateur.procedures.published.not_archived.order(created_at: :desc),
partial: "admin/procedures/list", partial: "admin/procedures/list",
array: true array: true
@ -15,7 +15,7 @@ class Admin::ProceduresController < AdminController
def archived def archived
@procedures = smart_listing_create :procedures, @procedures = smart_listing_create :procedures,
current_administrateur.procedures.where(archived: true).order(created_at: :desc), current_administrateur.procedures.archived.order(created_at: :desc),
partial: "admin/procedures/list", partial: "admin/procedures/list",
array: true array: true
@ -26,7 +26,7 @@ class Admin::ProceduresController < AdminController
def draft def draft
@procedures = smart_listing_create :procedures, @procedures = smart_listing_create :procedures,
current_administrateur.procedures.where(published: false, archived: false).order(created_at: :desc), current_administrateur.procedures.not_published.not_archived.order(created_at: :desc),
partial: "admin/procedures/list", partial: "admin/procedures/list",
array: true array: true

View file

@ -9,10 +9,10 @@ class API::StatistiquesController < ApplicationController
private private
def total_dossiers def total_dossiers
Dossier.where.not(state: :draft).size Dossier.state_not_brouillon.size
end end
def dossiers_mois def dossiers_mois
Dossier.where.not(state: :draft).where(created_at: (1.month.ago)..Time.now).size Dossier.state_not_brouillon.where(created_at: (1.month.ago)..Time.now).size
end end
end end

View file

@ -7,7 +7,7 @@ class API::V1::DossiersController < APIController
def index def index
procedure = current_administrateur.procedures.find(params[:procedure_id]) procedure = current_administrateur.procedures.find(params[:procedure_id])
dossiers = procedure.dossiers.where.not(state: :draft).paginate(page: params[:page]) dossiers = procedure.dossiers.state_not_brouillon.paginate(page: params[:page])
render json: { dossiers: dossiers.map{ |dossier| DossiersSerializer.new(dossier) }, pagination: pagination(dossiers) }, status: 200 render json: { dossiers: dossiers.map{ |dossier| DossiersSerializer.new(dossier) }, pagination: pagination(dossiers) }, status: 200
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound

View file

@ -13,14 +13,16 @@ class CommentairesController < ApplicationController
def create def create
@commentaire = Commentaire.new @commentaire = Commentaire.new
@commentaire.dossier = Dossier.find(params['dossier_id'])
@commentaire.champ = @commentaire.dossier.champs.find(params[:champ_id]) if params[:champ_id] @commentaire.champ = @commentaire.dossier.champs.find(params[:champ_id]) if params[:champ_id]
dossier_id = params['dossier_id']
if is_gestionnaire? if is_gestionnaire?
@commentaire.email = current_gestionnaire.email @commentaire.email = current_gestionnaire.email
@commentaire.dossier = current_gestionnaire.dossiers.find_by(id: dossier_id) || current_gestionnaire.avis.find_by!(dossier_id: dossier_id).dossier
@commentaire.dossier.next_step! 'gestionnaire', 'comment' @commentaire.dossier.next_step! 'gestionnaire', 'comment'
else else
@commentaire.email = current_user.email @commentaire.email = current_user.email
@commentaire.dossier = current_user.dossiers.find_by(id: dossier_id) || current_user.invites.find_by!(dossier_id: dossier_id).dossier
@commentaire.dossier.next_step! 'user', 'comment' if current_user.email == @commentaire.dossier.user.email @commentaire.dossier.next_step! 'user', 'comment' if current_user.email == @commentaire.dossier.user.email
end end

View file

@ -6,7 +6,7 @@ class DemoController < ApplicationController
return redirect_to root_path if Rails.env.production? return redirect_to root_path if Rails.env.production?
smart_listing_create :procedures, smart_listing_create :procedures,
Procedure.where(archived: false, published: true).order("id DESC"), Procedure.published.not_archived.order("id DESC"),
partial: "demo/list", partial: "demo/list",
array: true array: true
end end

View file

@ -5,11 +5,12 @@ class InvitesController < ApplicationController
email_sender = @current_devise_profil.email email_sender = @current_devise_profil.email
class_var = @current_devise_profil.class == User ? InviteUser : InviteGestionnaire class_var = @current_devise_profil.class == User ? InviteUser : InviteGestionnaire
dossier = @current_devise_profil.dossiers.find(params[:dossier_id])
email = params[:email].downcase email = params[:email].downcase
user = User.find_by_email(email) user = User.find_by_email(email)
invite = class_var.create(dossier_id: params[:dossier_id], user: user, email: email, email_sender: email_sender) invite = class_var.create(dossier: dossier, user: user, email: email, email_sender: email_sender)
if invite.valid? if invite.valid?
InviteMailer.invite_user(invite).deliver_now! unless invite.user.nil? InviteMailer.invite_user(invite).deliver_now! unless invite.user.nil?

View file

@ -4,7 +4,7 @@ class StatsController < ApplicationController
MEAN_NUMBER_OF_CHAMPS_IN_A_FORM = 24.0 MEAN_NUMBER_OF_CHAMPS_IN_A_FORM = 24.0
def index def index
procedures = Procedure.where(:published => true) procedures = Procedure.published
dossiers = Dossier.where.not(:state => :draft) dossiers = Dossier.where.not(:state => :draft)
@procedures_count = procedures.count @procedures_count = procedures.count

View file

@ -60,7 +60,7 @@ class Users::DossiersController < UsersController
end end
def new def new
procedure = Procedure.where(archived: false, published: true).find(params[:procedure_id]) procedure = Procedure.not_archived.published.find(params[:procedure_id])
dossier = Dossier.create(procedure: procedure, user: current_user, state: 'draft') dossier = Dossier.create(procedure: procedure, user: current_user, state: 'draft')
siret = params[:siret] || current_user.siret siret = params[:siret] || current_user.siret

View file

@ -8,11 +8,11 @@ class AdminProceduresShowFacades
end end
def dossiers def dossiers
@procedure.dossiers.where.not(state: :draft) @procedure.dossiers.state_not_brouillon
end end
def dossiers_for_pie_highchart def dossiers_for_pie_highchart
dossiers.where.not(state: :draft, archived: true).group(:state).count dossiers.state_not_brouillon.not_archived.group(:state).count
.reduce({}) do |acc, (key, val)| .reduce({}) do |acc, (key, val)|
translated_key = DossierDecorator.case_state_fr(key) translated_key = DossierDecorator.case_state_fr(key)
acc[translated_key].nil? ? acc[translated_key] = val : acc[translated_key] += val acc[translated_key].nil? ? acc[translated_key] = val : acc[translated_key] += val
@ -21,11 +21,11 @@ class AdminProceduresShowFacades
end end
def dossiers_archived_by_state_total def dossiers_archived_by_state_total
dossiers.select('state, count(*) as total').where(archived: true).where.not(state: :termine).group(:state).order(:state).decorate dossiers.select('state, count(*) as total').archived.where.not(state: :termine).group(:state).order(:state).decorate
end end
def dossiers_archived_total def dossiers_archived_total
dossiers.where(archived: true).where.not(state: :termine).size dossiers.archived.where.not(state: :termine).size
end end
def dossiers_total def dossiers_total

View file

@ -14,7 +14,7 @@ class DossiersListFacades
end end
def total_dossier def total_dossier
current_devise_profil.dossiers.where(archived: false).count current_devise_profil.dossiers.not_archived.count
end end
def total_dossier_follow def total_dossier_follow
@ -22,11 +22,11 @@ class DossiersListFacades
end end
def total_new_dossier def total_new_dossier
current_devise_profil.dossiers.where(state: :initiated, archived: false).count current_devise_profil.dossiers.state_nouveaux.not_archived.count
end end
def new_dossier_number procedure_id def new_dossier_number procedure_id
current_devise_profil.dossiers.where(state: :initiated, archived: false, procedure_id: procedure_id).count current_devise_profil.dossiers.state_nouveaux.not_archived.where(procedure_id: procedure_id).count
end end
def gestionnaire_procedures_name_and_id_list def gestionnaire_procedures_name_and_id_list

View file

@ -8,7 +8,7 @@ class Gestionnaire < ActiveRecord::Base
has_many :assign_to, dependent: :destroy has_many :assign_to, dependent: :destroy
has_many :procedures, through: :assign_to has_many :procedures, through: :assign_to
has_many :dossiers, -> { where.not(state: :draft) }, through: :procedures has_many :dossiers, -> { state_not_brouillon }, through: :procedures
has_many :followed_dossiers, through: :follows, source: :dossier has_many :followed_dossiers, through: :follows, source: :dossier
has_many :follows has_many :follows
has_many :preference_list_dossiers has_many :preference_list_dossiers
@ -108,8 +108,7 @@ class Gestionnaire < ActiveRecord::Base
start_date = DateTime.now.beginning_of_week start_date = DateTime.now.beginning_of_week
active_procedure_overviews = procedures active_procedure_overviews = procedures
.where(published: true) .published
.all
.map { |procedure| procedure.procedure_overview(start_date) } .map { |procedure| procedure.procedure_overview(start_date) }
.select(&:had_some_activities?) .select(&:had_some_activities?)

View file

@ -32,6 +32,9 @@ class Procedure < ActiveRecord::Base
mount_uploader :logo, ProcedureLogoUploader mount_uploader :logo, ProcedureLogoUploader
default_scope { where(hidden_at: nil) } default_scope { where(hidden_at: nil) }
scope :published, -> { where(published: true) }
scope :not_published, -> { where(published: false) }
scope :archived, -> { where(archived: true) }
scope :not_archived, -> { where(archived: false) } scope :not_archived, -> { where(archived: false) }
scope :by_libelle, -> { order(libelle: :asc) } scope :by_libelle, -> { order(libelle: :asc) }
@ -61,7 +64,7 @@ class Procedure < ActiveRecord::Base
end end
def self.active id def self.active id
not_archived.where(published: true).find(id) not_archived.published.find(id)
end end
def switch_types_de_champ index_of_first_element def switch_types_de_champ index_of_first_element
@ -127,7 +130,7 @@ class Procedure < ActiveRecord::Base
end end
def total_dossier def total_dossier
self.dossiers.where.not(state: :draft).size self.dossiers.state_not_brouillon.size
end end
def generate_export def generate_export

View file

@ -46,8 +46,8 @@ class Search < ActiveRecord::Base
dossier_ids = @gestionnaire.dossiers dossier_ids = @gestionnaire.dossiers
.select(:id) .select(:id)
.where(archived: false) .not_archived
.where.not(state: "draft") .state_not_brouillon
q = Search q = Search
.select("DISTINCT(searches.dossier_id)") .select("DISTINCT(searches.dossier_id)")

View file

@ -18,10 +18,10 @@
= admin.last_sign_in_at.localtime.strftime('%d/%m/%Y') = admin.last_sign_in_at.localtime.strftime('%d/%m/%Y')
) )
%td %td
= admin.procedures.where(published: true).count = admin.procedures.published.count
%td %td
- total_dossier = 0 - total_dossier = 0
- admin.procedures.each do |procedure| total_dossier += procedure.dossiers.where.not(state: :draft).count end - admin.procedures.each do |procedure| total_dossier += procedure.dossiers.state_not_brouillon.count end
= total_dossier = total_dossier
= smart_listing.paginate = smart_listing.paginate
= smart_listing.pagination_per_page_links = smart_listing.pagination_per_page_links

View file

@ -1,2 +1,2 @@
%data.mj-w-data{ "data-apikey" => "1v5T", "data-base" => "https://app.mailjet.com", "data-height" => "328", "data-lang" => "fr_FR", "data-statics" => "statics", "data-token" => "11c89e7ddb46fbcdcb7f8fe5fdfca818", "data-w-id" => "39b", "data-width" => "640" } %data.mj-w-data{ "data-apikey" => "1v5T", "data-base" => "https://app.mailjet.com", "data-height" => "328", "data-lang" => "fr_FR", "data-statics" => "statics", "data-token" => "11c89e7ddb46fbcdcb7f8fe5fdfca818", "data-w-id" => "39b", "data-width" => "640" }
%script{ src: 'https://app.mailjet.com/statics/js/widget.modal.js' } %script{ src: 'https://app.mailjet.com/statics/js/widget.modal.js', 'data-turbolinks-eval': 'false' }

View file

@ -13,19 +13,19 @@
.procedure-list-element{ class: @draft_class } .procedure-list-element{ class: @draft_class }
Brouillons Brouillons
.badge.progress-bar-default .badge.progress-bar-default
= current_administrateur.procedures.where(published: false, archived: false).count = current_administrateur.procedures.not_published.not_archived.count
%a#active-procedures{ :href => "#{url_for :admin_procedures}" } %a#active-procedures{ :href => "#{url_for :admin_procedures}" }
.procedure-list-element{ class: @active_class } .procedure-list-element{ class: @active_class }
Actives Actives
.badge.progress-bar-success .badge.progress-bar-success
= current_administrateur.procedures.where(published: true, archived: false).count = current_administrateur.procedures.published.not_archived.count
%a#archived-procedures{ :href => "#{url_for :admin_procedures_archived}" } %a#archived-procedures{ :href => "#{url_for :admin_procedures_archived}" }
.procedure-list-element{ class: @archived_class } .procedure-list-element{ class: @archived_class }
Archivées Archivées
.badge.progress-bar-purple .badge.progress-bar-purple
= current_administrateur.procedures.where(archived: true).count = current_administrateur.procedures.archived.count
.split-hr-left .split-hr-left

View file

@ -35,7 +35,7 @@
= render partial: "layouts/mailjet_newsletter" = render partial: "layouts/mailjet_newsletter"
= render partial: "layouts/crisp" = render partial: "layouts/crisp"
= javascript_include_tag "new_design/application", "data-turbolinks-track": true = javascript_include_tag "new_design/application", "data-turbolinks-eval": false
= yield :charts_js = yield :charts_js
- if Rails.env == "test" - if Rails.env == "test"
%script{ type: "text/javascript" } %script{ type: "text/javascript" }

View file

@ -80,7 +80,7 @@
%ul.numbers %ul.numbers
%li.number %li.number
.number-value .number-value
= number_with_delimiter(Procedure.where(:published => true).count, :locale => :fr) = number_with_delimiter(Procedure.published.count, :locale => :fr)
.number-label< .number-label<
procédures procédures
%br<> %br<>

View file

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe Backoffice::CommentairesController, type: :controller do describe Backoffice::CommentairesController, type: :controller do
let(:dossier) { create(:dossier) } let(:dossier) { create(:dossier, :replied) }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
let(:email_commentaire) { 'test@test.com' } let(:email_commentaire) { 'test@test.com' }
let(:texte_commentaire) { 'Commentaire de test' } let(:texte_commentaire) { 'Commentaire de test' }
@ -16,6 +16,25 @@ describe Backoffice::CommentairesController, type: :controller do
sign_in gestionnaire sign_in gestionnaire
end end
context "when gestionnaire has no access to dossier" do
subject { post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire } }
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
it { expect { subject rescue nil }.to change(Commentaire, :count).by(0) }
end
context "when gestionnaire is invited for avis on dossier" do
subject { post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire } }
before { Avis.create(dossier: dossier, gestionnaire: gestionnaire, claimant: create(:gestionnaire)) }
it { expect{ subject }.to change(Commentaire, :count).by(1) }
end
context "when gestionnaire has access to dossier" do
before do
gestionnaire.procedures << dossier.procedure
end
context "création correct d'un commentaire" do context "création correct d'un commentaire" do
subject { post :create, params: {dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire} } subject { post :create, params: {dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire} }
@ -58,8 +77,8 @@ describe Backoffice::CommentairesController, type: :controller do
subject subject
end end
it 'Internal notification is not create' do it 'Internal notification is created' do
expect { subject }.to change(Notification, :count).by (0) expect { subject }.to change(Notification, :count).by (1)
end end
describe 'piece justificative created' do describe 'piece justificative created' do
@ -96,7 +115,7 @@ describe Backoffice::CommentairesController, type: :controller do
context 'gestionnaire is connected' do context 'gestionnaire is connected' do
context 'when dossier is at state updated' do context 'when dossier is at state updated' do
before do before do
sign_in create(:gestionnaire) sign_in gestionnaire
dossier.updated! dossier.updated!
post :create, params: {dossier_id: dossier_id, texte_commentaire: texte_commentaire} post :create, params: {dossier_id: dossier_id, texte_commentaire: texte_commentaire}
@ -130,3 +149,4 @@ describe Backoffice::CommentairesController, type: :controller do
end end
end end
end end
end

View file

@ -1,18 +1,41 @@
require 'spec_helper' require 'spec_helper'
describe InvitesController, type: :controller do describe InvitesController, type: :controller do
let(:dossier) { create(:dossier) } let(:dossier) { create(:dossier, :replied) }
let(:email) { 'plop@octo.com' } let(:email) { 'plop@octo.com' }
describe '#POST create' do describe '#POST create' do
let(:invite) { Invite.last } let(:invite) { Invite.last }
before do before do
sign_in create(:gestionnaire) sign_in signed_in_profile
end end
subject { post :create, params: {dossier_id: dossier.id, email: email} } subject { post :create, params: {dossier_id: dossier.id, email: email} }
context "when gestionnaire is signed_in" do
let(:signed_in_profile) { create(:gestionnaire) }
shared_examples_for "he can not create invitation" do
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
it { expect { subject rescue nil }.to change(InviteGestionnaire, :count).by(0) }
end
context 'when gestionnaire has no access to dossier' do
it_behaves_like "he can not create invitation"
end
context 'when gestionnaire is invited for avis on dossier' do
before { Avis.create(gestionnaire: signed_in_profile, claimant: create(:gestionnaire), dossier: dossier) }
it_behaves_like "he can not create invitation"
end
context 'when gestionnaire has access to dossier' do
before do
signed_in_profile.procedures << dossier.procedure
end
it { expect { subject }.to change(InviteGestionnaire, :count).by(1) } it { expect { subject }.to change(InviteGestionnaire, :count).by(1) }
context 'when is a user who is loged' do context 'when is a user who is loged' do
@ -101,3 +124,32 @@ describe InvitesController, type: :controller do
end end
end end
end end
context "when user is signed_in" do
let(:signed_in_profile) { create(:user) }
shared_examples_for "he can not create a invite" do
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
it { expect { subject rescue nil }.to change(InviteUser, :count).by(0) }
end
context 'when user has no access to dossier' do
it_behaves_like "he can not create a invite"
end
context 'when user is invited on dossier' do
before { Invite.create(user: signed_in_profile, email: signed_in_profile.email, dossier: dossier) }
it_behaves_like "he can not create a invite"
end
context 'when user has access to dossier' do
before do
dossier.update_attributes(user: signed_in_profile)
end
it { expect { subject }.to change(InviteUser, :count).by(1) }
end
end
end
end

View file

@ -11,6 +11,28 @@ describe Users::CommentairesController, type: :controller do
end end
describe '#POST create' do describe '#POST create' do
context "when user has no access to dossier" do
before do
sign_in create(:user)
end
subject { post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire } }
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
it { expect { subject rescue nil }.to change(Commentaire, :count).by(0) }
end
context "when user is invited on dossier" do
let(:user) { create(:user) }
subject { post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire } }
before do
sign_in user
InviteUser.create(dossier: dossier, user: user, email: user.email, email_sender: "test@test.com")
end
it { expect{ subject }.to change(Commentaire, :count).by(1) }
end
context 'création correct d\'un commentaire' do context 'création correct d\'un commentaire' do
subject do subject do
sign_in dossier.user sign_in dossier.user