Merge branch 'dev'

This commit is contained in:
gregoirenovel 2018-02-26 10:00:00 +01:00
commit 8e080a2695
15 changed files with 125 additions and 92 deletions

View file

@ -17,8 +17,6 @@ gem 'therubyracer', platforms: :ruby
gem 'jquery-rails' gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks' gem 'turbolinks'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Enable deep clone of active record models # Enable deep clone of active record models
gem 'deep_cloneable' gem 'deep_cloneable'

View file

@ -82,7 +82,7 @@ GEM
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.8.1) administrate (0.9.0)
actionpack (>= 4.2, < 5.2) actionpack (>= 4.2, < 5.2)
actionview (>= 4.2, < 5.2) actionview (>= 4.2, < 5.2)
activerecord (>= 4.2, < 5.2) activerecord (>= 4.2, < 5.2)
@ -98,14 +98,14 @@ GEM
arel (9.0.0) arel (9.0.0)
ast (2.4.0) ast (2.4.0)
attr_required (1.0.1) attr_required (1.0.1)
autoprefixer-rails (7.2.5) autoprefixer-rails (8.0.0)
execjs execjs
axlsx (2.0.1) axlsx (2.0.1)
htmlentities (~> 4.3.1) htmlentities (~> 4.3.1)
nokogiri (>= 1.4.1) nokogiri (>= 1.4.1)
rubyzip (~> 1.0.0) rubyzip (~> 1.0.0)
bcrypt (3.1.11) bcrypt (3.1.11)
bindata (2.4.1) bindata (2.4.2)
bindex (0.5.0) bindex (0.5.0)
bootstrap-sass (3.3.7) bootstrap-sass (3.3.7)
autoprefixer-rails (>= 5.2.1) autoprefixer-rails (>= 5.2.1)
@ -195,7 +195,7 @@ GEM
http_parser.rb (~> 0.6.0) http_parser.rb (~> 0.6.0)
erubi (1.7.0) erubi (1.7.0)
erubis (2.7.0) erubis (2.7.0)
eventmachine (1.2.1) eventmachine (1.2.5)
excon (0.60.0) excon (0.60.0)
execjs (2.7.0) execjs (2.7.0)
factory_bot (4.8.2) factory_bot (4.8.2)
@ -205,7 +205,7 @@ GEM
ffi (1.9.18) ffi (1.9.18)
fission (0.5.0) fission (0.5.0)
CFPropertyList (~> 2.2) CFPropertyList (~> 2.2)
fog (1.41.0) fog (1.42.0)
fog-aliyun (>= 0.1.0) fog-aliyun (>= 0.1.0)
fog-atmos fog-atmos
fog-aws (>= 0.6.0) fog-aws (>= 0.6.0)
@ -222,6 +222,7 @@ GEM
fog-json fog-json
fog-local fog-local
fog-openstack fog-openstack
fog-ovirt
fog-powerdns (>= 0.1.1) fog-powerdns (>= 0.1.1)
fog-profitbricks fog-profitbricks
fog-rackspace fog-rackspace
@ -238,7 +239,7 @@ GEM
fog-xenserver fog-xenserver
fog-xml (~> 0.1.1) fog-xml (~> 0.1.1)
ipaddress (~> 0.5) ipaddress (~> 0.5)
json (>= 1.8, < 2.0) json (~> 2.0)
fog-aliyun (0.2.0) fog-aliyun (0.2.0)
fog-core (~> 1.27) fog-core (~> 1.27)
fog-json (~> 1.0) fog-json (~> 1.0)
@ -300,6 +301,11 @@ GEM
fog-core (~> 1.40) fog-core (~> 1.40)
fog-json (>= 1.0) fog-json (>= 1.0)
ipaddress (>= 0.8) ipaddress (>= 0.8)
fog-ovirt (0.1.3)
fog-core (~> 1.45)
fog-json
fog-xml (~> 0.1.1)
rbovirt (~> 0.1.5)
fog-powerdns (0.1.1) fog-powerdns (0.1.1)
fog-core (~> 1.27) fog-core (~> 1.27)
fog-json (~> 1.0) fog-json (~> 1.0)
@ -411,7 +417,7 @@ GEM
rails-dom-testing (>= 1, < 3) rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0) railties (>= 4.2.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
json (1.8.6) json (2.1.0)
json-jwt (1.8.3) json-jwt (1.8.3)
activesupport activesupport
bindata bindata
@ -431,7 +437,7 @@ GEM
activerecord activerecord
kaminari-core (= 1.1.1) kaminari-core (= 1.1.1)
kaminari-core (1.1.1) kaminari-core (1.1.1)
kgio (2.11.1) kgio (2.11.2)
launchy (2.4.3) launchy (2.4.3)
addressable (~> 2.3) addressable (~> 2.3)
leaflet-draw-rails (0.1.0) leaflet-draw-rails (0.1.0)
@ -499,7 +505,7 @@ GEM
oauth2 (~> 1.1) oauth2 (~> 1.1)
omniauth (~> 1.2) omniauth (~> 1.2)
open4 (1.3.4) open4 (1.3.4)
openid_connect (1.1.3) openid_connect (1.1.4)
activemodel activemodel
attr_required (>= 1.0.0) attr_required (>= 1.0.0)
json (>= 1.4.3) json (>= 1.4.3)
@ -537,12 +543,12 @@ GEM
rack rack
rack-mini-profiler (0.10.7) rack-mini-profiler (0.10.7)
rack (>= 1.2.0) rack (>= 1.2.0)
rack-oauth2 (1.7.0) rack-oauth2 (1.8.2)
activesupport (>= 2.3) activesupport
attr_required (>= 0.0.5) attr_required
httpclient (>= 2.4) httpclient
multi_json (>= 1.3.6) json-jwt
rack (>= 1.1) rack
rack-protection (2.0.1) rack-protection (2.0.1)
rack rack
rack-test (0.8.2) rack-test (0.8.2)
@ -581,12 +587,14 @@ GEM
rb-fsevent (0.10.2) rb-fsevent (0.10.2)
rb-inotify (0.9.10) rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2) ffi (>= 0.5.0, < 2)
rbovirt (0.1.5)
nokogiri
rest-client (> 1.7.0)
rbvmomi (1.11.6) rbvmomi (1.11.6)
builder (~> 3.0) builder (~> 3.0)
json (>= 1.8) json (>= 1.8)
nokogiri (~> 1.5) nokogiri (~> 1.5)
trollop (~> 2.1) trollop (~> 2.1)
rdoc (4.3.0)
ref (2.0.0) ref (2.0.0)
request_store (1.4.0) request_store (1.4.0)
rack (>= 1.4) rack (>= 1.4)
@ -660,9 +668,6 @@ GEM
scss_lint (0.56.0) scss_lint (0.56.0)
rake (>= 0.9, < 13) rake (>= 0.9, < 13)
sass (~> 3.5.3) sass (~> 3.5.3)
sdoc (0.4.2)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
securecompare (1.0.0) securecompare (1.0.0)
select2-rails (4.0.3) select2-rails (4.0.3)
thor (~> 0.14) thor (~> 0.14)
@ -672,7 +677,7 @@ GEM
rubyzip (~> 1.0) rubyzip (~> 1.0)
sentry-raven (2.7.2) sentry-raven (2.7.2)
faraday (>= 0.7.6, < 1.0) faraday (>= 0.7.6, < 1.0)
sexp_processor (4.10.0) sexp_processor (4.10.1)
shellany (0.0.1) shellany (0.0.1)
shoulda-matchers (3.1.2) shoulda-matchers (3.1.2)
activesupport (>= 4.0.0) activesupport (>= 4.0.0)
@ -724,7 +729,7 @@ GEM
execjs (>= 0.3.0, < 3) execjs (>= 0.3.0, < 3)
unf (0.1.4) unf (0.1.4)
unf_ext unf_ext
unf_ext (0.0.7.4) unf_ext (0.0.7.5)
unicode-display_width (1.3.0) unicode-display_width (1.3.0)
unicode_utils (1.4.0) unicode_utils (1.4.0)
unicorn (5.4.0) unicorn (5.4.0)
@ -830,7 +835,6 @@ DEPENDENCIES
sass-rails sass-rails
scenic scenic
scss_lint scss_lint
sdoc (~> 0.4.0)
select2-rails select2-rails
sentry-raven sentry-raven
shoulda-matchers shoulda-matchers

