Skip to content

Commit 53349a6

Browse files
authored
Merge pull request #4456 from betagouv/dev
2019-10-30-01
2 parents 28acdfd + 77bf1fe commit 53349a6

16 files changed

Lines changed: 321 additions & 90 deletions

File tree

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ gem 'aasm'
44
gem 'actiontext', git: 'https://github.com/kobaltz/actiontext.git', branch: 'archive', require: 'action_text' # Port of ActionText to Rails 5
55
gem 'active_link_to' # Automatically set a class on active links
66
gem 'active_model_serializers'
7-
gem 'activestorage-openstack', git: 'https://github.com/fredZen/activestorage-openstack.git', branch: 'frederic/fix_upload_signature'
7+
gem 'activestorage-openstack'
88
gem 'administrate'
99
gem 'after_party'
1010
gem 'anchored'

Gemfile.lock

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
GIT
2-
remote: https://github.com/fredZen/activestorage-openstack.git
3-
revision: c71d5107a51701eab9d9267dd0000e6c1cf3e39a
4-
branch: frederic/fix_upload_signature
5-
specs:
6-
activestorage-openstack (0.5.0)
7-
fog-openstack (~> 1.0)
8-
marcel
9-
mime-types
10-
rails (~> 5.2.0)
11-
121
GIT
132
remote: https://github.com/kobaltz/actiontext.git
143
revision: ef59c4ba99d1b7614dd47f5a294eef553224db88
@@ -75,6 +64,11 @@ GEM
7564
actionpack (= 5.2.2.1)
7665
activerecord (= 5.2.2.1)
7766
marcel (~> 0.3.1)
67+
activestorage-openstack (1.0.0)
68+
fog-openstack (~> 1.0)
69+
marcel
70+
mime-types
71+
rails (<= 6)
7872
activesupport (5.2.2.1)
7973
concurrent-ruby (~> 1.0, >= 1.0.2)
8074
i18n (>= 0.7, < 2)
@@ -214,7 +208,7 @@ GEM
214208
ethon (0.11.0)
215209
ffi (>= 1.3.0)
216210
eventmachine (1.2.7)
217-
excon (0.62.0)
211+
excon (0.68.0)
218212
execjs (2.7.0)
219213
factory_bot (4.11.1)
220214
activesupport (>= 3.0.0)
@@ -238,7 +232,7 @@ GEM
238232
fog-json (1.2.0)
239233
fog-core
240234
multi_json (~> 1.10)
241-
fog-openstack (1.0.6)
235+
fog-openstack (1.0.10)
242236
fog-core (~> 2.1)
243237
fog-json (>= 1.0)
244238
ipaddress (>= 0.8)
@@ -325,7 +319,7 @@ GEM
325319
rails-dom-testing (>= 1, < 3)
326320
railties (>= 4.2.0)
327321
thor (>= 0.14, < 2.0)
328-
json (2.1.0)
322+
json (2.2.0)
329323
json-jwt (1.10.0)
330324
activesupport (>= 4.2)
331325
aes_key_wrap
@@ -375,16 +369,16 @@ GEM
375369
marcel (0.3.3)
376370
mimemagic (~> 0.3.2)
377371
method_source (0.9.2)
378-
mime-types (3.2.2)
372+
mime-types (3.3)
379373
mime-types-data (~> 3.2015)
380-
mime-types-data (3.2018.0812)
374+
mime-types-data (3.2019.1009)
381375
mimemagic (0.3.3)
382376
mini_mime (1.0.2)
383377
mini_portile2 (2.4.0)
384378
minitest (5.11.3)
385379
momentjs-rails (2.20.1)
386380
railties (>= 3.1)
387-
multi_json (1.13.1)
381+
multi_json (1.14.1)
388382
multi_xml (0.6.0)
389383
multipart-post (2.0.0)
390384
mustermann (1.0.3)
@@ -425,7 +419,7 @@ GEM
425419
validate_email
426420
validate_url
427421
webfinger (>= 1.0.1)
428-
openstack (3.3.20)
422+
openstack (3.3.21)
429423
json
430424
orm_adapter (0.5.0)
431425
parallel (1.12.1)
@@ -717,7 +711,7 @@ DEPENDENCIES
717711
actiontext!
718712
active_link_to
719713
active_model_serializers
720-
activestorage-openstack!
714+
activestorage-openstack
721715
administrate
722716
after_party
723717
anchored
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
module Instructeurs
2+
class GroupeInstructeursController < InstructeurController
3+
ITEMS_PER_PAGE = 25
4+
5+
def index
6+
@procedure = procedure
7+
@groupes_instructeurs = paginated_groupe_instructeurs
8+
end
9+
10+
def show
11+
@procedure = procedure
12+
@groupe_instructeur = groupe_instructeur
13+
@instructeurs = paginated_instructeurs
14+
end
15+
16+
def add_instructeur
17+
@instructeur = Instructeur.find_by(email: instructeur_email) ||
18+
create_instructeur(instructeur_email)
19+
20+
if groupe_instructeur.instructeurs.include?(@instructeur)
21+
flash[:alert] = "L’instructeur « #{instructeur_email} » est déjà dans le groupe."
22+
23+
else
24+
groupe_instructeur.instructeurs << @instructeur
25+
flash[:notice] = "L’instructeur « #{instructeur_email} » a été affecté au groupe."
26+
GroupeInstructeurMailer
27+
.add_instructeur(groupe_instructeur, @instructeur, current_user.email)
28+
.deliver_later
29+
end
30+
31+
redirect_to instructeur_groupe_path(procedure, groupe_instructeur)
32+
end
33+
34+
def remove_instructeur
35+
if groupe_instructeur.instructeurs.one?
36+
flash[:alert] = "Suppression impossible : il doit y avoir au moins un instructeur dans le groupe"
37+
38+
else
39+
@instructeur = Instructeur.find(instructeur_id)
40+
groupe_instructeur.instructeurs.destroy(@instructeur)
41+
flash[:notice] = "L’instructeur « #{@instructeur.email} » a été retiré du groupe."
42+
GroupeInstructeurMailer
43+
.remove_instructeur(groupe_instructeur, @instructeur, current_user.email)
44+
.deliver_later
45+
end
46+
47+
redirect_to instructeur_groupe_path(procedure, groupe_instructeur)
48+
end
49+
50+
private
51+
52+
def create_instructeur(email)
53+
user = User.create_or_promote_to_instructeur(
54+
email,
55+
SecureRandom.hex,
56+
administrateurs: [procedure.administrateurs.first]
57+
)
58+
user.invite!
59+
user.instructeur
60+
end
61+
62+
def procedure
63+
current_instructeur
64+
.procedures
65+
.includes(:groupe_instructeurs)
66+
.find(params[:procedure_id])
67+
end
68+
69+
def groupe_instructeur
70+
current_instructeur.groupe_instructeurs.find(params[:id])
71+
end
72+
73+
def paginated_groupe_instructeurs
74+
current_instructeur
75+
.groupe_instructeurs
76+
.where(procedure: procedure)
77+
.page(params[:page])
78+
.per(ITEMS_PER_PAGE)
79+
.order(:label)
80+
end
81+
82+
def paginated_instructeurs
83+
groupe_instructeur
84+
.instructeurs
85+
.page(params[:page])
86+
.per(ITEMS_PER_PAGE)
87+
.order(:email)
88+
end
89+
90+
def instructeur_email
91+
params[:instructeur][:email].strip.downcase
92+
end
93+
94+
def instructeur_id
95+
params[:instructeur][:id]
96+
end
97+
end
98+
end

