Merge pull request #23 from sgmap/admin_can_modify_procedure_description_after_published
Admin can modify procedure description after published
This commit is contained in:
commit
c4f57087fe
9 changed files with 126 additions and 71 deletions
21
app/assets/stylesheets/_helpers.scss
Normal file
21
app/assets/stylesheets/_helpers.scss
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
$default-spacer: 15px;
|
||||||
|
|
||||||
|
.m-1 {
|
||||||
|
margin: $default-spacer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mt-1 {
|
||||||
|
margin-top: $default-spacer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mr-1 {
|
||||||
|
margin-right: $default-spacer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mb-1 {
|
||||||
|
margin-bottom: $default-spacer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ml-1 {
|
||||||
|
margin-left: $default-spacer;
|
||||||
|
}
|
|
@ -3,7 +3,6 @@ class Admin::ProceduresController < AdminController
|
||||||
helper SmartListing::Helper
|
helper SmartListing::Helper
|
||||||
|
|
||||||
before_action :retrieve_procedure, only: [:show, :edit]
|
before_action :retrieve_procedure, only: [:show, :edit]
|
||||||
before_action :procedure_locked?, only: [:edit]
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@procedures = smart_listing_create :procedures,
|
@procedures = smart_listing_create :procedures,
|
||||||
|
@ -61,7 +60,7 @@ class Admin::ProceduresController < AdminController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@procedure = Procedure.new(create_procedure_params)
|
@procedure = Procedure.new(procedure_params)
|
||||||
@procedure.module_api_carto = ModuleAPICarto.new(create_module_api_carto_params) if @procedure.valid?
|
@procedure.module_api_carto = ModuleAPICarto.new(create_module_api_carto_params) if @procedure.valid?
|
||||||
|
|
||||||
unless @procedure.save
|
unless @procedure.save
|
||||||
|
@ -76,7 +75,7 @@ class Admin::ProceduresController < AdminController
|
||||||
def update
|
def update
|
||||||
@procedure = current_administrateur.procedures.find(params[:id])
|
@procedure = current_administrateur.procedures.find(params[:id])
|
||||||
|
|
||||||
unless @procedure.update_attributes(create_procedure_params)
|
unless @procedure.update_attributes(procedure_params)
|
||||||
flash.now.alert = @procedure.errors.full_messages.join('<br />').html_safe
|
flash.now.alert = @procedure.errors.full_messages.join('<br />').html_safe
|
||||||
return render 'edit'
|
return render 'edit'
|
||||||
end
|
end
|
||||||
|
@ -192,8 +191,12 @@ class Admin::ProceduresController < AdminController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def create_procedure_params
|
def procedure_params
|
||||||
params.require(:procedure).permit(:libelle, :description, :organisation, :direction, :lien_demarche, :lien_site_web, :lien_notice, :euro_flag, :logo, :cerfa_flag, :for_individual, :individual_with_siret, module_api_carto_attributes: [:id, :use_api_carto, :quartiers_prioritaires, :cadastre]).merge(administrateur_id: current_administrateur.id)
|
if @procedure.try(:locked?)
|
||||||
|
params.require(:procedure).permit(:libelle, :description, :organisation, :direction, :lien_site_web, :lien_notice, :euro_flag, :logo)
|
||||||
|
else
|
||||||
|
params.require(:procedure).permit(:libelle, :description, :organisation, :direction, :lien_site_web, :lien_notice, :euro_flag, :logo, :lien_demarche, :cerfa_flag, :for_individual, :individual_with_siret, module_api_carto_attributes: [:id, :use_api_carto, :quartiers_prioritaires, :cadastre]).merge(administrateur_id: current_administrateur.id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_module_api_carto_params
|
def create_module_api_carto_params
|
||||||
|
|
|
@ -11,9 +11,17 @@ class ProcedureDecorator < Draper::Decorator
|
||||||
end
|
end
|
||||||
|
|
||||||
def logo_img
|
def logo_img
|
||||||
return h.image_url(LOGO_NAME) if logo.blank?
|
if logo.blank?
|
||||||
File.join(STORAGE_URL, File.basename(logo.path))
|
h.image_url(LOGO_NAME)
|
||||||
|
else
|
||||||
|
if Features.remote_storage
|
||||||
|
(RemoteDownloader.new logo.filename).url
|
||||||
|
else
|
||||||
|
(LocalDownloader.new logo.path, 'logo').url
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def geographic_information
|
def geographic_information
|
||||||
module_api_carto
|
module_api_carto
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,9 +23,6 @@
|
||||||
%tr
|
%tr
|
||||||
%td.center
|
%td.center
|
||||||
%b.text-success
|
%b.text-success
|
||||||
= raw "--#{balise.first}--"
|
= "--#{balise.first}--"
|
||||||
-# \--
|
|
||||||
-# = balise.first
|
|
||||||
-# \--
|
|
||||||
%td
|
%td
|
||||||
=balise.second[:description]
|
=balise.second[:description]
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
|
||||||
|
- if @procedure.locked?
|
||||||
|
.alert.alert-info
|
||||||
|
Cette procédure est publiée, certains éléments de la description ne sont plus modifiables
|
||||||
|
|
||||||
-{libelle: 'Libellé*', description: 'Description*', organisation: 'Organisation', direction: 'Direction', lien_site_web: 'Lien site internet', lien_notice: 'Lien notice'}.each do |key, value|
|
-{libelle: 'Libellé*', description: 'Description*', organisation: 'Organisation', direction: 'Direction', lien_site_web: 'Lien site internet', lien_notice: 'Lien notice'}.each do |key, value|
|
||||||
.form-group
|
.form-group
|
||||||
%h4
|
%h4
|
||||||
|
@ -9,30 +14,31 @@
|
||||||
= f.text_field key, class: 'form-control', placeholder: value
|
= f.text_field key, class: 'form-control', placeholder: value
|
||||||
|
|
||||||
.row
|
.row
|
||||||
.col-xs-6
|
.col-md-6
|
||||||
%h4 Logo de la procédure
|
%h4 Logo de la procédure
|
||||||
- unless @procedure.logo.blank?
|
- unless @procedure.logo.blank?
|
||||||
= image_tag @procedure.decorate.logo_img, {style: 'height: 40px; display: inline; margin-right: 6px', id: 'preview_procedure_logo'}
|
= image_tag @procedure.decorate.logo_img, {style: 'height: 40px; display: inline; margin-right: 6px', id: 'preview_procedure_logo'}
|
||||||
= f.file_field(:logo, accept: 'image/png, image/jpg, image/jpeg', style: 'display:inline')
|
= f.file_field :logo, accept: 'image/png, image/jpg, image/jpeg', style: 'display:inline'
|
||||||
|
|
||||||
%div{style:'margin-top:5px'}
|
%div{style:'margin-top:5px'}
|
||||||
%i
|
%i
|
||||||
Fichier accepté : JPG / JPEG / PNG
|
Fichier accepté : JPG / JPEG / PNG
|
||||||
.col-xs-6
|
.col-md-6
|
||||||
%h4 Drapeau européen
|
%h4 Drapeau européen
|
||||||
.checkbox
|
.checkbox
|
||||||
%label
|
%label
|
||||||
=f.check_box :euro_flag
|
=f.check_box :euro_flag
|
||||||
Afficher le drapeau européen
|
Afficher le drapeau européen
|
||||||
|
|
||||||
|
- unless @procedure.locked?
|
||||||
.row
|
.row
|
||||||
.col-xs-6
|
.col-md-6
|
||||||
%h4 Cartographie
|
%h4 Cartographie
|
||||||
|
|
||||||
= f.fields_for :module_api_carto, @procedure.module_api_carto do |ff|
|
= f.fields_for :module_api_carto, @procedure.module_api_carto do |ff|
|
||||||
.checkbox
|
.checkbox
|
||||||
%label
|
%label
|
||||||
=ff.check_box :use_api_carto, {id: :procedure_module_api_carto_use_api_carto}
|
=ff.check_box :use_api_carto, id: :procedure_module_api_carto_use_api_carto
|
||||||
Utilisation de la cartographie
|
Utilisation de la cartographie
|
||||||
|
|
||||||
%ul#modules_api_carto
|
%ul#modules_api_carto
|
||||||
|
@ -47,29 +53,28 @@
|
||||||
= ff.check_box :cadastre
|
= ff.check_box :cadastre
|
||||||
Cadastre
|
Cadastre
|
||||||
|
|
||||||
.col-xs-6
|
.col-md-6
|
||||||
- if @procedure.cerfa_flag
|
- if @procedure.cerfa_flag
|
||||||
%h4 Formulaire de demande ou CERFA
|
%h4 Formulaire de demande ou CERFA
|
||||||
.checkbox
|
.checkbox
|
||||||
%label
|
%label
|
||||||
= f.check_box :cerfa_flag
|
= f.check_box :cerfa_flag
|
||||||
Activer l'envoi de formulaire de demande ou CERFA
|
Activer l'envoi de formulaire de demande ou CERFA
|
||||||
|
%br
|
||||||
= f.text_field :lien_demarche, class: 'form-control', placeholder: 'URL vers le formulaire vierge (facultatif)'
|
= f.text_field :lien_demarche, class: 'form-control', placeholder: 'URL vers le formulaire vierge (facultatif)'
|
||||||
|
|
||||||
.row
|
.row
|
||||||
.col-xs-6
|
.col-md-6
|
||||||
%h4 Particuliers
|
%h4 Particuliers
|
||||||
%ul.list-unstyled
|
|
||||||
%li
|
|
||||||
.checkbox
|
.checkbox
|
||||||
%label
|
%label
|
||||||
=f.check_box :for_individual
|
=f.check_box :for_individual
|
||||||
Cette procédure s'adresse à un public qui
|
Cette procédure s'adresse à un public qui
|
||||||
%b
|
%b
|
||||||
ne possède pas (ou pas encore) de numéro SIRET,
|
ne possède pas (ou pas encore) de numéro SIRET,
|
||||||
qui doit donc s'identifier en tant que personne physique.
|
qui doivent donc s'identifier en tant que personne physique.
|
||||||
|
|
||||||
%ul.list-unstyled#individual_with_siret{style:'margin-left: 15px'}
|
%ul#individual_with_siret
|
||||||
%li
|
%li
|
||||||
.checkbox
|
.checkbox
|
||||||
%label
|
%label
|
||||||
|
|
|
@ -2,6 +2,5 @@
|
||||||
#procedure_new.section.section-label
|
#procedure_new.section.section-label
|
||||||
= form_for @procedure, url: url_for({controller: 'admin/procedures', action: :update, id: @procedure.id}), multipart: true do |f|
|
= form_for @procedure, url: url_for({controller: 'admin/procedures', action: :update, id: @procedure.id}), multipart: true do |f|
|
||||||
= render partial: 'informations', locals: {f: f}
|
= render partial: 'informations', locals: {f: f}
|
||||||
|
|
||||||
.text-right
|
.text-right
|
||||||
= f.submit 'Editer', class: 'btn btn-success'
|
= f.submit 'Enregistrer', class: 'btn btn-success'
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
%div.procedure_list_element{class: ('active' if active == 'Accompagnateurs')}
|
%div.procedure_list_element{class: ('active' if active == 'Accompagnateurs')}
|
||||||
=t('dynamics.admin.procedure.onglets.accompagnateurs')
|
=t('dynamics.admin.procedure.onglets.accompagnateurs')
|
||||||
|
|
||||||
- unless @procedure.locked?
|
|
||||||
%a{:href => "#{url_for edit_admin_procedure_path(@procedure)}", id: 'onglet-description'}
|
%a{:href => "#{url_for edit_admin_procedure_path(@procedure)}", id: 'onglet-description'}
|
||||||
%div.procedure_list_element{class: ('active' if active == 'Description')}
|
%div.procedure_list_element{class: ('active' if active == 'Description')}
|
||||||
Description
|
Description
|
||||||
|
|
|
@ -13,6 +13,7 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
let(:use_api_carto) { '0' }
|
let(:use_api_carto) { '0' }
|
||||||
let(:quartiers_prioritaires) { '0' }
|
let(:quartiers_prioritaires) { '0' }
|
||||||
let(:cadastre) { '0' }
|
let(:cadastre) { '0' }
|
||||||
|
let(:cerfa_flag) { true }
|
||||||
|
|
||||||
let(:procedure_params) {
|
let(:procedure_params) {
|
||||||
{
|
{
|
||||||
|
@ -21,6 +22,7 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
organisation: organisation,
|
organisation: organisation,
|
||||||
direction: direction,
|
direction: direction,
|
||||||
lien_demarche: lien_demarche,
|
lien_demarche: lien_demarche,
|
||||||
|
cerfa_flag: cerfa_flag,
|
||||||
module_api_carto_attributes: {
|
module_api_carto_attributes: {
|
||||||
use_api_carto: use_api_carto,
|
use_api_carto: use_api_carto,
|
||||||
quartiers_prioritaires: quartiers_prioritaires,
|
quartiers_prioritaires: quartiers_prioritaires,
|
||||||
|
@ -105,24 +107,24 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
sign_out admin
|
sign_out admin
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(subject).to redirect_to new_user_session_path }
|
it { is_expected.to redirect_to new_user_session_path }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when user is connected' do
|
context 'when user is connected' do
|
||||||
context 'when procedure exist' do
|
context 'when procedure exist' do
|
||||||
let(:procedure_id) { procedure.id }
|
let(:procedure_id) { procedure.id }
|
||||||
it { expect(subject).to have_http_status(:success) }
|
it { is_expected.to have_http_status(:success) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when procedure is published' do
|
context 'when procedure is published' do
|
||||||
let(:published) { true }
|
let(:published) { true }
|
||||||
it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
|
it { is_expected.to have_http_status(:success) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when procedure doesn't exist" do
|
context "when procedure doesn't exist" do
|
||||||
let(:procedure_id) { bad_procedure_id }
|
let(:procedure_id) { bad_procedure_id }
|
||||||
|
|
||||||
it { expect(subject).to have_http_status(404) }
|
it { is_expected.to have_http_status(404) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -164,7 +166,7 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
it { expect(subject.quartiers_prioritaires).to be_truthy }
|
it { expect(subject.quartiers_prioritaires).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(subject).to redirect_to(admin_procedure_types_de_champ_path(procedure_id: Procedure.last.id)) }
|
it { is_expected.to redirect_to(admin_procedure_types_de_champ_path(procedure_id: Procedure.last.id)) }
|
||||||
|
|
||||||
it { expect(flash[:notice]).to be_present }
|
it { expect(flash[:notice]).to be_present }
|
||||||
end
|
end
|
||||||
|
@ -204,7 +206,7 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
|
|
||||||
subject { put :update, params: {id: procedure.id} }
|
subject { put :update, params: {id: procedure.id} }
|
||||||
|
|
||||||
it { expect(subject).to redirect_to new_user_session_path }
|
it { is_expected.to redirect_to new_user_session_path }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when administrateur is connected' do
|
context 'when administrateur is connected' do
|
||||||
|
@ -213,7 +215,7 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
procedure.reload
|
procedure.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when all attributs are informated' do
|
context 'when all attributs are present' do
|
||||||
let(:libelle) { 'Blable' }
|
let(:libelle) { 'Blable' }
|
||||||
let(:description) { 'blabla' }
|
let(:description) { 'blabla' }
|
||||||
let(:organisation) { 'plop' }
|
let(:organisation) { 'plop' }
|
||||||
|
@ -240,7 +242,7 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
it { expect(subject.cadastre).to be_truthy }
|
it { expect(subject.cadastre).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(subject).to redirect_to(edit_admin_procedure_path id: procedure.id) }
|
it { is_expected.to redirect_to(edit_admin_procedure_path id: procedure.id) }
|
||||||
it { expect(flash[:notice]).to be_present }
|
it { expect(flash[:notice]).to be_present }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -260,6 +262,26 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
it { expect(subject.cadastre).to be_falsey }
|
it { expect(subject.cadastre).to be_falsey }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when procedure is published' do
|
||||||
|
let!(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative, :published, administrateur: admin) }
|
||||||
|
|
||||||
|
describe 'only some properties can be updated' do
|
||||||
|
subject { procedure }
|
||||||
|
|
||||||
|
it { expect(subject.libelle).to eq procedure_params[:libelle] }
|
||||||
|
it { expect(subject.description).to eq procedure_params[:description] }
|
||||||
|
it { expect(subject.organisation).to eq procedure_params[:organisation] }
|
||||||
|
it { expect(subject.direction).to eq procedure_params[:direction] }
|
||||||
|
|
||||||
|
it { expect(subject.cerfa_flag).not_to eq procedure_params[:cerfa_flag] }
|
||||||
|
it { expect(subject.lien_demarche).not_to eq procedure_params[:lien_demarche] }
|
||||||
|
it { expect(subject.for_individual).not_to eq procedure_params[:for_individual] }
|
||||||
|
it { expect(subject.individual_with_siret).not_to eq procedure_params[:individual_with_siret] }
|
||||||
|
it { expect(subject.use_api_carto).not_to eq procedure_params[:module_api_carto_attributes][:use_api_carto] }
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ FactoryGirl.define do
|
||||||
organisation "Orga SGMAP"
|
organisation "Orga SGMAP"
|
||||||
direction "direction SGMAP"
|
direction "direction SGMAP"
|
||||||
published false
|
published false
|
||||||
|
cerfa_flag false
|
||||||
administrateur { create(:administrateur) }
|
administrateur { create(:administrateur) }
|
||||||
mail_templates { [create(:mail_template, :dossier_received)]}
|
mail_templates { [create(:mail_template, :dossier_received)]}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue