Merge branch 'dev'

This commit is contained in:
gregoirenovel 2018-10-25 15:03:13 +02:00
commit 584309cdbe
8 changed files with 87 additions and 70 deletions

View file

@ -32,7 +32,7 @@ class Users::CarteController < UsersController
@dossier = current_user_dossier
@data = {}
geo_json = JSON.parse(params.required(:selection))
geo_json = JSON.parse(params.fetch(:selection, '[]'))
if geo_json.first == ["error", "TooManyPolygons"]
@error = true

View file

@ -126,7 +126,7 @@ class Gestionnaire < ApplicationRecord
procedure.dossiers.not_archived
else
procedure.dossiers.en_cours
end.followed_by(self)
end
dossiers_id_with_notifications(dossiers)
end
@ -139,35 +139,14 @@ class Gestionnaire < ApplicationRecord
Dossier.not_archived
else
Dossier.en_cours
end.followed_by(self)
end
Dossier.where(id: dossiers_id_with_notifications(dossiers)).group(:procedure_id).count
end
def mark_tab_as_seen(dossier, tab)
attributes = {}
attributes["#{tab}_seen_at"] = DateTime.now
Follow.where(gestionnaire: self, dossier: dossier).update_all(attributes)
end
def invite!
reset_password_token = set_reset_password_token
GestionnaireMailer.invite_gestionnaire(self, reset_password_token).deliver_later
end
private
def annotations_hash(demande, annotations_privees, avis, messagerie)
{
demande: demande,
annotations_privees: annotations_privees,
avis: avis,
messagerie: messagerie
}
end
def dossiers_id_with_notifications(dossiers)
dossiers = dossiers.followed_by(self)
updated_demandes = dossiers
.joins(:champs)
.where('champs.updated_at > follows.demande_seen_at')
@ -198,4 +177,27 @@ class Gestionnaire < ApplicationRecord
updated_messagerie
].flat_map { |query| query.distinct.ids }.uniq
end
def mark_tab_as_seen(dossier, tab)
attributes = {}
attributes["#{tab}_seen_at"] = DateTime.now
Follow.where(gestionnaire: self, dossier: dossier).update_all(attributes)
end
def invite!
reset_password_token = set_reset_password_token
GestionnaireMailer.invite_gestionnaire(self, reset_password_token).deliver_later
end
private
def annotations_hash(demande, annotations_privees, avis, messagerie)
{
demande: demande,
annotations_privees: annotations_privees,
avis: avis,
messagerie: messagerie
}
end
end

View file

@ -78,7 +78,7 @@ class ProcedurePresentation < ApplicationRecord
case table
when 'notifications'
dossiers_id_with_notification = gestionnaire.notifications_for_procedure(procedure)
dossiers_id_with_notification = gestionnaire.dossiers_id_with_notifications(dossiers)
if order == 'desc'
return dossiers_id_with_notification +
(dossiers.order('dossiers.updated_at desc').ids - dossiers_id_with_notification)

View file

