Merge branch 'dev'

This commit is contained in:
gregoirenovel 2018-02-07 10:42:54 +01:00
commit ba3d1fb729
35 changed files with 89 additions and 554 deletions

View file

@ -30,27 +30,27 @@ GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
CFPropertyList (2.3.6) CFPropertyList (2.3.6)
actioncable (5.0.6) actioncable (5.1.4)
actionpack (= 5.0.6) actionpack (= 5.1.4)
nio4r (>= 1.2, < 3.0) nio4r (~> 2.0)
websocket-driver (~> 0.6.1) websocket-driver (~> 0.6.1)
actionmailer (5.0.6) actionmailer (5.1.4)
actionpack (= 5.0.6) actionpack (= 5.1.4)
actionview (= 5.0.6) actionview (= 5.1.4)
activejob (= 5.0.6) activejob (= 5.1.4)
mail (~> 2.5, >= 2.5.4) mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
actionpack (5.0.6) actionpack (5.1.4)
actionview (= 5.0.6) actionview (= 5.1.4)
activesupport (= 5.0.6) activesupport (= 5.1.4)
rack (~> 2.0) rack (~> 2.0)
rack-test (~> 0.6.3) rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2) rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.0.6) actionview (5.1.4)
activesupport (= 5.0.6) activesupport (= 5.1.4)
builder (~> 3.1) builder (~> 3.1)
erubis (~> 2.7.0) erubi (~> 1.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3) rails-html-sanitizer (~> 1.0, >= 1.0.3)
active_model_serializers (0.10.7) active_model_serializers (0.10.7)
@ -58,44 +58,43 @@ GEM
activemodel (>= 4.1, < 6) activemodel (>= 4.1, < 6)
case_transform (>= 0.2) case_transform (>= 0.2)
jsonapi-renderer (>= 0.1.1.beta1, < 0.3) jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
activejob (5.0.6) activejob (5.1.4)
activesupport (= 5.0.6) activesupport (= 5.1.4)
globalid (>= 0.3.6) globalid (>= 0.3.6)
activemodel (5.0.6) activemodel (5.1.4)
activesupport (= 5.0.6) activesupport (= 5.1.4)
activemodel-serializers-xml (1.0.2) activemodel-serializers-xml (1.0.2)
activemodel (> 5.x) activemodel (> 5.x)
activesupport (> 5.x) activesupport (> 5.x)
builder (~> 3.1) builder (~> 3.1)
activerecord (5.0.6) activerecord (5.1.4)
activemodel (= 5.0.6) activemodel (= 5.1.4)
activesupport (= 5.0.6) activesupport (= 5.1.4)
arel (~> 7.0) arel (~> 8.0)
activesupport (5.0.6) activesupport (5.1.4)
concurrent-ruby (~> 1.0, >= 1.0.2) concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7) i18n (~> 0.7)
minitest (~> 5.1) minitest (~> 5.1)
tzinfo (~> 1.1) tzinfo (~> 1.1)
addressable (2.5.2) addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0) public_suffix (>= 2.0.2, < 4.0)
administrate (0.4.0) administrate (0.8.1)
autoprefixer-rails (~> 6.0) actionpack (>= 4.2, < 5.2)
bourbon (~> 4.2) actionview (>= 4.2, < 5.2)
activerecord (>= 4.2, < 5.2)
autoprefixer-rails (>= 6.0)
datetime_picker_rails (~> 0.0.7) datetime_picker_rails (~> 0.0.7)
jquery-rails (~> 4.0) jquery-rails (>= 4.0)
kaminari (~> 0.16) kaminari (>= 1.0)
momentjs-rails (~> 2.8) momentjs-rails (~> 2.8)
neat (~> 1.1)
normalize-rails (~> 3.0)
rails (>= 4.2, < 5.1)
sass-rails (~> 5.0) sass-rails (~> 5.0)
selectize-rails (~> 0.6) selectize-rails (~> 0.6)
apipie-rails (0.5.6) apipie-rails (0.5.6)
rails (>= 4.1) rails (>= 4.1)
arel (7.1.4) arel (8.0.0)
ast (2.3.0) ast (2.3.0)
attr_required (1.0.1) attr_required (1.0.1)
autoprefixer-rails (6.7.7.2) autoprefixer-rails (7.2.5)
execjs execjs
axlsx (2.0.1) axlsx (2.0.1)
htmlentities (~> 4.3.1) htmlentities (~> 4.3.1)
@ -109,9 +108,6 @@ GEM
sass (>= 3.3.4) sass (>= 3.3.4)
bootstrap-wysihtml5-rails (0.3.3.8) bootstrap-wysihtml5-rails (0.3.3.8)
railties (>= 3.0) railties (>= 3.0)
bourbon (4.3.4)
sass (~> 3.4)
thor (~> 0.19)
brakeman (4.1.1) brakeman (4.1.1)
browser (2.5.2) browser (2.5.2)
builder (3.2.3) builder (3.2.3)
@ -138,7 +134,7 @@ GEM
chartkick (2.2.5) chartkick (2.2.5)
childprocess (0.8.0) childprocess (0.8.0)
ffi (~> 1.0, >= 1.0.11) ffi (~> 1.0, >= 1.0.11)
chunky_png (1.3.8) chunky_png (1.3.10)
clamav-client (3.1.0) clamav-client (3.1.0)
coderay (1.1.2) coderay (1.1.2)
coffee-rails (4.2.2) coffee-rails (4.2.2)
@ -193,6 +189,7 @@ GEM
em-websocket (0.5.1) em-websocket (0.5.1)
eventmachine (>= 0.12.9) eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0) http_parser.rb (~> 0.6.0)
erubi (1.7.0)
erubis (2.7.0) erubis (2.7.0)
eventmachine (1.2.1) eventmachine (1.2.1)
excon (0.60.0) excon (0.60.0)
@ -402,7 +399,7 @@ GEM
domain_name (~> 0.5) domain_name (~> 0.5)
http_parser.rb (0.6.0) http_parser.rb (0.6.0)
httpclient (2.8.3) httpclient (2.8.3)
i18n (0.9.1) i18n (0.9.3)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
inflecto (0.0.2) inflecto (0.0.2)
ipaddress (0.8.3) ipaddress (0.8.3)
@ -418,9 +415,18 @@ GEM
url_safe_base64 url_safe_base64
jsonapi-renderer (0.2.0) jsonapi-renderer (0.2.0)
jwt (1.5.6) jwt (1.5.6)
kaminari (0.17.0) kaminari (1.1.1)
actionpack (>= 3.0.0) activesupport (>= 4.1.0)
activesupport (>= 3.0.0) kaminari-actionview (= 1.1.1)
kaminari-activerecord (= 1.1.1)
kaminari-core (= 1.1.1)
kaminari-actionview (1.1.1)
actionview
kaminari-core (= 1.1.1)
kaminari-activerecord (1.1.1)
activerecord
kaminari-core (= 1.1.1)
kaminari-core (1.1.1)
kgio (2.11.1) kgio (2.11.1)
launchy (2.4.3) launchy (2.4.3)
addressable (~> 2.3) addressable (~> 2.3)
@ -463,15 +469,11 @@ GEM
multi_xml (0.6.0) multi_xml (0.6.0)
multipart-post (2.0.0) multipart-post (2.0.0)
mustermann (1.0.1) mustermann (1.0.1)
neat (1.9.0)
sass (>= 3.3)
thor (~> 0.19)
nenv (0.3.0) nenv (0.3.0)
netrc (0.11.0) netrc (0.11.0)
nio4r (2.2.0) nio4r (2.2.0)
nokogiri (1.8.2) nokogiri (1.8.2)
mini_portile2 (~> 2.3.0) mini_portile2 (~> 2.3.0)
normalize-rails (3.0.3)
notiffany (0.1.1) notiffany (0.1.1)
nenv (~> 0.1) nenv (~> 0.1)
shellany (~> 0.0) shellany (~> 0.0)
@ -537,19 +539,19 @@ GEM
rack (>= 1.1) rack (>= 1.1)
rack-protection (2.0.0) rack-protection (2.0.0)
rack rack
rack-test (0.6.3) rack-test (0.8.2)
rack (>= 1.0) rack (>= 1.0, < 3)
rails (5.0.6) rails (5.1.4)
actioncable (= 5.0.6) actioncable (= 5.1.4)
actionmailer (= 5.0.6) actionmailer (= 5.1.4)
actionpack (= 5.0.6) actionpack (= 5.1.4)
actionview (= 5.0.6) actionview (= 5.1.4)
activejob (= 5.0.6) activejob (= 5.1.4)
activemodel (= 5.0.6) activemodel (= 5.1.4)
activerecord (= 5.0.6) activerecord (= 5.1.4)
activesupport (= 5.0.6) activesupport (= 5.1.4)
bundler (>= 1.3.0) bundler (>= 1.3.0)
railties (= 5.0.6) railties (= 5.1.4)
sprockets-rails (>= 2.0.0) sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.2) rails-controller-testing (1.0.2)
actionpack (~> 5.x, >= 5.0.1) actionpack (~> 5.x, >= 5.0.1)
@ -560,9 +562,9 @@ GEM
nokogiri (>= 1.6) nokogiri (>= 1.6)
rails-html-sanitizer (1.0.3) rails-html-sanitizer (1.0.3)
loofah (~> 2.0) loofah (~> 2.0)
railties (5.0.6) railties (5.1.4)
actionpack (= 5.0.6) actionpack (= 5.1.4)
activesupport (= 5.0.6) activesupport (= 5.1.4)
method_source method_source
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
@ -711,7 +713,7 @@ GEM
turbolinks-source (5.1.0) turbolinks-source (5.1.0)
tzinfo (1.2.4) tzinfo (1.2.4)
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (4.1.3) uglifier (4.1.4)
execjs (>= 0.3.0, < 3) execjs (>= 0.3.0, < 3)
unf (0.1.4) unf (0.1.4)
unf_ext unf_ext

