Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
gregoirenovel committed Aug 30, 2018
2 parents 7bbd5d7 + d8a91bf commit e5df2e4
Show file tree
Hide file tree
Showing 112 changed files with 1,332 additions and 387 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ L'application tourne à l'adresse `http://localhost:3000`. Un utilisateur de tes

AutoArchiveProcedureJob.set(cron: "* * * * *").perform_later
WeeklyOverviewJob.set(cron: "0 8 * * 0").perform_later
AutoReceiveDossiersForProcedureJob.set(cron: "* * * * *").perform_later(procedure_declaratoire_id, 'en_instruction')
AutoReceiveDossiersForProcedureJob.set(cron: "* * * * *").perform_later(procedure_declaratoire_id, Dossier.states.fetch(:en_instruction))
FindDubiousProceduresJob.set(cron: "0 0 * * *").perform_later
Administrateurs::ActivateBeforeExpirationJob.set(cron: "0 8 * * *").perform_later

Expand Down
12 changes: 12 additions & 0 deletions app/assets/stylesheets/new_design/contact.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$default-space: 15px;
$contact-padding: $default-space * 2;

#contact-form {
width: 1040px;
margin: 0 auto;
padding-top: $contact-padding;

.description {
padding-bottom: $contact-padding;
}
}
8 changes: 8 additions & 0 deletions app/assets/stylesheets/new_design/stats.scss
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ $big-number-card-padding: 2 * $segmented-control-item-border-radius;
display: block;
text-align: center;
margin: 0 auto;
margin-bottom: 20px;
color: $light-grey;
}

Expand All @@ -137,3 +138,10 @@ $big-number-card-padding: 2 * $segmented-control-item-border-radius;
font-weight: bold;
color: $blue;
}

.big-number-card-detail {
display: block;
text-align: center;
color: $blue;
}

2 changes: 1 addition & 1 deletion app/controllers/admin/procedures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def hide
procedure = current_administrateur.procedures.find(params[:id])
procedure.hide!

flash.notice = "Procédure supprimée, en cas d'erreur contactez nous : #{CONTACT_EMAIL}"
flash.notice = "Procédure supprimée, en cas d'erreur #{view_context.contact_link('contactez nous', tags: 'procédure supprimée')}"
redirect_to admin_procedures_draft_path
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/administrateurs/activate_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def new
@administrateur = Administrateur.find_inactive_by_token(params[:token])

if !@administrateur
flash.alert = "Le lien de validation d'administrateur a expiré, contactez-nous à #{CONTACT_EMAIL} pour obtenir un nouveau lien."
flash.alert = "Le lien de validation d'administrateur a expiré, #{view_context.contact_link('contactez-nous', tags: 'lien expiré')} pour obtenir un nouveau lien."
redirect_to root_path
end
end
Expand Down
18 changes: 0 additions & 18 deletions app/controllers/api/statistiques_controller.rb

This file was deleted.

6 changes: 6 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def load_navbar_left_pannel_partial_url
@facade_data_view = nil
end

def logged_in?
logged_user.present?
end

helper_method :logged_in?

protected

def authenticate_gestionnaire!
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/france_connect/particulier_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def connect_france_connect_particulier(user)

sign_in user

user.update_attribute('loged_in_with_france_connect', 'particulier')
user.update_attribute('loged_in_with_france_connect', User.loged_in_with_france_connects.fetch(:particulier))

redirect_to stored_location_for(current_user) || root_path(current_user)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/gestionnaires/activate_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def new
@gestionnaire = Gestionnaire.with_reset_password_token(params[:token])

if !@gestionnaire
flash.alert = "Le lien de validation du compte accompagnateur a expiré, contactez-nous à #{CONTACT_EMAIL} pour obtenir un nouveau lien."
flash.alert = "Le lien de validation du compte accompagnateur a expiré, #{view_context.contact_link('contactez-nous', tags: 'lien expiré')} pour obtenir un nouveau lien."
redirect_to root_path
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/manager/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def scoped_resource

def change_state_to_instruction
dossier = Dossier.find(params[:id])
dossier.update(state: 'en_instruction', processed_at: nil, motivation: nil)
dossier.update(state: Dossier.states.fetch(:en_instruction), processed_at: nil, motivation: nil)
dossier.attestation&.destroy
logger.info("Le dossier #{dossier.id} est repassé en instruction par #{current_administration.email}")
flash[:notice] = "Le dossier #{dossier.id} est repassé en instruction"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/new_user/feedbacks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class NewUser::FeedbacksController < ApplicationController
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 à <a href='mailto:#{CONTACT_EMAIL}' target='_blank'>nous contacter par email</a>."
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
10 changes: 5 additions & 5 deletions app/controllers/root_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def patron
.map.with_index { |type_de_champ, i| type_de_champ.champ.build(id: i) }