app/lib/active_storage/service/ds_proxy_service.rb

Lines changed: 0 additions & 57 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
- content_for(:title, "Notifications pour #{@procedure.libelle}")
2+
3+
= render partial: 'new_administrateur/breadcrumbs',
4+
locals: { steps: [link_to(@procedure.libelle, procedure_path(@procedure)),
5+
'Groupes d’instructeurs'] }
6+
7+
.container.groupe-instructeur
8+
.card
9+
.card-title Gestion des Groupes
10+
%table.table.mt-2
11+
%thead
12+
%tr
13+
%th{ colspan: 2 } Liste des groupes
14+
%tbody
15+
- @groupes_instructeurs.each do |group|
16+
%tr
17+
%td= group.label
18+
%td.actions= link_to "voir", instructeur_groupe_path(@procedure, group)
19+
20+
= paginate @groupes_instructeurs
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
- content_for(:title, "Instructeurs du groupe #{@groupe_instructeur.label}")
2+
3+
= render partial: 'new_administrateur/breadcrumbs',
4+
locals: { steps: [link_to(@procedure.libelle, procedure_path(@procedure)),
5+
link_to('Groupes d’instructeurs', instructeur_groupes_path(@procedure)),
6+
@groupe_instructeur.label] }
7+
8+
.container.groupe-instructeur
9+
%h1 Groupe « #{@groupe_instructeur.label} »
10+
11+
.card.mt-2
12+
.card-title Gestion des instructeurs
13+
= form_for :instructeur,
14+
url: { action: :add_instructeur },
15+
html: { class: 'form' } do |f|
16+
17+
= f.label :email do
18+
Affecter un nouvel instructeur
19+
= f.email_field :email, placeholder: 'marie.dupont@exemple.fr', required: true
20+
= f.submit 'Affecter', class: 'button primary send'
21+
22+
%table.table.mt-2
23+
%thead
24+
%tr
25+
%th{ colspan: 2 } Instructeurs affectés
26+
%tbody
27+
- @instructeurs.each do |instructeur|
28+
%tr
29+
%td= instructeur.email
30+
%td.actions= button_to 'retirer',
31+
{ action: :remove_instructeur },
32+
{ method: :delete,
33+
data: { confirm: "Êtes-vous sûr de vouloir retirer l’instructeur « #{instructeur.email} » du groupe  « #{@groupe_instructeur.label} » ?" },
34+
params: { instructeur: { id: instructeur.id }},
35+
class: 'button' }
36+
37+
= paginate @instructeurs