View file

@ -1,20 +1,4 @@
$(document).on('turbolinks:load', the_terms); $(document).on('turbolinks:load', the_terms);
$(document).on('turbolinks:load', pannel_switch);
function pannel_switch() {
$('#switch-notifications').click(function () {
$('#procedure-list').addClass('hidden');
$('#notifications-list').removeClass('hidden');
$(this).addClass('active');
$('#switch-procedures').removeClass('active');
})
$('#switch-procedures').click(function () {
$('#notifications-list').addClass('hidden');
$('#procedure-list').removeClass('hidden');
$(this).addClass('active');
$('#switch-notifications').removeClass('active');
})
}
function the_terms() { function the_terms() {
var the_terms = $("#dossier_autorisation_donnees"); var the_terms = $("#dossier_autorisation_donnees");

View file

@ -29,7 +29,6 @@
// = require login // = require login
// = require main_container // = require main_container
// = require navbar // = require navbar
// = require notification_alert
// = require pieces_justificatives_fields // = require pieces_justificatives_fields
// = require pj_modal // = require pj_modal
// = require pref_list_menu // = require pref_list_menu

View file

@ -36,8 +36,7 @@ h5 span {
cursor: pointer; cursor: pointer;
} }
#procedure-list, #procedure-list {
#notifications-list {
margin-left: -10px; margin-left: -10px;
margin-top: 20px; margin-top: 20px;
@ -47,13 +46,11 @@ h5 span {
text-decoration: none; text-decoration: none;
} }
.procedure-list-element.active, .procedure-list-element.active {
.notification.active {
background-color: #668ABD; background-color: #668ABD;
} }
.procedure-list-element, .procedure-list-element {
.notification {
padding: 15px 40px 15px 20px; padding: 15px 40px 15px 20px;
cursor: pointer; cursor: pointer;
line-height: 1.8em; line-height: 1.8em;
@ -63,8 +60,7 @@ h5 span {
} }
} }
.procedure-list-element:hover, .procedure-list-element:hover {
.notification:hover {
background-color: #668ABD; background-color: #668ABD;
cursor: pointer; cursor: pointer;
} }

View file

@ -1,12 +0,0 @@
#notification-alert {
position: fixed;
top: 20px;
right: -250px;
z-index: 1000;
width: 250px;
height: 80px;
border: solid #000000 1px;
}

View file

@ -2,7 +2,6 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception. # Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead. # For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception protect_from_forgery with: :exception
before_action :check_browser
before_action :load_navbar_left_pannel_partial_url before_action :load_navbar_left_pannel_partial_url
before_action :set_raven_context before_action :set_raven_context
before_action :authorize_request_for_profiler before_action :authorize_request_for_profiler
@ -26,10 +25,6 @@ class ApplicationController < ActionController::Base
{} {}
end end
def check_browser
BROWSER.value = BrowserService.get_browser(request)
end
def load_navbar_left_pannel_partial_url def load_navbar_left_pannel_partial_url
controller = request.controller_class controller = request.controller_class
method = params[:action] method = params[:action]

View file

@ -203,22 +203,18 @@ module NewGestionnaire
end end
def mark_demande_as_read def mark_demande_as_read
dossier.notifications.demande.mark_as_read
current_gestionnaire.mark_tab_as_seen(dossier, :demande) current_gestionnaire.mark_tab_as_seen(dossier, :demande)
end end
def mark_messagerie_as_read def mark_messagerie_as_read
dossier.notifications.messagerie.mark_as_read
current_gestionnaire.mark_tab_as_seen(dossier, :messagerie) current_gestionnaire.mark_tab_as_seen(dossier, :messagerie)
end end
def mark_avis_as_read def mark_avis_as_read
dossier.notifications.avis.mark_as_read
current_gestionnaire.mark_tab_as_seen(dossier, :avis) current_gestionnaire.mark_tab_as_seen(dossier, :avis)
end end
def mark_annotations_privees_as_read def mark_annotations_privees_as_read
dossier.notifications.annotations_privees.mark_as_read
current_gestionnaire.mark_tab_as_seen(dossier, :annotations_privees) current_gestionnaire.mark_tab_as_seen(dossier, :annotations_privees)
end end
end end

View file

@ -21,8 +21,6 @@ module NewGestionnaire
.group(:procedure_id) .group(:procedure_id)
.reorder(nil) .reorder(nil)
.count .count
@notifications_count_per_procedure = current_gestionnaire.notifications_count_per_procedure
end end
def show def show
@ -41,7 +39,7 @@ module NewGestionnaire
@followed_dossiers = current_gestionnaire @followed_dossiers = current_gestionnaire
.followed_dossiers .followed_dossiers
.includes(:user, :notifications) .includes(:user)
.where(procedure: @procedure) .where(procedure: @procedure)
.en_cours .en_cours

View file

@ -2,9 +2,9 @@ class PingController < ApplicationController
def index def index
Rails.logger.silence do Rails.logger.silence do
if (ActiveRecord::Base.connected?) if (ActiveRecord::Base.connected?)
head :ok head :ok, content_type: "application/json"
else else
head :internal_server_error head :internal_server_error, content_type: "application/json"
end end
end end
end end

View file

@ -1,8 +0,0 @@
class NotificationDecorator < Draper::Decorator
delegate_all
def index_display
['champs', 'piece_justificative'].include?(type_notif) ? type = liste.join(" ") : type = liste.last
{ dossier: "Dossier nº #{dossier.id}", date: created_at.strftime('%d/%m %H:%M'), type: type }
end
end