View file

@ -4,6 +4,9 @@ class Admin::AccompagnateursController < AdminController
before_action :retrieve_procedure before_action :retrieve_procedure
ASSIGN = 'assign'
NOT_ASSIGN = 'not_assign'
def show def show
assign_scope = @procedure.gestionnaires assign_scope = @procedure.gestionnaires
@ -46,11 +49,21 @@ class Admin::AccompagnateursController < AdminController
procedure = Procedure.find(params[:procedure_id]) procedure = Procedure.find(params[:procedure_id])
to = params[:to] to = params[:to]
accompagnateur_service = AccompagnateurService.new gestionnaire, procedure, to case to
when ASSIGN
if gestionnaire.assign_to_procedure(procedure)
flash.notice = "L'accompagnateur a bien été affecté"
else
flash.alert = "L'accompagnateur a déjà été affecté"
end
when NOT_ASSIGN
if gestionnaire.remove_from_procedure(procedure)
flash.notice = "L'accompagnateur a bien été désaffecté"
else
flash.alert = "L'accompagnateur a déjà été désaffecté"
end
end
accompagnateur_service.change_assignement!
flash.notice = "Assignement effectué"
redirect_to admin_procedure_accompagnateurs_path, procedure_id: params[:procedure_id] redirect_to admin_procedure_accompagnateurs_path, procedure_id: params[:procedure_id]
end end
end end

