From 7e94f7778afd7a7f2e61cdf4103f4070779f9a1d Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 14:43:07 +0100 Subject: [PATCH 01/27] Disable csrf forgery protection in test environement --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a0b353e99..5a8561931 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. - protect_from_forgery with: :exception + protect_from_forgery with: :exception, if: -> { !Rails.env.test? } before_action :load_navbar_left_pannel_partial_url before_action :set_raven_context before_action :authorize_request_for_profiler From e2a2748e794945fbb7027af1ac958aee14bf0528 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 14:44:00 +0100 Subject: [PATCH 02/27] Expose authenticated_logged_user! method --- app/controllers/application_controller.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5a8561931..e1b052a25 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -41,6 +41,16 @@ class ApplicationController < ActionController::Base protected + def authenticate_logged_user! + if gestionnaire_signed_in? + authenticate_gestionnaire! + elsif administrateur_signed_in? + authenticate_administrateur! + else + authenticate_user! + end + end + def authenticate_gestionnaire! if gestionnaire_signed_in? super @@ -80,6 +90,8 @@ class ApplicationController < ActionController::Base logged_users.first end + helper_method :logged_user + def logged_user_roles roles = logged_users.map { |logged_user| logged_user.class.name } roles.any? ? roles.join(', ') : 'Guest' From c49db4b5a416fe5819e90597539da0f1d3dc95bf Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 17:16:29 +0100 Subject: [PATCH 03/27] Add a champs/dossier_link endpoint and use it to fetch dossier info --- .../champs/dossier_link_controller.rb | 11 ++++ app/views/champs/dossier_link/show.js.erb | 3 + .../champs/dossier_link/_help_block.html.haml | 8 +++ .../editable_champs/_dossier_link.html.haml | 15 +---- config/routes.rb | 1 + .../champs/dossier_link_controller_spec.rb | 56 +++++++++++++++++++ 6 files changed, 82 insertions(+), 12 deletions(-) create mode 100644 app/controllers/champs/dossier_link_controller.rb create mode 100644 app/views/champs/dossier_link/show.js.erb create mode 100644 app/views/shared/champs/dossier_link/_help_block.html.haml create mode 100644 spec/controllers/champs/dossier_link_controller_spec.rb diff --git a/app/controllers/champs/dossier_link_controller.rb b/app/controllers/champs/dossier_link_controller.rb new file mode 100644 index 000000000..d4297c733 --- /dev/null +++ b/app/controllers/champs/dossier_link_controller.rb @@ -0,0 +1,11 @@ +class Champs::DossierLinkController < ApplicationController + before_action :authenticate_logged_user! + + def show + if params[:dossier].key?(:champs_attributes) + @dossier_id = params[:dossier][:champs_attributes][params[:position]][:value] + else + @dossier_id = params[:dossier][:champs_private_attributes][params[:position]][:value] + end + end +end diff --git a/app/views/champs/dossier_link/show.js.erb b/app/views/champs/dossier_link/show.js.erb new file mode 100644 index 000000000..d561ee26a --- /dev/null +++ b/app/views/champs/dossier_link/show.js.erb @@ -0,0 +1,3 @@ +<%= render_to_element('.dossier-link .help-block', + partial: 'shared/champs/dossier_link/help_block', + locals: { id: @dossier_id }) %> diff --git a/app/views/shared/champs/dossier_link/_help_block.html.haml b/app/views/shared/champs/dossier_link/_help_block.html.haml new file mode 100644 index 000000000..624dc21c8 --- /dev/null +++ b/app/views/shared/champs/dossier_link/_help_block.html.haml @@ -0,0 +1,8 @@ +- if id.present? + - dossier = logged_user.dossiers.find_by(id: id) + - if dossier.blank? + %p.text-warning + Ce dossier est inconnu + - else + %p.text-info + %span.dossier-text-summary= sanitize(dossier.text_summary) diff --git a/app/views/shared/dossiers/editable_champs/_dossier_link.html.haml b/app/views/shared/dossiers/editable_champs/_dossier_link.html.haml index 72ce494ec..40d830ad8 100644 --- a/app/views/shared/dossiers/editable_champs/_dossier_link.html.haml +++ b/app/views/shared/dossiers/editable_champs/_dossier_link.html.haml @@ -1,18 +1,9 @@ -- dossier = Dossier.find_by(id: champ.value) -- show_text_summary = dossier.present? -- show_warning = !show_text_summary && champ.value.present? -- text_summary = sanitize(dossier&.text_summary) - .dossier-link = form.number_field :value, placeholder: "Numéro de dossier", autocomplete: 'off', - 'data-type': 'dossier-link', - required: champ.mandatory? + required: champ.mandatory?, + data: { remote: true, url: champs_dossier_link_path(form.index) } .help-block - %p.text-info{ style: show_text_summary ? nil : 'display: none;' } - %span.dossier-text-summary= text_summary - - %p.text-warning{ style: show_warning ? nil : 'display: none;' } - Ce dossier est inconnu + = render partial: 'shared/champs/dossier_link/help_block', locals: { id: champ.value } diff --git a/config/routes.rb b/config/routes.rb index cb8855c75..661a47429 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -111,6 +111,7 @@ Rails.application.routes.draw do namespace :champs do get ':champ_id/siret' => 'siret#index', as: 'siret' + get ':position/dossier_link', to: 'dossier_link#show', as: :dossier_link end namespace :commencer do diff --git a/spec/controllers/champs/dossier_link_controller_spec.rb b/spec/controllers/champs/dossier_link_controller_spec.rb new file mode 100644 index 000000000..b01b91c41 --- /dev/null +++ b/spec/controllers/champs/dossier_link_controller_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' + +describe Champs::DossierLinkController, type: :controller do + let(:user) { create(:user) } + let(:procedure) { create(:procedure, :published) } + + describe '#show' do + let(:dossier) { create(:dossier, user: user, procedure: procedure) } + + context 'when user is connected' do + render_views + before { sign_in user } + + let(:params) do + { + dossier: { + champs_attributes: { + '1' => { value: "#{dossier_id}" } + } + }, + position: '1' + } + end + let(:dossier_id) { dossier.id } + + context 'when the dossier exist' do + before { + get :show, params: params, format: 'js' + } + + it 'returns the procedure name' do + expect(response.body).to include('Dossier en brouillon') + expect(response.body).to include(procedure.libelle) + expect(response.body).to include(procedure.organisation) + end + end + + context 'when the dossier does not exist' do + let(:dossier_id) { '13' } + before { + get :show, params: params, format: 'js' + } + + it { expect(response.body).to include('Ce dossier est inconnu') } + end + end + + context 'when user is not connected' do + before { + get :show, params: { position: '1' }, format: 'js' + } + + it { expect(response.code).to eq('401') } + end + end +end From 212dee15655be843b88f7139ec399483f1ef34b3 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 17:16:45 +0100 Subject: [PATCH 04/27] Drop unused js --- .../new_design/champs/dossier-link.js | 42 ------------------- app/javascript/packs/application.js | 1 - 2 files changed, 43 deletions(-) delete mode 100644 app/javascript/new_design/champs/dossier-link.js diff --git a/app/javascript/new_design/champs/dossier-link.js b/app/javascript/new_design/champs/dossier-link.js deleted file mode 100644 index 0a86d53c9..000000000 --- a/app/javascript/new_design/champs/dossier-link.js +++ /dev/null @@ -1,42 +0,0 @@ -import $ from 'jquery'; - -function showNotFound() { - $('.dossier-link .text-info').hide(); - $('.dossier-link .text-warning').show(); -} - -function showData(data) { - $('.dossier-link .dossier-text-summary').text(data.textSummary); - $('.dossier-link .text-info').show(); - $('.dossier-link .text-warning').hide(); -} - -function hideEverything() { - $('.dossier-link .text-info').hide(); - $('.dossier-link .text-warning').hide(); -} - -function fetchProcedureLibelle(e) { - const dossierId = $(e.target).val(); - if (dossierId) { - $.get(`/users/dossiers/${dossierId}/text_summary`) - .done(showData) - .fail(showNotFound); - } else { - hideEverything(); - } -} - -let timeOut; -function debounceFetchProcedureLibelle(e) { - if (timeOut) { - clearTimeout(timeOut); - } - timeOut = setTimeout(() => fetchProcedureLibelle(e), 300); -} - -$(document).on( - 'input', - '[data-type=dossier-link]', - debounceFetchProcedureLibelle -); diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index 64c5c01c7..971840e3a 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -21,7 +21,6 @@ import '../new_design/form-validation'; import '../new_design/carto'; import '../new_design/select2'; -import '../new_design/champs/dossier-link'; import '../new_design/champs/linked-drop-down-list'; import '../new_design/champs/siret'; From f3333595a0f4148ca1c5b6a98442dda3b81088bd Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 17:17:12 +0100 Subject: [PATCH 05/27] Drop text_summary endpoint --- app/controllers/users/dossiers_controller.rb | 7 ------ config/routes.rb | 2 -- .../users/dossiers_controller_spec.rb | 25 ------------------- 3 files changed, 34 deletions(-) diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 06d1ec4eb..9349d72d5 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -162,13 +162,6 @@ class Users::DossiersController < UsersController redirect_to url_for dossiers_path end - def text_summary - dossier = Dossier.find(params[:dossier_id]) - render json: { textSummary: dossier.text_summary } - rescue ActiveRecord::RecordNotFound - render json: {}, status: 404 - end - private def check_siret diff --git a/config/routes.rb b/config/routes.rb index 661a47429..78a27debe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -159,8 +159,6 @@ Rails.application.routes.draw do post '/siret_informations' => 'dossiers#siret_informations' put '/change_siret' => 'dossiers#change_siret' - - get 'text_summary' => 'dossiers#text_summary' end resource 'dossiers' diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 8a518d099..5161cb779 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -446,29 +446,4 @@ describe Users::DossiersController, type: :controller do subject end end - - describe 'Get #text_summary' do - let!(:dossier) { create(:dossier, procedure: procedure) } - - context 'when user is connected' do - before { sign_in user } - - context 'when the dossier exist' do - before { get :text_summary, params: { dossier_id: dossier.id } } - it 'returns the procedure name' do - expect(JSON.parse(response.body)).to eq("textSummary" => "Dossier en brouillon répondant à la démarche #{procedure.libelle} gérée par l'organisme #{procedure.organisation}") - end - end - - context 'when the dossier does not exist' do - before { get :text_summary, params: { dossier_id: 666 } } - it { expect(response.code).to eq('404') } - end - end - - context 'when user is not connected' do - before { get :text_summary, params: { dossier_id: dossier.id } } - it { expect(response.code).to eq('302') } - end - end end From b63038facae0bc8bf31edda8a077b97c10e59bb7 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 17:17:51 +0100 Subject: [PATCH 06/27] =?UTF-8?q?Allow=20administrateur=20to=20try=20dossi?= =?UTF-8?q?er=20info=20on=20aper=C3=A7u=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/administrateur.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/administrateur.rb b/app/models/administrateur.rb index 37242cb4b..f45bb1447 100644 --- a/app/models/administrateur.rb +++ b/app/models/administrateur.rb @@ -10,6 +10,7 @@ class Administrateur < ApplicationRecord has_many :administrateurs_procedures has_many :admin_procedures, through: :administrateurs_procedures, source: :procedure has_many :services + has_many :dossiers, -> { state_not_brouillon }, through: :procedures before_validation -> { sanitize_email(:email) } before_save :ensure_api_token From e2091fabdf2fc2e4c28fae582afed713660dcac6 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 6 Sep 2018 18:22:03 +0200 Subject: [PATCH 07/27] Unscope .messages-list --- .../stylesheets/new_design/messagerie.scss | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/app/assets/stylesheets/new_design/messagerie.scss b/app/assets/stylesheets/new_design/messagerie.scss index 74102f1c7..6e575540b 100644 --- a/app/assets/stylesheets/new_design/messagerie.scss +++ b/app/assets/stylesheets/new_design/messagerie.scss @@ -2,31 +2,31 @@ @import "common"; @import "constants"; -.messagerie { - .messages-list { - max-height: 350px; - overflow-y: scroll; - border: 1px solid $border-grey; - background: $light-grey; - padding: 2 * $default-spacer; - margin-bottom: $default-spacer; - border-radius: 4px; +.messages-list { + max-height: 350px; + overflow-y: scroll; + border: 1px solid $border-grey; + background: $light-grey; + padding: 2 * $default-spacer; + margin-bottom: $default-spacer; + border-radius: 4px; - > li { - display: flex; - align-items: flex-start; - margin-bottom: $default-padding; - padding: $default-padding; - background: #FFFFFF; - width: 80%; - border-radius: 3px; + > li { + display: flex; + align-items: flex-start; + margin-bottom: $default-padding; + padding: $default-padding; + background: #FFFFFF; + width: 80%; + border-radius: 3px; - &.from-me { - margin-left: auto; - } + &.from-me { + margin-left: auto; } } +} +.messagerie { .person-icon { margin-right: $default-spacer; } From 94e5f856d323a5bcf14611522d4394ddafd47a61 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 6 Sep 2018 18:40:47 +0200 Subject: [PATCH 08/27] Extract some CSS in a .message class --- .../stylesheets/new_design/messagerie.scss | 22 +++++++++---------- app/assets/stylesheets/new_design/print.scss | 8 +++---- .../shared/dossiers/_messagerie.html.haml | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/assets/stylesheets/new_design/messagerie.scss b/app/assets/stylesheets/new_design/messagerie.scss index 6e575540b..b44c180bc 100644 --- a/app/assets/stylesheets/new_design/messagerie.scss +++ b/app/assets/stylesheets/new_design/messagerie.scss @@ -10,19 +10,19 @@ padding: 2 * $default-spacer; margin-bottom: $default-spacer; border-radius: 4px; +} - > li { - display: flex; - align-items: flex-start; - margin-bottom: $default-padding; - padding: $default-padding; - background: #FFFFFF; - width: 80%; - border-radius: 3px; +.message { + display: flex; + align-items: flex-start; + margin-bottom: $default-padding; + padding: $default-padding; + background: #FFFFFF; + width: 80%; + border-radius: 3px; - &.from-me { - margin-left: auto; - } + &.from-me { + margin-left: auto; } } diff --git a/app/assets/stylesheets/new_design/print.scss b/app/assets/stylesheets/new_design/print.scss index 0a62ad243..2a6ebd178 100644 --- a/app/assets/stylesheets/new_design/print.scss +++ b/app/assets/stylesheets/new_design/print.scss @@ -44,10 +44,6 @@ th { padding-left: 0; max-height: none; - li { - margin-bottom: 40px; - } - h2 { font-size: 110%; } @@ -58,6 +54,10 @@ th { } } +.message { + margin-bottom: 40px; +} + .updated-at { display: none; } diff --git a/app/views/shared/dossiers/_messagerie.html.haml b/app/views/shared/dossiers/_messagerie.html.haml index be8414010..ee380ee09 100644 --- a/app/views/shared/dossiers/_messagerie.html.haml +++ b/app/views/shared/dossiers/_messagerie.html.haml @@ -1,7 +1,7 @@ .messagerie.container %ul.messages-list - dossier.commentaires.each do |commentaire| - %li{ class: commentaire_is_from_me_class(commentaire, user_email) } + %li.message{ class: commentaire_is_from_me_class(commentaire, user_email) } = render partial: "shared/dossiers/messages/message", locals: { commentaire: commentaire, user_email: user_email, messagerie_seen_at: messagerie_seen_at } = render partial: "shared/dossiers/messages/form", locals: { commentaire: new_commentaire, form_url: form_url } From a4367c080905b3903845b3bea846f6279c3fa885 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 6 Sep 2018 18:28:13 +0200 Subject: [PATCH 09/27] Extract some more CSS classes from .messagerie to .messagge --- app/assets/stylesheets/new_design/messagerie.scss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/new_design/messagerie.scss b/app/assets/stylesheets/new_design/messagerie.scss index b44c180bc..29979cf13 100644 --- a/app/assets/stylesheets/new_design/messagerie.scss +++ b/app/assets/stylesheets/new_design/messagerie.scss @@ -24,9 +24,7 @@ &.from-me { margin-left: auto; } -} -.messagerie { .person-icon { margin-right: $default-spacer; } @@ -52,7 +50,9 @@ .attachment-link { margin-top: $default-spacer; } +} +.messagerie { .message-textarea { margin-bottom: $default-spacer; } From 7482b859d5eb54e7cf4066a80eb18d20f7c2e3a9 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 6 Sep 2018 18:29:04 +0200 Subject: [PATCH 10/27] Extract the message class into its own file --- .../stylesheets/new_design/message.scss | 42 +++++++++++++++++++ .../stylesheets/new_design/messagerie.scss | 40 ------------------ 2 files changed, 42 insertions(+), 40 deletions(-) create mode 100644 app/assets/stylesheets/new_design/message.scss diff --git a/app/assets/stylesheets/new_design/message.scss b/app/assets/stylesheets/new_design/message.scss new file mode 100644 index 000000000..97b008951 --- /dev/null +++ b/app/assets/stylesheets/new_design/message.scss @@ -0,0 +1,42 @@ +@import "colors"; +@import "constants"; + +.message { + display: flex; + align-items: flex-start; + margin-bottom: $default-padding; + padding: $default-padding; + background: #FFFFFF; + width: 80%; + border-radius: 3px; + + &.from-me { + margin-left: auto; + } + + .person-icon { + margin-right: $default-spacer; + } + + h2 { + margin-bottom: $default-spacer; + } + + .mail { + font-weight: bold; + } + + .guest, + .date { + font-size: 12px; + color: $grey; + } + + .date { + float: right; + } + + .attachment-link { + margin-top: $default-spacer; + } +} diff --git a/app/assets/stylesheets/new_design/messagerie.scss b/app/assets/stylesheets/new_design/messagerie.scss index 29979cf13..29a24600f 100644 --- a/app/assets/stylesheets/new_design/messagerie.scss +++ b/app/assets/stylesheets/new_design/messagerie.scss @@ -12,46 +12,6 @@ border-radius: 4px; } -.message { - display: flex; - align-items: flex-start; - margin-bottom: $default-padding; - padding: $default-padding; - background: #FFFFFF; - width: 80%; - border-radius: 3px; - - &.from-me { - margin-left: auto; - } - - .person-icon { - margin-right: $default-spacer; - } - - h2 { - margin-bottom: $default-spacer; - } - - .mail { - font-weight: bold; - } - - .guest, - .date { - font-size: 12px; - color: $grey; - } - - .date { - float: right; - } - - .attachment-link { - margin-top: $default-spacer; - } -} - .messagerie { .message-textarea { margin-bottom: $default-spacer; From afae82c5baa8950cb6de464d0fe2b2f1d6350cb7 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 6 Sep 2018 18:49:02 +0200 Subject: [PATCH 11/27] Remove a useless import in messagerie.scss --- app/assets/stylesheets/new_design/messagerie.scss | 1 - 1 file changed, 1 deletion(-) diff --git a/app/assets/stylesheets/new_design/messagerie.scss b/app/assets/stylesheets/new_design/messagerie.scss index 29a24600f..89a5e40a5 100644 --- a/app/assets/stylesheets/new_design/messagerie.scss +++ b/app/assets/stylesheets/new_design/messagerie.scss @@ -1,5 +1,4 @@ @import "colors"; -@import "common"; @import "constants"; .messages-list { From 6a475981e3efdae140ead06ffd3f5cad30d4b200 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 7 Sep 2018 20:10:22 +0200 Subject: [PATCH 12/27] The relative message width is only relevant in messages-list --- app/assets/stylesheets/new_design/message.scss | 1 - app/assets/stylesheets/new_design/messagerie.scss | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/new_design/message.scss b/app/assets/stylesheets/new_design/message.scss index 97b008951..d38a946cd 100644 --- a/app/assets/stylesheets/new_design/message.scss +++ b/app/assets/stylesheets/new_design/message.scss @@ -7,7 +7,6 @@ margin-bottom: $default-padding; padding: $default-padding; background: #FFFFFF; - width: 80%; border-radius: 3px; &.from-me { diff --git a/app/assets/stylesheets/new_design/messagerie.scss b/app/assets/stylesheets/new_design/messagerie.scss index 89a5e40a5..2367fe0fc 100644 --- a/app/assets/stylesheets/new_design/messagerie.scss +++ b/app/assets/stylesheets/new_design/messagerie.scss @@ -9,6 +9,10 @@ padding: 2 * $default-spacer; margin-bottom: $default-spacer; border-radius: 4px; + + .message { + width: 80%; + } } .messagerie { From ce458764f1c0892b8590e980ba5386f59696e23a Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 7 Sep 2018 20:13:45 +0200 Subject: [PATCH 13/27] from-me is only relevant when the message is in a messages-list --- app/assets/stylesheets/new_design/message.scss | 4 ---- app/assets/stylesheets/new_design/messagerie.scss | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/new_design/message.scss b/app/assets/stylesheets/new_design/message.scss index d38a946cd..025a7783e 100644 --- a/app/assets/stylesheets/new_design/message.scss +++ b/app/assets/stylesheets/new_design/message.scss @@ -9,10 +9,6 @@ background: #FFFFFF; border-radius: 3px; - &.from-me { - margin-left: auto; - } - .person-icon { margin-right: $default-spacer; } diff --git a/app/assets/stylesheets/new_design/messagerie.scss b/app/assets/stylesheets/new_design/messagerie.scss index 2367fe0fc..c8fe54379 100644 --- a/app/assets/stylesheets/new_design/messagerie.scss +++ b/app/assets/stylesheets/new_design/messagerie.scss @@ -12,6 +12,10 @@ .message { width: 80%; + + &.from-me { + margin-left: auto; + } } } From d504af321657c27c2e7fc940a02393afd89a1c1d Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 10 Sep 2018 20:19:03 +0200 Subject: [PATCH 14/27] FeedbacksController should inherit from UserController --- app/controllers/new_user/feedbacks_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/new_user/feedbacks_controller.rb b/app/controllers/new_user/feedbacks_controller.rb index 3c7b391da..9ec9b97bc 100644 --- a/app/controllers/new_user/feedbacks_controller.rb +++ b/app/controllers/new_user/feedbacks_controller.rb @@ -1,4 +1,4 @@ -class NewUser::FeedbacksController < ApplicationController +class NewUser::FeedbacksController < UserController def create current_user.feedbacks.create!(rating: params[:rating]) flash.notice = "Merci de votre retour, si vous souhaitez nous en dire plus, n'hésitez pas à #{view_context.contact_link('nous contacter', type: Helpscout::FormAdapter::TYPE_AMELIORATION)}." From 05d2988f610b55cdf90e1e3c2c9c8f5182c26893 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 10 Sep 2018 20:20:58 +0200 Subject: [PATCH 15/27] Format FeedbackController like the other controllers --- app/controllers/new_user/feedbacks_controller.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/new_user/feedbacks_controller.rb b/app/controllers/new_user/feedbacks_controller.rb index 9ec9b97bc..40ec33f80 100644 --- a/app/controllers/new_user/feedbacks_controller.rb +++ b/app/controllers/new_user/feedbacks_controller.rb @@ -1,6 +1,8 @@ -class NewUser::FeedbacksController < UserController - def create - current_user.feedbacks.create!(rating: params[:rating]) - flash.notice = "Merci de votre retour, si vous souhaitez nous en dire plus, n'hésitez pas à #{view_context.contact_link('nous contacter', type: Helpscout::FormAdapter::TYPE_AMELIORATION)}." +module NewUser + class FeedbacksController < UserController + def create + current_user.feedbacks.create!(rating: params[:rating]) + flash.notice = "Merci de votre retour, si vous souhaitez nous en dire plus, n'hésitez pas à #{view_context.contact_link('nous contacter', type: Helpscout::FormAdapter::TYPE_AMELIORATION)}." + end end end From 26e0ada3d4a5dd66c9e11135d8d9b3034d0209e2 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Sun, 9 Sep 2018 23:04:00 +0200 Subject: [PATCH 16/27] Improve the ratings stats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure that for each data point, we have do not have any partial data (e.g. a week that hasn’t finished yet) --- app/controllers/stats_controller.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 6a183433a..73a7dbef7 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -129,12 +129,16 @@ class StatsController < ApplicationController Feedback.ratings.fetch(:neutral) => "Neutres", Feedback.ratings.fetch(:unhappy) => "Mécontents" } + interval = 6.weeks.ago.beginning_of_week..1.week.ago.beginning_of_week - totals = Feedback.where(created_at: 5.weeks.ago..Time.now).group_by_week(:created_at).count + totals = Feedback + .where(created_at: interval) + .group_by_week(:created_at) + .count Feedback.ratings.values.map do |rating| data = Feedback - .where(created_at: 5.weeks.ago..Time.now, rating: rating) + .where(created_at: interval, rating: rating) .group_by_week(:created_at) .count .map do |week, count| From 50019e5317863f774ded766f69e8bf6a297f913b Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 10 Sep 2018 14:04:59 +0200 Subject: [PATCH 17/27] Show user satisfaction in percentages --- app/controllers/stats_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 73a7dbef7..4d2c54ee5 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -145,7 +145,7 @@ class StatsController < ApplicationController total = totals[week] if total > 0 - [week, (count.to_f / total).round(2)] + [week, (count.to_f / total * 100).round(2)] else 0 end From de908ef4be3cd59d3586838fba72f9abd2f56e8e Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 17:28:27 +0100 Subject: [PATCH 18/27] Extract ProcedurePath#find_by_path --- app/controllers/admin/procedures_controller.rb | 5 +---- app/models/procedure_path.rb | 7 +++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 2d24d5c65..fe4309449 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -205,10 +205,7 @@ class Admin::ProceduresController < AdminController def path_list json_path_list = ProcedurePath - .joins(:procedure) - .where(procedures: { archived_at: nil }) - .where("path LIKE ?", "%#{params[:request]}%") - .order(:id) + .find_with_path(params[:request]) .pluck(:path, :administrateur_id) .map do |path, administrateur_id| { diff --git a/app/models/procedure_path.rb b/app/models/procedure_path.rb index 197162224..418e74345 100644 --- a/app/models/procedure_path.rb +++ b/app/models/procedure_path.rb @@ -6,6 +6,13 @@ class ProcedurePath < ApplicationRecord belongs_to :procedure belongs_to :administrateur + def self.find_with_path(path) + joins(:procedure) + .where.not(procedures: { aasm_state: :archivee }) + .where("path LIKE ?", "%#{path}%") + .order(:id) + end + def hide! destroy! end From 7a322266fa10c2a439047c3520e4f9a2b05661c7 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 17:36:31 +0100 Subject: [PATCH 19/27] Make aasm related methods private --- app/models/procedure.rb | 72 ++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index d508e64fa..8c1089591 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -84,33 +84,6 @@ class Procedure < ApplicationRecord end end - def after_publish(path) - now = Time.now - update( - test_started_at: now, - archived_at: nil, - published_at: now - ) - procedure_path = ProcedurePath.find_by(path: path) - - if procedure_path.present? - procedure_path.publish!(self) - else - ProcedurePath.create(procedure: self, administrateur: administrateur, path: path) - end - end - - def after_archive - update(archived_at: Time.now) - end - - def after_hide - now = Time.now - update(hidden_at: now) - procedure_path&.hide! - dossiers.update_all(hidden_at: now) - end - def reset! if locked? raise "Can not reset a locked procedure." @@ -132,15 +105,6 @@ class Procedure < ApplicationRecord publiee? || archivee? end - def can_publish?(path) - procedure_path = ProcedurePath.find_by(path: path) - if procedure_path.present? - administrateur.owns?(procedure_path) - else - true - end - end - # Warning: dossier after_save build_default_champs must be removed # to save a dossier created from this method def new_dossier @@ -372,6 +336,42 @@ class Procedure < ApplicationRecord private + def can_publish?(path) + procedure_path = ProcedurePath.find_by(path: path) + if procedure_path.present? + administrateur.owns?(procedure_path) + else + true + end + end + + def after_publish(path) + now = Time.now + update( + test_started_at: now, + archived_at: nil, + published_at: now + ) + procedure_path = ProcedurePath.find_by(path: path) + + if procedure_path.present? + procedure_path.publish!(self) + else + ProcedurePath.create(procedure: self, administrateur: administrateur, path: path) + end + end + + def after_archive + update(archived_at: Time.now) + end + + def after_hide + now = Time.now + update(hidden_at: now) + procedure_path&.hide! + dossiers.update_all(hidden_at: now) + end + def update_juridique_required self.juridique_required ||= (cadre_juridique.present? || deliberation.attached?) true From f2f3c541476abe4dbf5c776f73cc9c3f43c24711 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 17:38:24 +0100 Subject: [PATCH 20/27] Procedure: update -> update! --- app/models/procedure.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 8c1089591..e7b88963f 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -362,12 +362,12 @@ class Procedure < ApplicationRecord end def after_archive - update(archived_at: Time.now) + update!(archived_at: Time.now) end def after_hide now = Time.now - update(hidden_at: now) + update!(hidden_at: now) procedure_path&.hide! dossiers.update_all(hidden_at: now) end From e6485603c4412d67a0c51e7dfb6dc6efa7bd21b9 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 17:39:41 +0100 Subject: [PATCH 21/27] Add ProcedurePath#valid? --- app/controllers/admin/procedures_controller.rb | 12 +----------- app/models/procedure_path.rb | 5 +++++ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index fe4309449..a413e3d4d 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -94,17 +94,7 @@ class Admin::ProceduresController < AdminController def publish procedure = current_administrateur.procedures.find(params[:procedure_id]) - new_procedure_path = ProcedurePath.new( - { - path: params[:procedure_path], - procedure: procedure, - administrateur: procedure.administrateur - } - ) - - if new_procedure_path.validate - new_procedure_path.delete - else + if !ProcedurePath.valid?(procedure, params[:procedure_path]) flash.alert = 'Lien de la démarche invalide' return redirect_to admin_procedures_path end diff --git a/app/models/procedure_path.rb b/app/models/procedure_path.rb index 418e74345..77a6e9403 100644 --- a/app/models/procedure_path.rb +++ b/app/models/procedure_path.rb @@ -6,6 +6,11 @@ class ProcedurePath < ApplicationRecord belongs_to :procedure belongs_to :administrateur + def self.valid?(procedure, path) + create_with(procedure: procedure, administrateur: procedure.administrateur) + .find_or_initialize_by(path: path).validate + end + def self.find_with_path(path) joins(:procedure) .where.not(procedures: { aasm_state: :archivee }) From b3f8b68b99d46ad16fbb1d490353c16a5fc3b678 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 17:40:36 +0100 Subject: [PATCH 22/27] Add Procedure#publish_with_path! --- app/models/procedure.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index e7b88963f..82bb56f7b 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -84,6 +84,18 @@ class Procedure < ApplicationRecord end end + def publish_with_path!(path) + procedure_path = ProcedurePath + .where(administrateur: administrateur) + .find_by(path: path) + + if procedure_path.present? + procedure_path.publish!(self) + else + create_procedure_path!(administrateur: administrateur, path: path) + end + end + def reset! if locked? raise "Can not reset a locked procedure." From ec3a0dc4cfb84151b9efc3b6f868feb25e33bb83 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 17:41:48 +0100 Subject: [PATCH 23/27] Use Procedure#publish_with_path! --- app/models/procedure.rb | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 82bb56f7b..383488beb 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -358,19 +358,9 @@ class Procedure < ApplicationRecord end def after_publish(path) - now = Time.now - update( - test_started_at: now, - archived_at: nil, - published_at: now - ) - procedure_path = ProcedurePath.find_by(path: path) + update!(published_at: Time.now) - if procedure_path.present? - procedure_path.publish!(self) - else - ProcedurePath.create(procedure: self, administrateur: administrateur, path: path) - end + publish_with_path!(path) end def after_archive From 5a794cbb08cfd43c5b3e08f81a702eecb41c7ab6 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 17:42:12 +0100 Subject: [PATCH 24/27] Use Procedure#publish_or_reopen! --- app/controllers/admin/procedures_controller.rb | 4 +--- app/models/procedure.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index a413e3d4d..6532cc3a3 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -99,9 +99,7 @@ class Admin::ProceduresController < AdminController return redirect_to admin_procedures_path end - if procedure.may_publish?(params[:procedure_path]) - procedure.publish!(params[:procedure_path]) - + if procedure.publish_or_reopen!(params[:procedure_path]) flash.notice = "Démarche publiée" redirect_to admin_procedures_path else diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 383488beb..85b5d7282 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -84,6 +84,15 @@ class Procedure < ApplicationRecord end end + def publish_or_reopen!(path) + if archivee? && may_reopen?(path) + reopen!(path) + elsif may_publish?(path) + reset! + publish!(path) + end + end + def publish_with_path!(path) procedure_path = ProcedurePath .where(administrateur: administrateur) From be518029838624f6d3e66730ea86d32626f4d612 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 17:37:44 +0100 Subject: [PATCH 25/27] Add reopen aasm event --- app/models/procedure.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 85b5d7282..79f432ee6 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -70,6 +70,9 @@ class Procedure < ApplicationRecord event :publish, after: :after_publish, guard: :can_publish? do transitions from: :brouillon, to: :publiee + end + + event :reopen, after: :after_reopen, guard: :can_publish? do transitions from: :archivee, to: :publiee end @@ -383,6 +386,12 @@ class Procedure < ApplicationRecord dossiers.update_all(hidden_at: now) end + def after_reopen(path) + update!(published_at: Time.now, archived_at: nil) + + publish_with_path!(path) + end + def update_juridique_required self.juridique_required ||= (cadre_juridique.present? || deliberation.attached?) true From 2770f1db82634b9060df0fcfe6579eb9a9a92cd1 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 17:43:21 +0100 Subject: [PATCH 26/27] Archive only when path changes owner --- app/models/procedure_path.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/procedure_path.rb b/app/models/procedure_path.rb index 77a6e9403..07665a5b5 100644 --- a/app/models/procedure_path.rb +++ b/app/models/procedure_path.rb @@ -23,7 +23,7 @@ class ProcedurePath < ApplicationRecord end def publish!(new_procedure) - if procedure&.publiee? + if procedure&.publiee? && procedure != new_procedure procedure.archive! end update!(procedure: new_procedure) From 631df3197ab15cd48ac5e34b03ccde33867d7e46 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 17:43:37 +0100 Subject: [PATCH 27/27] Add uniqueness validation to procedure path --- app/models/procedure_path.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/procedure_path.rb b/app/models/procedure_path.rb index 07665a5b5..7bab10680 100644 --- a/app/models/procedure_path.rb +++ b/app/models/procedure_path.rb @@ -1,5 +1,5 @@ class ProcedurePath < ApplicationRecord - validates :path, format: { with: /\A[a-z0-9_\-]{3,50}\z/ }, presence: true, allow_blank: false, allow_nil: false + validates :path, format: { with: /\A[a-z0-9_\-]{3,50}\z/ }, uniqueness: true, presence: true, allow_blank: false, allow_nil: false validates :administrateur_id, presence: true, allow_blank: false, allow_nil: false validates :procedure_id, presence: true, allow_blank: false, allow_nil: false