View file

@ -9,10 +9,6 @@ class DossierFacades
@dossier.decorate @dossier.decorate
end end
def last_notifications
@dossier.notifications.order("updated_at DESC").limit(5)
end
def champs def champs
@dossier.ordered_champs @dossier.ordered_champs
end end

View file

@ -5,8 +5,6 @@ class Cerfa < ActiveRecord::Base
mount_uploader :content, CerfaUploader mount_uploader :content, CerfaUploader
validates :content, :file_size => { :maximum => 20.megabytes } validates :content, :file_size => { :maximum => 20.megabytes }
after_save :internal_notification, if: Proc.new { dossier.present? }
def empty? def empty?
content.blank? content.blank?
end end
@ -20,12 +18,4 @@ class Cerfa < ActiveRecord::Base
end end
end end
end end
private
def internal_notification
if dossier.state != 'brouillon'
NotificationService.new('cerfa', self.dossier.id).notify
end
end
end end

View file

@ -9,8 +9,6 @@ class Champ < ActiveRecord::Base
before_save :format_datetime, if: Proc.new { type_champ == 'datetime' } before_save :format_datetime, if: Proc.new { type_champ == 'datetime' }
before_save :multiple_select_to_string, if: Proc.new { type_champ == 'multiple_drop_down_list' } before_save :multiple_select_to_string, if: Proc.new { type_champ == 'multiple_drop_down_list' }
after_save :internal_notification, if: Proc.new { dossier.present? }
scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) } scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) }
def mandatory? def mandatory?
@ -110,16 +108,6 @@ class Champ < ActiveRecord::Base
end end
end end
def internal_notification
if dossier.state != 'brouillon'
if type == 'ChampPublic'
NotificationService.new('champs', self.dossier.id, self.libelle).notify
else
NotificationService.new('annotations_privees', self.dossier.id, self.libelle).notify
end
end
end
def multiple_select_to_string def multiple_select_to_string
if value.present? if value.present?
json = JSON.parse(value) json = JSON.parse(value)

View file

@ -35,11 +35,11 @@ class Commentaire < ActiveRecord::Base
when I18n.t("dynamics.contact_email") when I18n.t("dynamics.contact_email")
# The commentaire is a copy of an automated notification email # The commentaire is a copy of an automated notification email
# we sent to a user, so do nothing # we sent to a user, so do nothing
when dossier_user_email, *invited_users_emails when dossier_user_email, *invited_users_emails
# A user or an inved user posted a commentaire, # A user or an inved user posted a commentaire,
# we need to notify the gestionnaires # do nothing, the notification system will properly
notify_gestionnaires
else else
# A gestionnaire posted a commentaire, # A gestionnaire posted a commentaire,
# we need to notify the user # we need to notify the user
@ -48,10 +48,6 @@ class Commentaire < ActiveRecord::Base
end end
end end
def notify_gestionnaires
NotificationService.new('commentaire', self.dossier.id).notify
end
def notify_user def notify_user
NotificationMailer.new_answer(dossier).deliver_now! NotificationMailer.new_answer(dossier).deliver_now!
end end

View file

@ -29,7 +29,6 @@ class Dossier < ActiveRecord::Base
has_many :invites_user, class_name: 'InviteUser', dependent: :destroy has_many :invites_user, class_name: 'InviteUser', dependent: :destroy
has_many :invites_gestionnaires, class_name: 'InviteGestionnaire', dependent: :destroy has_many :invites_gestionnaires, class_name: 'InviteGestionnaire', dependent: :destroy
has_many :follows has_many :follows
has_many :notifications, dependent: :destroy
has_many :avis, dependent: :destroy has_many :avis, dependent: :destroy
belongs_to :procedure belongs_to :procedure
@ -58,7 +57,6 @@ class Dossier < ActiveRecord::Base
scope :downloadable_sorted, -> { state_not_brouillon.includes(:entreprise, :etablissement, :champs, :champs_private).order(en_construction_at: 'asc') } scope :downloadable_sorted, -> { state_not_brouillon.includes(:entreprise, :etablissement, :champs, :champs_private).order(en_construction_at: 'asc') }
scope :en_cours, -> { not_archived.state_en_construction_ou_instruction } scope :en_cours, -> { not_archived.state_en_construction_ou_instruction }
scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) } scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) }
scope :with_unread_notifications, -> { where(notifications: { already_read: false }) }
scope :followed_by, -> (gestionnaire) { joins(:follows).where(follows: { gestionnaire: gestionnaire }) } scope :followed_by, -> (gestionnaire) { joins(:follows).where(follows: { gestionnaire: gestionnaire }) }
accepts_nested_attributes_for :individual accepts_nested_attributes_for :individual
@ -78,29 +76,10 @@ class Dossier < ActiveRecord::Base
validates :user, presence: true validates :user, presence: true
def unreaded_notifications
@unreaded_notif ||= notifications.where(already_read: false)
end
def first_unread_notification
unreaded_notifications.order("created_at ASC").first
end
def was_piece_justificative_uploaded_for_type_id?(type_id) def was_piece_justificative_uploaded_for_type_id?(type_id)
pieces_justificatives.where(type_de_piece_justificative_id: type_id).count > 0 pieces_justificatives.where(type_de_piece_justificative_id: type_id).count > 0
end end
def notifications_summary
unread_notifications = notifications.unread
{
demande: unread_notifications.select(&:demande?).present?,
avis: unread_notifications.select(&:avis?).present?,
messagerie: unread_notifications.select(&:messagerie?).present?,
annotations_privees: unread_notifications.select(&:annotations_privees?).present?
}
end
def retrieve_last_piece_justificative_by_type(type) def retrieve_last_piece_justificative_by_type(type)
pieces_justificatives.where(type_de_piece_justificative_id: type).last pieces_justificatives.where(type_de_piece_justificative_id: type).last
end end