app/views/instructeurs/procedures/show.html.haml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
|
1414
= link_to 'statistiques', stats_instructeur_procedure_path(@procedure), class: 'header-link', data: { turbolinks: false } # Turbolinks disabled for Chartkick. See Issue #350
1515

16+
- if @procedure.routee?
17+
|
18+
- if current_administrateur.present? && current_administrateur.owns?(@procedure)
19+
= link_to 'instructeurs', procedure_groupe_instructeurs_path(@procedure), class: 'header-link'
20+
- else
21+
= link_to 'instructeurs', instructeur_groupes_path(@procedure), class: 'header-link'
1622

1723
%ul.tabs
1824
= tab_item('à suivre',

app/views/new_administrateur/groupe_instructeurs/show.html.haml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
@groupe_instructeur.label] }
66

77
.container.groupe-instructeur
8-
.rename_form_block
9-
.flex.baseline-start
10-
%h1 Groupe « #{@groupe_instructeur.label} »
8+
%h1 Groupe « #{@groupe_instructeur.label} »
119

1210
.card.mt-2
1311
= form_for @groupe_instructeur,

config/env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ FOG_OPENSTACK_REGION=""
2424
FOG_DIRECTORY=""
2525
FOG_ENABLED=""
2626
CARRIERWAVE_CACHE_DIR="/tmp/tps-local-cache"
27+
DS_PROXY_URL=""
2728

2829
FC_PARTICULIER_ID=""
2930
FC_PARTICULIER_SECRET=""

config/environments/development.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# Don't care if the mailer can't send.
2323
config.action_mailer.raise_delivery_errors = false
2424

25-
config.active_storage.service = :local
25+
config.active_storage.service = ENV['FOG_ENABLED'] == 'enabled' ? :openstack : :local
2626

2727
# Print deprecation notices to the Rails logger.
2828
config.active_support.deprecation = :log

0 commit comments

Comments
 (0)