View file

@ -6,7 +6,7 @@ module NewGestionnaire
ITEMS_PER_PAGE = 25 ITEMS_PER_PAGE = 25
def index def index
@procedures = current_gestionnaire.procedures.order(archived_at: :desc, published_at: :desc) @procedures = current_gestionnaire.visible_procedures.order(archived_at: :desc, published_at: :desc)
dossiers = current_gestionnaire.dossiers dossiers = current_gestionnaire.dossiers
@dossiers_count_per_procedure = dossiers.all_state.group(:procedure_id).reorder(nil).count @dossiers_count_per_procedure = dossiers.all_state.group(:procedure_id).reorder(nil).count
@ -202,7 +202,7 @@ module NewGestionnaire
end end
def redirect_to_avis_if_needed def redirect_to_avis_if_needed
if current_gestionnaire.procedures.count == 0 && current_gestionnaire.avis.count > 0 if current_gestionnaire.visible_procedures.count == 0 && current_gestionnaire.avis.count > 0
redirect_to gestionnaire_avis_index_path redirect_to gestionnaire_avis_index_path
end end
end end

View file

@ -5,7 +5,7 @@ class Gestionnaire < ActiveRecord::Base
has_and_belongs_to_many :administrateurs has_and_belongs_to_many :administrateurs
has_many :assign_to, dependent: :destroy has_many :assign_to, dependent: :destroy
has_many :procedures, -> { publiees_ou_archivees }, through: :assign_to has_many :procedures, through: :assign_to
has_many :dossiers, -> { state_not_brouillon }, through: :procedures has_many :dossiers, -> { state_not_brouillon }, through: :procedures
has_many :follows has_many :follows
has_many :followed_dossiers, through: :follows, source: :dossier has_many :followed_dossiers, through: :follows, source: :dossier
@ -14,6 +14,10 @@ class Gestionnaire < ActiveRecord::Base
include CredentialsSyncableConcern include CredentialsSyncableConcern
def visible_procedures
procedures.publiees_ou_archivees
end
def procedure_filter def procedure_filter
procedure_id = self[:procedure_filter] procedure_id = self[:procedure_filter]
if procedures.find_by(id: procedure_id).present? if procedures.find_by(id: procedure_id).present?
@ -47,6 +51,19 @@ class Gestionnaire < ActiveRecord::Base
procedures.find_by(id: procedure_id).present? procedures.find_by(id: procedure_id).present?
end end
def assign_to_procedure(procedure)
begin
procedures << procedure
true
rescue ActiveRecord::RecordNotUnique
false
end
end
def remove_from_procedure(procedure)
!!(procedure.in?(procedures) && procedures.destroy(procedure))
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,19 +0,0 @@
class AccompagnateurService
ASSIGN = 'assign'
NOT_ASSIGN = 'not_assign'
def initialize accompagnateur, procedure, to
@accompagnateur = accompagnateur
@procedure = procedure
@to = to
end
def change_assignement!
case @to
when ASSIGN
AssignTo.create(gestionnaire: @accompagnateur, procedure: @procedure)
when NOT_ASSIGN
AssignTo.where(gestionnaire: @accompagnateur, procedure: @procedure).delete_all
end
end
end

View file