View file

@ -47,27 +47,6 @@ class Gestionnaire < ActiveRecord::Base
procedures.find_by(id: procedure_id).present? procedures.find_by(id: procedure_id).present?
end end
def notifications
Notification.where(already_read: false, dossier_id: follows.pluck(:dossier_id)).order("updated_at DESC")
end
def dossiers_with_notifications_count_for_procedure(procedure)
followed_dossiers_id = followed_dossiers.where(procedure: procedure).pluck(:id)
Notification.unread.where(dossier_id: followed_dossiers_id).select(:dossier_id).distinct(:dossier_id).count
end
def notifications_count_per_procedure
followed_dossiers
.joins(:notifications)
.where(notifications: { already_read: false })
.group('procedure_id')
.count
end
def dossiers_with_notifications_count
notifications.pluck(:dossier_id).uniq.count
end
def last_week_overview def last_week_overview
start_date = DateTime.now.beginning_of_week start_date = DateTime.now.beginning_of_week

View file

@ -1,41 +0,0 @@
class Notification < ActiveRecord::Base
enum type_notif: {
commentaire: 'commentaire',
cerfa: 'cerfa',
piece_justificative: 'piece_justificative',
champs: 'champs',
submitted: 'submitted',
avis: 'avis',
annotations_privees: 'annotations_privees'
}
DEMANDE = %w(cerfa piece_justificative champs submitted)
AVIS = %w(avis)
MESSAGERIE = %w(commentaire)
ANNOTATIONS_PRIVEES = %w(annotations_privees)
belongs_to :dossier
scope :unread, -> { where(already_read: false) }
scope :demande, -> { where(type_notif: DEMANDE) }
scope :avis, -> { where(type_notif: AVIS) }
scope :messagerie, -> { where(type_notif: MESSAGERIE) }
scope :annotations_privees, -> { where(type_notif: ANNOTATIONS_PRIVEES) }
scope :mark_as_read, -> { update_all(already_read: true) }
def demande?
Notification::DEMANDE.include?(type_notif)
end
def avis?
Notification::AVIS.include?(type_notif)
end
def messagerie?
Notification::MESSAGERIE.include?(type_notif)
end
def annotations_privees?
Notification::ANNOTATIONS_PRIVEES.include?(type_notif)
end
end

View file

@ -13,8 +13,6 @@ class PieceJustificative < ActiveRecord::Base
validates :content, :file_size => { :maximum => 20.megabytes } validates :content, :file_size => { :maximum => 20.megabytes }
validates :content, presence: true, allow_blank: false, allow_nil: false validates :content, presence: true, allow_blank: false, allow_nil: false
after_save :internal_notification, if: Proc.new { dossier.present? }
scope :updated_since?, -> (date) { where('pieces_justificatives.updated_at > ?', date) } scope :updated_since?, -> (date) { where('pieces_justificatives.updated_at > ?', date) }
def empty? def empty?
@ -55,12 +53,4 @@ class PieceJustificative < ActiveRecord::Base
image/jpeg image/jpeg
" "
end end
private
def internal_notification
if self.type_de_piece_justificative.present? || dossier.state != 'brouillon'
NotificationService.new('piece_justificative', self.dossier.id, self.libelle).notify
end
end
end end

View file

@ -1,17 +0,0 @@
class BrowserService
def self.get_browser request
BROWSER.value = Browser.new(request.user_agent)
end
def self.recommended_browser?
browser = BROWSER.value
return false if browser.chrome? && browser.version.to_i < 40
return false if browser.ie?(["<10"])
return false if browser.firefox? && browser.version.to_i < 45
return false if browser.opera? && browser.version.to_i < 19
return false if browser.safari? && browser.version.to_i < 8
true
end
end

View file

@ -1,43 +0,0 @@
class NotificationService
def initialize type_notif, dossier_id, attribut_change = ''
@type_notif = type_notif
@dossier_id = dossier_id
notification.liste.push text_for_notif attribut_change
notification.liste = notification.liste.uniq
self
end
def notify
notification.save
end
def notification
@notification ||=
begin
Notification.find_by! dossier_id: @dossier_id, already_read: false, type_notif: @type_notif
rescue ActiveRecord::RecordNotFound
Notification.new dossier_id: @dossier_id, type_notif: @type_notif, liste: []
end
end
def text_for_notif attribut = ''
case @type_notif
when 'commentaire'
"#{notification.liste.size + 1} nouveau(x) commentaire(s) déposé(s)."
when 'cerfa'
"Un nouveau formulaire a été déposé."
when 'piece_justificative'
attribut
when 'champs'
attribut
when 'submitted'
"Le dossier nº #{@dossier_id} a été déposé."
when 'avis'
'Un nouvel avis a été rendu'
else
'Notification par défaut'
end
end
end