all_champs
.select { |champ| champ.type_champ == 'header_section' }
.select { |champ| champ.type_champ == TypeDeChamp.type_champs.fetch(:header_section) }
.each { |champ| champ.type_de_champ.libelle = 'un super titre de section' }

all_champs
.select { |champ| %w(drop_down_list multiple_drop_down_list).include?(champ.type_champ) }
.select { |champ| [TypeDeChamp.type_champs.fetch(:drop_down_list), TypeDeChamp.type_champs.fetch(:multiple_drop_down_list)].include?(champ.type_champ) }
.each do |champ|
champ.type_de_champ.drop_down_list = DropDownList.new(type_de_champ: champ.type_de_champ)
champ.drop_down_list.value =
Expand All @@ -42,9 +42,9 @@ def patron
end

type_champ_values = {
'date': '2016-07-26',
'datetime': '26/07/2016 07:35',
'textarea': 'Une description de mon projet'
TypeDeChamp.type_champs.fetch(:date) => '2016-07-26',
TypeDeChamp.type_champs.fetch(:datetime) => '26/07/2016 07:35',
TypeDeChamp.type_champs.fetch(:textarea) => 'Une description de mon projet'
}

type_champ_values.each do |(type_champ, value)|
Expand Down
34 changes: 31 additions & 3 deletions app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class StatsController < ApplicationController

def index
procedures = Procedure.publiees_ou_archivees
dossiers = Dossier.where.not(:state => :brouillon)
dossiers = Dossier.where.not(:state => Dossier.states.fetch(:brouillon))

@procedures_count = procedures.count
@dossiers_count = dossiers.count
@procedures_numbers = procedures_numbers(procedures)
@dossiers_numbers = dossiers_numbers(dossiers)

@satisfaction_usagers = satisfaction_usagers
@dossiers_states = dossiers_states
Expand Down Expand Up @@ -78,6 +78,34 @@ def download

private

def procedures_numbers(procedures)
total = procedures.count
last_30_days_count = procedures.where(published_at: 1.month.ago..Time.now).count
previous_count = procedures.where(published_at: 2.months.ago..1.month.ago).count
evolution = (((last_30_days_count.to_f / previous_count) - 1) * 100).round(0)
formatted_evolution = sprintf("%+d", evolution)

{
total: total.to_s,
last_30_days_count: last_30_days_count.to_s,
evolution: formatted_evolution
}
end

def dossiers_numbers(dossiers)
total = dossiers.count
last_30_days_count = dossiers.where(en_construction_at: 1.month.ago..Time.now).count
previous_count = dossiers.where(en_construction_at: 2.months.ago..1.month.ago).count
evolution = (((last_30_days_count.to_f / previous_count) - 1) * 100).round(0)
formatted_evolution = sprintf("%+d", evolution)

{
total: total.to_s,
last_30_days_count: last_30_days_count.to_s,
evolution: formatted_evolution
}
end