@ -9,7 +9,7 @@
- @accompagnateurs_assign.each do |accompagnateur| - @accompagnateurs_assign.each do |accompagnateur|
%tr %tr
%td.col-md-1.col-lg-1.col-sm-1.col-xs-1.col-sm-1.col-xs-1.center %td.col-md-1.col-lg-1.col-sm-1.col-xs-1.col-sm-1.col-xs-1.center
%a.btn.btn-primary{ href: "#{admin_procedure_accompagnateurs_path(procedure_id: @procedure.id, accompagnateur_id: accompagnateur.id, to: AccompagnateurService::NOT_ASSIGN)}", 'data-method' => 'put' } = link_to "#{admin_procedure_accompagnateurs_path(procedure_id: @procedure.id, accompagnateur_id: accompagnateur.id, to: Admin::AccompagnateursController::NOT_ASSIGN)}", class: "btn btn-primary", 'data-method' => 'put' do
.fa.fa-arrow-left .fa.fa-arrow-left
%td{ style: 'padding-top: 11px; font-size: 15px; text-align: right;' }= accompagnateur.email %td{ style: 'padding-top: 11px; font-size: 15px; text-align: right;' }= accompagnateur.email

View file

@ -16,7 +16,7 @@
%tr %tr
%td.col-xs-11{ style: 'padding-top: 11px; font-size: 15px;' }= accompagnateur.email %td.col-xs-11{ style: 'padding-top: 11px; font-size: 15px;' }= accompagnateur.email
%td.center %td.center
%a.btn.btn-success.gestionnaire-affectation{ href: "#{admin_procedure_accompagnateurs_path(procedure_id: @procedure.id, accompagnateur_id: accompagnateur.id, to: AccompagnateurService::ASSIGN)}", 'data-method' => 'put' } = link_to "#{admin_procedure_accompagnateurs_path(procedure_id: @procedure.id, accompagnateur_id: accompagnateur.id, to: Admin::AccompagnateursController::ASSIGN)}", class: "btn btn-success gestionnaire-affectation", 'data-method' => 'put' do
.fa.fa-arrow-right .fa.fa-arrow-right

View file

@ -10,7 +10,7 @@
- if nav_bar_profile == :gestionnaire && gestionnaire_signed_in? - if nav_bar_profile == :gestionnaire && gestionnaire_signed_in?
- current_url = request.path_info - current_url = request.path_info
%ul.header-tabs %ul.header-tabs
- if current_gestionnaire.procedures.count > 0 - if current_gestionnaire.visible_procedures.count > 0
%li %li
= link_to "Procédures", gestionnaire_procedures_path, class: (controller_name != 'avis') ? "tab-link active" : 'tab-link' = link_to "Procédures", gestionnaire_procedures_path, class: (controller_name != 'avis') ? "tab-link active" : 'tab-link'
- if current_gestionnaire.avis.count > 0 - if current_gestionnaire.avis.count > 0

View file