View file

@ -34,7 +34,7 @@ class TypesDeChampService
def self.order_champs(params, attributes) def self.order_champs(params, attributes)
# It's OK to use an unsafe hash here because the params will then go through # It's OK to use an unsafe hash here because the params will then go through
# require / permit methods in the method before this one # require / permit methods in #create_update_procedure_params
tdcas = params[:procedure][attributes].to_unsafe_hash.to_a tdcas = params[:procedure][attributes].to_unsafe_hash.to_a
.map { |_hash_index, tdca| tdca } .map { |_hash_index, tdca| tdca }

View file

@ -1,7 +1,7 @@
- if !BrowserService.recommended_browser? - if !browser.modern?
#support-navigator-banner.row #support-navigator-banner.row
.col-xs-12 .col-xs-12
= BROWSER.value.name = browser.name
= BROWSER.value.version = browser.version
\- \-
Attention, votre navigateur n'est pas recommandé pour la navigation sur ce site internet. Aucun support ne pourra vous être prodigué en cas de dysfonctionnement. Attention, votre navigateur n'est pas recommandé pour la navigation sur ce site internet. Aucun support ne pourra vous être prodigué en cas de dysfonctionnement.

View file

@ -1,3 +1,7 @@
BROWSER = Hashie::Mash.new ({ Browser.modern_rules.clear
value: nil Browser.modern_rules << -> b { b.chrome? && b.version.to_i >= 40 }
}) Browser.modern_rules << -> b { b.ie?([">=10"]) }
Browser.modern_rules << -> b { b.edge? }
Browser.modern_rules << -> b { b.firefox? && b.version.to_i >= 45 }
Browser.modern_rules << -> b { b.opera? && b.version.to_i >= 19 }
Browser.modern_rules << -> b { b.safari? && b.version.to_i >= 8 }

View file

@ -0,0 +1,5 @@
class DropNotifications < ActiveRecord::Migration[5.0]
def change
drop_table :notifications
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180111153308) do ActiveRecord::Schema.define(version: 20180201163642) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -332,16 +332,6 @@ ActiveRecord::Schema.define(version: 20180111153308) do
t.index ["procedure_id"], name: "index_module_api_cartos_on_procedure_id", unique: true, using: :btree t.index ["procedure_id"], name: "index_module_api_cartos_on_procedure_id", unique: true, using: :btree
end end
create_table "notifications", force: :cascade do |t|
t.boolean "already_read", default: false
t.string "liste", array: true
t.string "type_notif"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "dossier_id"
t.index ["dossier_id"], name: "index_notifications_on_dossier_id", using: :btree
end
create_table "pieces_justificatives", force: :cascade do |t| create_table "pieces_justificatives", force: :cascade do |t|
t.string "content" t.string "content"
t.integer "dossier_id" t.integer "dossier_id"

View file

@ -280,38 +280,6 @@ describe NewGestionnaire::DossiersController, type: :controller do
end end
end end
describe '#show #messagerie #annotations_privees #avis' do
before do
dossier.notifications = %w(champs annotations_privees avis commentaire).map{ |type| Notification.create!(type_notif: type) }
get method, params: { procedure_id: procedure.id, dossier_id: dossier.id }
dossier.notifications.each(&:reload)
end
context '#show' do
let(:method) { :show }
it { expect(dossier.notifications.map(&:already_read)).to match([true, false, false, false]) }
it { expect(response).to have_http_status(:success) }
end
context '#annotations_privees' do
let(:method) { :annotations_privees }
it { expect(dossier.notifications.map(&:already_read)).to match([false, true, false, false]) }
it { expect(response).to have_http_status(:success) }
end
context '#avis' do
let(:method) { :avis }
it { expect(dossier.notifications.map(&:already_read)).to match([false, false, true, false]) }
it { expect(response).to have_http_status(:success) }
end
context '#messagerie' do
let(:method) { :messagerie }
it { expect(dossier.notifications.map(&:already_read)).to match([false, false, false, true]) }
it { expect(response).to have_http_status(:success) }
end
end
describe "#create_commentaire" do describe "#create_commentaire" do
let(:saved_commentaire) { dossier.commentaires.first } let(:saved_commentaire) { dossier.commentaires.first }
let(:body) { "avant\napres" } let(:body) { "avant\napres" }

View file

@ -50,10 +50,6 @@ describe Users::CommentairesController, type: :controller do
subject subject
end end
it 'Notification interne is create' do
expect { subject }.to change(Notification, :count).by (1)
end
end end
context 'when document is upload whith a commentaire', vcr: { cassette_name: 'controllers_sers_commentaires_controller_upload_doc' } do context 'when document is upload whith a commentaire', vcr: { cassette_name: 'controllers_sers_commentaires_controller_upload_doc' } do