@ -39,11 +39,13 @@
- if Flipflop.web_hook?
.form-group
%h4 Lien de rappel HTTP
%h4 Lien de rappel HTTP (webhook)
= f.text_field :web_hook_url, class: 'form-control', placeholder: 'https://callback.exemple.fr/'
%p.help-block
%i.fa.fa-info-circle
Un lien de rappel HTTP (aussi appelé webhook) est utilisé pour notifier un service tiers du changement de l'état dun dossier sur demarches-simplifiees.fr. À chaque changement détat d'un dossier, notre site va effectuer une requête sur le lien renseigné avec en paramètres : le nouvel état du dossier, lidentifiant de la démarche, l'identifiant dossier et la date du changement. Vous pourrez alors utiliser notre API pour récupérer les nouvelles informations du dossier concerné.
Vous pouvez définir un lien de rappel HTTP (aussi appelé webhook) pour notifier un service tiers du changement de l'état dun dossier de cette démarche sur demarches-simplifiees.fr.
= link_to("Consulter la documentation du webhook", WEBHOOK_DOC_URL, target: "_blank")
\.
.form-group
%h4 Cadre juridique *
@ -51,7 +53,9 @@
%ul
%li Texte de loi (loi, décret, circulaire, arrêté,…)
%li Texte juridique (statuts, délibération, décision du conseil d'administration…)
%li <a href="https://doc.demarches-simplifiees.fr/tutoriels/tutoriel-administrateur#cadre-juridique" target="_blank">En savoir plus</a>
%li
= link_to("En savoir plus", CADRE_JURIDIQUE_URL, target: "_blank")
%p.help-block
%i.fa.fa-info-circle
Vous pouvez saisir un lien vers ce texte ou importer celui-ci directement.

View file

@ -1,6 +1,6 @@
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rails'
require 'mina/rbenv'
# Basic settings:
@ -12,42 +12,35 @@ require 'mina/rbenv'
# Advanced settings:
# forward_agent - SSH forward_agent
# user - Username in the server to SSH to
# shared_dirs - Manually create these paths in shared/ on your server.
# They will be linked in the 'deploy:link_shared_paths' step.
set :domain, ENV.fetch('domain')
set :repository, 'https://github.com/betagouv/tps.git'
deploy_to = '/var/www/ds'
set :deploy_to, deploy_to
set :user, 'ds'
set :branch, ENV.fetch('branch')
# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
# They will be linked in the 'deploy:link_shared_paths' step.
set :shared_dirs, [
shared_dirs = [
'log',
'sockets',
'tmp/pids',
'tmp/cache'
'tmp/cache',
'tmp/pids'
]
set :domain, ENV.fetch('domain')
set :deploy_to, deploy_to
set :repository, 'https://github.com/betagouv/tps.git'
set :branch, ENV.fetch('branch')
set :forward_agent, true
set :user, 'ds'
set :shared_dirs, shared_dirs
set :rbenv_path, "/home/ds/.rbenv/bin/rbenv"
set :forward_agent, true # SSH forward_agent.
puts "Deploy to #{ENV.fetch('domain')}, branch: #{ENV.fetch('branch')}"
# This task is the environment that is loaded for most commands, such as
# `mina deploy` or `mina rake`.
task :setup do
command %[mkdir -p "#{deploy_to}/shared/log"]
command %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
command %[mkdir -p "#{deploy_to}/shared/tmp/pids"]
command %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp/pids"]
command %[mkdir -p "#{deploy_to}/shared/tmp/cache"]
command %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp/cache"]
command %[mkdir -p "#{deploy_to}/shared/sockets"]
command %[chmod g+rx,u+rwx "#{deploy_to}/shared/sockets"]
shared_dirs.each do |dir|
command %[mkdir -p "#{deploy_to}/shared/#{dir}"]
command %[chmod g+rx,u+rwx "#{deploy_to}/shared/#{dir}"]
end
end
namespace :yarn do
@ -76,6 +69,12 @@ namespace :service do
command %{
echo "-----> Restarting puma service"
#{echo_cmd %[sudo systemctl restart puma]}
}
end
desc "Reload nginx"
task :reload_nginx do
command %{
echo "-----> Reloading nginx service"
#{echo_cmd %[sudo systemctl reload nginx]}
}
@ -94,11 +93,12 @@ desc "Deploys the current version to the server."
task :deploy do
command 'export PATH=$PATH:/home/ds/.rbenv/bin:/home/ds/.rbenv/shims'
command 'source /home/ds/.profile'
deploy do
# Put things that will set up an empty directory into a fully set-up
# instance of your project.
invoke :'git:clone'
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
invoke :'bundle:install'
invoke :'yarn:install'
@ -108,6 +108,7 @@ task :deploy do
on :launch do
invoke :'service:restart_puma'
invoke :'service:reload_nginx'
invoke :'service:restart_delayed_job'
end
end

View file

@ -12,11 +12,13 @@ FOG_BASE_URL = "https://storage.apientreprise.fr"
# External services URLs
DOC_URL = "https://doc.demarches-simplifiees.fr"
ADMINISTRATEUR_TUTORIAL_URL = "https://doc.demarches-simplifiees.fr/tutoriels/tutoriel-administrateur"
INSTRUCTEUR_TUTORIAL_URL = "https://doc.demarches-simplifiees.fr/tutoriels/tutoriel-accompagnateur"
WEBINAIRE_URL = "https://doc.demarches-simplifiees.fr/pour-aller-plus-loin/webinaires"
ADMINISTRATEUR_TUTORIAL_URL = [DOC_URL, "tutoriels", "tutoriel-administrateur"].join("/")
INSTRUCTEUR_TUTORIAL_URL = [DOC_URL, "tutoriels", "tutoriel-accompagnateur"].join("/")
CADRE_JURIDIQUE_URL = [ADMINISTRATEUR_TUTORIAL_URL, "cadre-juridique"].join("#")
WEBINAIRE_URL = [DOC_URL, "pour-aller-plus-loin", "webinaires"].join("/")
LISTE_DES_DEMARCHES_URL = [DOC_URL, "listes-des-demarches"].join("/")
CGU_URL = [DOC_URL, "cgu"].join("/")
MENTIONS_LEGALES_URL = [CGU_URL, "4-mentions-legales"].join("#")
API_DOC_URL = [DOC_URL, "pour-aller-plus-loin", "api"].join("/")
WEBHOOK_DOC_URL = [DOC_URL, "pour-aller-plus-loin", "webhook"].join("/")
FAQ_URL = "https://faq.demarches-simplifiees.fr"

View file

@ -1,27 +1,27 @@
def domains_from_env(env)
case env
def domains_for_stage(stage)
case stage
when 'dev'
['web1.dev', 'web2.dev']
when 'prod'
['web1', 'web2']
else
raise "STAGE #{env} is unknown. It must be either dev or prod"
raise "STAGE #{stage} is unknown. It must be either dev or prod."
end
end
task :setup do
domains = domains_for_stage(ENV.fetch('STAGE'))
domains.each do |domain|
sh "mina setup domain=#{domain} force_asset_precompile=true"
end
end
task :deploy do
domains = domains_from_env(ENV.fetch('STAGE'))
domains = domains_for_stage(ENV.fetch('STAGE'))
branch = ENV.fetch('BRANCH')
domains.each do |domain|
sh "mina deploy domain=#{domain} branch=#{branch} force_asset_precompile=true"
end
end
task :setup do
domains = domains_from_env(ENV['STAGE'])
domains.each do |domain|
sh "mina setup domain=#{domain} force_asset_precompile=true"
end
end

View file

@ -238,6 +238,7 @@ describe ProcedurePresentation do
before do
notified_dossier.champs.first.touch(time: DateTime.new(2018, 9, 20))
create(:follow, gestionnaire: gestionnaire, dossier: notified_dossier, demande_seen_at: DateTime.new(2018, 9, 10))
notified_dossier.touch(time: DateTime.new(2018, 9, 20))
recent_dossier.touch(time: DateTime.new(2018, 9, 25))
older_dossier.touch(time: DateTime.new(2018, 5, 13))
end
@ -253,6 +254,13 @@ describe ProcedurePresentation do
it { is_expected.to eq([notified_dossier, recent_dossier, older_dossier].map(&:id)) }
end
context 'with a dossier terminé' do
let!(:notified_dossier) { create(:dossier, :accepte, procedure: procedure) }
let(:order) { 'desc' }
it { is_expected.to eq([notified_dossier, recent_dossier, older_dossier].map(&:id)) }
end
end
context 'for self table' do