@ -16,7 +16,7 @@ as well as a link to its edit page.
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Show [1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Show
%> %>
<% content_for(:title) { "#{t("administrate.actions.show")} #{page.page_title}" } %> <% content_for(:title) { t("administrate.actions.show_resource", name: page.page_title) } %>
<% procedure = page.resource %> <% procedure = page.resource %>
<header class="main-content__header" role="banner"> <header class="main-content__header" role="banner">
@ -26,7 +26,7 @@ as well as a link to its edit page.
<div> <div>
<%= link_to( <%= link_to(
"#{t("administrate.actions.edit")} #{page.page_title}", t("administrate.actions.edit_resource", name: page.page_title),
[:edit, namespace, page.resource], [:edit, namespace, page.resource],
class: "button", class: "button",
) if valid_action? :edit %> ) if valid_action? :edit %>

View file

@ -16,7 +16,7 @@ as well as a link to its edit page.
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Show [1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Show
%> %>
<% content_for(:title) { "#{t("administrate.actions.show")} #{page.page_title}" } %> <% content_for(:title) { t("administrate.actions.show_resource", name: page.page_title) } %>
<% procedure = page.resource %> <% procedure = page.resource %>
<header class="main-content__header" role="banner"> <header class="main-content__header" role="banner">
@ -26,7 +26,7 @@ as well as a link to its edit page.
<div> <div>
<%= link_to( <%= link_to(
"#{t("administrate.actions.edit")} #{page.page_title}", t("administrate.actions.edit_resource", name: page.page_title),
[:edit, namespace, page.resource], [:edit, namespace, page.resource],
class: "button", class: "button",
) if valid_action? :edit %> ) if valid_action? :edit %>

View file

@ -0,0 +1,5 @@
class AddUniqueIndexOnAssignTosGestionnaireIdProcedureId < ActiveRecord::Migration[5.2]
def change
add_index :assign_tos, [:gestionnaire_id, :procedure_id], unique: true
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: 2018_02_09_133452) do ActiveRecord::Schema.define(version: 2018_02_19_170553) 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"
@ -84,6 +84,7 @@ ActiveRecord::Schema.define(version: 2018_02_09_133452) do
create_table "assign_tos", id: :serial, force: :cascade do |t| create_table "assign_tos", id: :serial, force: :cascade do |t|
t.integer "gestionnaire_id" t.integer "gestionnaire_id"
t.integer "procedure_id" t.integer "procedure_id"
t.index ["gestionnaire_id", "procedure_id"], name: "index_assign_tos_on_gestionnaire_id_and_procedure_id", unique: true
t.index ["gestionnaire_id"], name: "index_assign_tos_on_gestionnaire_id" t.index ["gestionnaire_id"], name: "index_assign_tos_on_gestionnaire_id"
t.index ["procedure_id"], name: "index_assign_tos_on_procedure_id" t.index ["procedure_id"], name: "index_assign_tos_on_procedure_id"
end end

View file

@ -64,6 +64,54 @@ describe Gestionnaire, type: :model do
end end
end end
describe "#assign_to_procedure" do
subject { gestionnaire.assign_to_procedure(procedure_to_assign) }
context "with a procedure not already assigned" do
let(:procedure_to_assign) { procedure_3 }
it { is_expected.to be_truthy }
it { expect{ subject }.to change(gestionnaire.procedures, :count) }
end
context "with an already assigned procedure" do
let(:procedure_to_assign) { procedure }
it { is_expected.to be_falsey }
it { expect{ subject }.not_to change(gestionnaire.procedures, :count) }
end
end
describe "#remove_from_procedure" do
subject { gestionnaire.remove_from_procedure(procedure_to_remove) }
context "with an assigned procedure" do
let(:procedure_to_remove) { procedure }
let!(:procedure_presentation) { procedure_assign.procedure_presentation }
it { is_expected.to be_truthy }
describe "consequences" do
before do
procedure_assign.build_procedure_presentation
procedure_assign.save
subject
end
it "removes the assign_to and procedure_presentation" do
expect(AssignTo.where(id: procedure_assign).count).to eq(0)
expect(ProcedurePresentation.where(assign_to_id: procedure_assign.id).count).to eq(0)
end
end
end
context "with an already unassigned procedure" do
let(:procedure_to_remove) { procedure_3 }
it { is_expected.to be_falsey }
end
end
context 'unified login' do context 'unified login' do
it 'syncs credentials to associated user' do it 'syncs credentials to associated user' do
gestionnaire = create(:gestionnaire) gestionnaire = create(:gestionnaire)
@ -188,7 +236,6 @@ describe Gestionnaire, type: :model do
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!(:pp) { ProcedurePresentation.create(assign_to: procedure_assign) } let!(:pp) { ProcedurePresentation.create(assign_to: procedure_assign) }
it { expect(gestionnaire.procedure_presentation_for_procedure_id(procedure.id)).to eq(pp) } it { expect(gestionnaire.procedure_presentation_for_procedure_id(procedure.id)).to eq(pp) }

View file

@ -1,33 +0,0 @@
require 'spec_helper'
describe AccompagnateurService do
let(:procedure) { create :procedure, :published }
let(:accompagnateur) { create :gestionnaire }
let(:accompagnateur_service) { AccompagnateurService.new accompagnateur, procedure, to }
describe '#change_assignement!' do
subject { accompagnateur_service.change_assignement! }
context 'when accompagnateur is not assign at the procedure' do
let(:to) { AccompagnateurService::ASSIGN }
before do
subject
end
it { expect(accompagnateur.procedures).to include procedure }
end
context 'when accompagnateur is assign at the procedure' do
let(:to) { AccompagnateurService::NOT_ASSIGN }
before do
create :assign_to, gestionnaire: accompagnateur, procedure: procedure
subject
end
it { expect(accompagnateur.procedures).not_to include procedure }
end
end
end