View file

@ -190,10 +190,6 @@ shared_examples 'description_controller_spec' do
context 'Quand la procédure accepte les CERFA' do context 'Quand la procédure accepte les CERFA' do
subject { post :update, params: { dossier_id: dossier_id, cerfa_pdf: cerfa_pdf } } subject { post :update, params: { dossier_id: dossier_id, cerfa_pdf: cerfa_pdf } }
it 'Notification interne is create' do
expect { subject }.to change(Notification, :count).by (1)
end
context 'Sauvegarde du CERFA PDF', vcr: { cassette_name: 'controllers_users_description_controller_save_cerfa' } do context 'Sauvegarde du CERFA PDF', vcr: { cassette_name: 'controllers_users_description_controller_save_cerfa' } do
before do before do
post :update, params: { dossier_id: dossier_id, cerfa_pdf: cerfa_pdf } post :update, params: { dossier_id: dossier_id, cerfa_pdf: cerfa_pdf }
@ -369,10 +365,6 @@ shared_examples 'description_controller_spec' do
sign_in guest sign_in guest
end end
it 'Notification interne is create' do
expect { subject }.to change(Notification, :count).by (1)
end
context 'when PJ have no documents' do context 'when PJ have no documents' do
it { expect(dossier.pieces_justificatives.size).to eq 0 } it { expect(dossier.pieces_justificatives.size).to eq 0 }

View file

@ -1,12 +0,0 @@
FactoryBot.define do
factory :notification do
type_notif 'commentaire'
liste []
before(:create) do |notification, _evaluator|
if !notification.dossier
notification.dossier = create :dossier
end
end
end
end

View file

@ -4,7 +4,6 @@ RSpec.describe NotificationMailer, type: :mailer do
shared_examples_for "create a commentaire not notified" do shared_examples_for "create a commentaire not notified" do
it do it do
expect { subject.deliver_now }.to change { Commentaire.count }.by(1) expect { subject.deliver_now }.to change { Commentaire.count }.by(1)
expect { subject.deliver_now }.to_not change { Notification.count }
subject.deliver_now subject.deliver_now
commentaire = Commentaire.last commentaire = Commentaire.last
@ -19,7 +18,6 @@ RSpec.describe NotificationMailer, type: :mailer do
describe '.send_notification' do describe '.send_notification' do
let(:email_template) { instance_double('email_template', subject_for_dossier: 'subject', body_for_dossier: 'body') } let(:email_template) { instance_double('email_template', subject_for_dossier: 'subject', body_for_dossier: 'body') }
let(:attestation) { nil } let(:attestation) { nil }
let(:notifications_count_before) { Notification.count }
subject { described_class.send_notification(dossier, email_template, attestation) } subject { described_class.send_notification(dossier, email_template, attestation) }

View file

@ -17,30 +17,6 @@ describe Commentaire do
let(:dossier) { create(:dossier, procedure: procedure, user: user) } let(:dossier) { create(:dossier, procedure: procedure, user: user) }
let(:commentaire) { Commentaire.new(dossier: dossier, body: "Mon commentaire") } let(:commentaire) { Commentaire.new(dossier: dossier, body: "Mon commentaire") }
context "with a commentaire created by a user" do
it "calls notify_gestionnaires" do
expect(commentaire).to receive(:notify_gestionnaires)
commentaire.email = user.email
commentaire.save
end
end
context "with a commentaire created by an invited user" do
let(:user_invite) { create(:user) }
before do
FactoryBot.create(:invite_user, email: "invite@tps.apientreprise.fr", dossier: dossier, user: user_invite)
end
it "calls notify_gestionnaires" do
expect(commentaire).to receive(:notify_gestionnaires)
commentaire.email = user_invite.email
commentaire.save
end
end
context "with a commentaire created by a gestionnaire" do context "with a commentaire created by a gestionnaire" do
it "calls notify_user" do it "calls notify_user" do
expect(commentaire).to receive(:notify_user) expect(commentaire).to receive(:notify_user)

View file