def dossiers_states
{
'Brouilllon' => Dossier.state_brouillon.count,
Expand Down
75 changes: 75 additions & 0 deletions app/controllers/support_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
class SupportController < ApplicationController
layout "new_application"

def index
setup_context
end

def create
if direct_message? && create_commentaire
flash.notice = "Votre message a été envoyé sur la messagerie de votre dossier."

redirect_to users_dossier_recapitulatif_path(dossier)
elsif create_conversation
flash.notice = "Votre message a été envoyé."

redirect_to root_path
else
setup_context
flash.now.alert = "Une erreur est survenue. Vous pouvez nous contactez à #{CONTACT_EMAIL}."

render :index
end
end

private

def setup_context
@dossier_id = dossier&.id
@type = params[:type]
@tags = params[:tags]
@options = Helpscout::FormAdapter::OPTIONS
end

def create_conversation
Helpscout::FormAdapter.new(
subject: params[:subject],
email: email,
text: params[:text],
file: params[:file],
dossier_id: dossier&.id,
browser: browser_name,
tags: tags
).send_form
end

def create_commentaire
dossier.commentaires.create(
email: email,
file: params[:file],
body: "[#{params[:subject]}]<br><br>#{params[:text]}"
)
end

def tags
[params[:tags], params[:type]].flatten.compact
end

def browser_name
if browser.known?
"#{browser.name} #{browser.version} (#{browser.platform.name})"
end
end

def direct_message?
user_signed_in? && params[:type] == Helpscout::FormAdapter::TYPE_INSTRUCTION && dossier.present?
end

def dossier
@dossier ||= current_user&.dossiers&.find_by(id: params[:dossier_id])
end

def email
logged_user ? logged_user.email : params[:email]
end
end
2 changes: 1 addition & 1 deletion app/controllers/users/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def new
procedure = Procedure.publiees.find(params[:procedure_id])
end

dossier = Dossier.create!(procedure: procedure, user: current_user, state: 'brouillon')
dossier = Dossier.create!(procedure: procedure, user: current_user, state: Dossier.states.fetch(:brouillon))
siret = params[:siret] || current_user.siret

update_current_user_siret! siret if siret.present?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def destroy
sign_out :user

case connected_with_france_connect
when 'particulier'
when User.loged_in_with_france_connects.fetch(:particulier)
redirect_to FRANCE_CONNECT[:particulier][:logout_endpoint]
return
end
Expand Down
50 changes: 50 additions & 0 deletions app/controllers/webhook_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class WebhookController < ActionController::Base
before_action :verify_signature!, only: :helpscout

def helpscout
email = params[:customer][:email]
user = User.find_by(email: email)
gestionnaire = Gestionnaire.find_by(email: email)
administrateur = Administrateur.find_by(email: email)
html = []

if user
url = view_context.manager_user_url(user)
html << link_to_manager(user, url)
end

if gestionnaire
url = view_context.manager_gestionnaire_url(gestionnaire)
html << link_to_manager(gestionnaire, url)
end

if administrateur
url = view_context.manager_administrateur_url(administrateur)
html << link_to_manager(administrateur, url)
end

if html.empty?
head :not_found
else
render json: { html: html.join('<br>') }
end
end

private

def link_to_manager(model, url)
"<a target='_blank' href='#{url}'>#{model.model_name.human}##{model.id}</a>"
end

def verify_signature!
if generate_body_signature(request.body.read) != request.headers['X-Helpscout-Signature']
request_http_token_authentication
end
end

def generate_body_signature(body)
Base64.strict_encode64(OpenSSL::HMAC.digest('sha1',
Rails.application.secrets.helpscout[:webhook_secret],
body))
end
end
12 changes: 6 additions & 6 deletions app/decorators/champ_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ class ChampDecorator < Draper::Decorator
delegate_all

def value
if type_champ == "date" && object.value.present?
if type_champ == TypeDeChamp.type_champs.fetch(:date) && object.value.present?
Date.parse(object.value).strftime("%d/%m/%Y")
elsif type_champ.in? ["checkbox", "engagement"]
elsif type_champ.in? [TypeDeChamp.type_champs.fetch(:checkbox), TypeDeChamp.type_champs.fetch(:engagement)]
object.value == 'on' ? 'Oui' : 'Non'
elsif type_champ == 'yes_no'
elsif type_champ == TypeDeChamp.type_champs.fetch(:yes_no)
if object.value == 'true'
'Oui'
elsif object.value == 'false'
'Non'
end
elsif type_champ == 'multiple_drop_down_list' && object.value.present?
elsif type_champ == TypeDeChamp.type_champs.fetch(:multiple_drop_down_list) && object.value.present?
JSON.parse(object.value).join(', ')
else
object.value
Expand All @@ -21,9 +21,9 @@ def value

def date_for_input
if object.value.present?
if type_champ == "date"
if type_champ == TypeDeChamp.type_champs.fetch(:date)
object.value
elsif type_champ == "datetime" && object.value != ' 00:00'
elsif type_champ == TypeDeChamp.type_champs.fetch(:datetime) && object.value != ' 00:00'
DateTime.parse(object.value, "%Y-%m-%d %H:%M").strftime("%Y-%m-%d")
end
end
Expand Down
10 changes: 10 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ def staging?
ENV['APP_NAME'] == 'tps_dev'
end

def contact_link(title, options = {})
if Flipflop.support_form?
params = { tags: options[:tags], type: options[:type] }.compact
link_to title, contact_url(params), options
else
mail_to CONTACT_EMAIL, title,
options.merge(subject: "Question à propos de demarches-simplifiees.fr")
end
end

def root_path_for_profile(nav_bar_profile)
case nav_bar_profile
when :gestionnaire
Expand Down
Loading

0 comments on commit e5df2e4

Please sign in to comment.