@ -125,93 +125,6 @@ describe Gestionnaire, type: :model do
end end
end end
describe '#dossiers_with_notifications_count' do
subject { gestionnaire.dossiers_with_notifications_count }
context 'when there is no notifications' do
it { is_expected.to eq(0) }
end
context 'when there is one notification for one dossier' do
let(:notification){ create(:notification, already_read: false) }
let!(:follow){ create(:follow, dossier: notification.dossier, gestionnaire: gestionnaire) }
it { is_expected.to eq(1) }
end
context 'when there is one notification read' do
let(:notification){ create(:notification, already_read: true) }
let!(:follow){ create(:follow, dossier: notification.dossier, gestionnaire: gestionnaire) }
it { is_expected.to eq(0) }
end
context 'when there are many notifications for one dossier' do
let(:notification){ create(:notification, already_read: false) }
let(:notification2){ create(:notification, already_read: false, dossier: notification.dossier) }
let!(:follow){ create(:follow, dossier: notification.dossier, gestionnaire: gestionnaire) }
it { is_expected.to eq(1) }
end
context 'when there are many notifications for many dossiers' do
let(:notification){ create(:notification, already_read: false) }
let(:notification2){ create(:notification, already_read: false) }
let!(:follow){ create(:follow, dossier: notification.dossier, gestionnaire: gestionnaire) }
let!(:follow2){ create(:follow, dossier: notification2.dossier, gestionnaire: gestionnaire) }
it { is_expected.to eq(2) }
end
end
describe '#dossiers_with_notifications_count_for_procedure' do
subject { gestionnaire.dossiers_with_notifications_count_for_procedure(procedure) }
context 'without notifications' do
it { is_expected.to eq(0) }
end
context 'with a followed dossier' do
let!(:dossier){ create(:dossier, procedure: procedure, state: 'en_instruction') }
let!(:follow){ create(:follow, dossier: dossier, gestionnaire: gestionnaire) }
context 'with 1 notification' do
let!(:notification){ create(:notification, already_read: false, dossier: dossier) }
it { is_expected.to eq(1) }
end
context 'with 1 read notification' do
let!(:notification){ create(:notification, already_read: true, dossier: dossier) }
it { is_expected.to eq(0) }
end
context 'with 2 notifications' do
let!(:notification){ create(:notification, already_read: false, dossier: dossier) }
let!(:notification2){ create(:notification, already_read: false, dossier: dossier) }
it { is_expected.to eq(1) }
end
context 'with another dossier' do
let!(:dossier2){ create(:dossier, procedure: procedure, state: 'en_instruction') }
let!(:follow2){ create(:follow, dossier: dossier2, gestionnaire: gestionnaire) }
context 'and some notifications' do
let!(:notification){ create(:notification, already_read: false, dossier: dossier) }
let!(:notification2){ create(:notification, already_read: false, dossier: dossier) }
let!(:notification3){ create(:notification, already_read: false, dossier: dossier) }
let!(:notification4){ create(:notification, already_read: false, dossier: dossier2) }
let!(:notification5){ create(:notification, already_read: false, dossier: dossier2) }
it { is_expected.to eq(2) }
end
end
end
end
describe 'last_week_overview' do describe 'last_week_overview' do
let!(:gestionnaire2) { create(:gestionnaire) } let!(:gestionnaire2) { create(:gestionnaire) }
subject { gestionnaire2.last_week_overview } subject { gestionnaire2.last_week_overview }
@ -274,32 +187,6 @@ describe Gestionnaire, type: :model do
end end
end end
describe '#notifications_count_per_procedure' do
subject { gestionnaire.notifications_count_per_procedure }
let(:dossier_with_unread_notification) do
create(:dossier, notifications: [Notification.create(type_notif: 'champs', already_read: false)])
end
let(:dossier_with_no_unread_notification) do
create(:dossier, notifications: [Notification.create(type_notif: 'champs', already_read: true)])
end
before { gestionnaire.followed_dossiers << followed_dossier }
context 'when a followed dossier has unread notification' do
let(:followed_dossier) { dossier_with_unread_notification }
it { is_expected.to eq({ dossier_with_unread_notification.procedure.id => 1 }) }
end
context 'when a followed dossier has unread notification' do
let(:followed_dossier) { dossier_with_no_unread_notification }
it { is_expected.to eq({}) }
end
end
describe "procedure_presentation_for_procedure_id" do describe "procedure_presentation_for_procedure_id" do
let!(:procedure_assign_2) { create :assign_to, gestionnaire: gestionnaire, procedure: procedure_2 } let!(:procedure_assign_2) { create :assign_to, gestionnaire: gestionnaire, procedure: procedure_2 }
let!(:pp) { ProcedurePresentation.create(assign_to: procedure_assign) } let!(:pp) { ProcedurePresentation.create(assign_to: procedure_assign) }

View file

@ -1,11 +0,0 @@
require 'spec_helper'
describe Notification do
it { is_expected.to have_db_column(:already_read) }
it { is_expected.to have_db_column(:liste) }
it { is_expected.to have_db_column(:type_notif) }
it { is_expected.to have_db_column(:created_at) }
it { is_expected.to have_db_column(:updated_at) }
it { is_expected.to belong_to(:dossier) }
end

View file

@ -1,24 +0,0 @@
require 'spec_helper'
describe NotificationService do
describe '.notify' do
let(:dossier) { create :dossier }
let(:service) { described_class.new type_notif, dossier.id }
subject { service.notify }
context 'when is the first notification for dossier_id and type_notif and alread_read is false' do
let(:type_notif) { 'commentaire' }
it { expect { subject }.to change(Notification, :count).by (1) }
context 'when is not the first notification' do
before do
create :notification, dossier: dossier, type_notif: type_notif
end
it { expect { subject }.to change(Notification, :count).by (0) }
end
end
end
end

View file

@ -69,7 +69,6 @@ end
DatabaseCleaner.strategy = :transaction DatabaseCleaner.strategy = :transaction
SIADETOKEN = :valid_token if !defined? SIADETOKEN SIADETOKEN = :valid_token if !defined? SIADETOKEN
BROWSER.value = Browser.new('Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)')
include Warden::Test::Helpers include Warden::Test::Helpers