Merge pull request #2721 from betagouv/end-if

Do one thing per line
This commit is contained in:
gregoirenovel 2018-10-01 16:18:44 +02:00 committed by GitHub
commit 696f3cd8f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 186 additions and 62 deletions

View file

@ -16,7 +16,10 @@ class Admin::InstructeursController < AdminController
array: true
not_assign_scope = current_administrateur.gestionnaires.where.not(id: assign_scope.ids)
not_assign_scope = not_assign_scope.where("email LIKE ?", "%#{params[:filter]}%") if params[:filter]
if params[:filter]
not_assign_scope = not_assign_scope.where("email LIKE ?", "%#{params[:filter]}%")
end
@instructeurs_not_assign = smart_listing_create :instructeurs_not_assign,
not_assign_scope,

View file

@ -55,7 +55,9 @@ class Admin::ProceduresController < AdminController
def destroy
procedure = current_administrateur.procedures.find(params[:id])
return render json: {}, status: 401 if procedure.publiee_ou_archivee?
if procedure.publiee_ou_archivee?
return render json: {}, status: 401
end
procedure.destroy
@ -72,7 +74,11 @@ class Admin::ProceduresController < AdminController
def create
@procedure = Procedure.new(procedure_params)
@procedure.module_api_carto = ModuleAPICarto.new(create_module_api_carto_params) if @procedure.valid?
if @procedure.valid?
@procedure.module_api_carto = ModuleAPICarto.new(create_module_api_carto_params)
end
@path = params.require(:procedure).permit(:path)[:path]
@available = !ProcedurePath.exists?(path: @path)
@mine = ProcedurePath.mine?(current_administrateur, @path)

View file

@ -5,7 +5,10 @@ class Administrations::SessionsController < ApplicationController
end
def destroy
sign_out :administration if administration_signed_in?
if administration_signed_in?
sign_out :administration
end
redirect_to root_path
end
end

View file

@ -1,7 +1,10 @@
class CommentairesController < ApplicationController
def create
@commentaire = Commentaire.new
@commentaire.champ = @commentaire.dossier.champs.find(params[:champ_id]) if params[:champ_id]
if params[:champ_id]
@commentaire.champ = @commentaire.dossier.champs.find(params[:champ_id])
end
dossier_id = params['dossier_id']
@commentaire.email = current_user.email

View file

@ -36,9 +36,17 @@ class FranceConnect::ParticulierController < ApplicationController
end
def connect_france_connect_particulier(user)
sign_out :user if user_signed_in?
sign_out :gestionnaire if gestionnaire_signed_in?
sign_out :administrateur if administrateur_signed_in?
if user_signed_in?
sign_out :user
end
if gestionnaire_signed_in?
sign_out :gestionnaire
end
if administrateur_signed_in?
sign_out :administrateur
end
sign_in user

View file

@ -36,14 +36,20 @@ class Gestionnaires::PasswordsController < Devise::PasswordsController
def try_to_authenticate_user
if gestionnaire_signed_in?
user = User.find_by(email: current_gestionnaire.email)
sign_in user if user
if user
sign_in user
end
end
end
def try_to_authenticate_administrateur
if gestionnaire_signed_in?
administrateur = Administrateur.find_by(email: current_gestionnaire.email)
sign_in administrateur if administrateur
if administrateur
sign_in administrateur
end
end
end
end

View file

@ -131,7 +131,10 @@ module NewGestionnaire
def position
etablissement = dossier.etablissement
point = Carto::Geocodeur.convert_adresse_to_point(etablissement.geo_adresse) if etablissement.present?
if etablissement.present?
point = Carto::Geocodeur.convert_adresse_to_point(etablissement.geo_adresse)
end
lon = "2.428462"
lat = "46.538192"

View file

@ -2,9 +2,20 @@ class Sessions::SessionsController < Devise::SessionsController
before_action :before_sign_in, only: [:create]
def before_sign_in
sign_out :user if user_signed_in?
sign_out :gestionnaire if gestionnaire_signed_in?
sign_out :administrateur if administrateur_signed_in?
sign_out :administration if administration_signed_in?
if user_signed_in?
sign_out :user
end
if gestionnaire_signed_in?
sign_out :gestionnaire
end
if administrateur_signed_in?
sign_out :administrateur
end
if administration_signed_in?
sign_out :administration
end
end
end

View file

@ -35,7 +35,9 @@ class Users::CarteController < UsersController
etablissement = nil
end
point = Carto::Geocodeur.convert_adresse_to_point(etablissement.geo_adresse) if etablissement.present?
if etablissement.present?
point = Carto::Geocodeur.convert_adresse_to_point(etablissement.geo_adresse)
end
lon = '2.428462'
lat = '46.538192'

View file

@ -2,7 +2,10 @@ class Users::DescriptionController < UsersController
def pieces_justificatives
invite = current_user.invite? params[:dossier_id]
@dossier ||= Dossier.find(params[:dossier_id]) if invite
if invite
@dossier ||= Dossier.find(params[:dossier_id])
end
@dossier ||= current_user_dossier
if (errors_upload = PiecesJustificativesService.upload!(@dossier, current_user, params)).present?
@ -13,10 +16,14 @@ class Users::DescriptionController < UsersController
end
else
flash.notice = 'Nouveaux fichiers envoyés' if flash.alert.nil?
if flash.alert.nil?
flash.notice = 'Nouveaux fichiers envoyés'
end
end
return redirect_to users_dossiers_invite_path(id: current_user.invites.find_by(dossier_id: @dossier.id).id) if invite
if invite
return redirect_to users_dossiers_invite_path(id: current_user.invites.find_by(dossier_id: @dossier.id).id)
end
redirect_to users_dossier_recapitulatif_path
end

View file

@ -2,10 +2,13 @@ class Users::Dossiers::AddSiretController < ApplicationController
def show
@facade = DossierFacades.new params[:dossier_id], current_user.email
raise ActiveRecord::RecordNotFound if !@facade.procedure.individual_with_siret?
@siret = current_user.siret if current_user.siret.present?
if !@facade.procedure.individual_with_siret?
raise ActiveRecord::RecordNotFound
end
if current_user.siret.present?
@siret = current_user.siret
end
rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for dossiers_path

View file

@ -54,7 +54,9 @@ class Users::DossiersController < UsersController
dossier = Dossier.create!(procedure: procedure, user: current_user, state: Dossier.states.fetch(:brouillon))
siret = params[:siret] || current_user.siret
update_current_user_siret! siret if siret.present?
if siret.present?
update_current_user_siret! siret
end
if dossier.procedure.for_individual
redirect_to identite_dossier_path(dossier)
@ -67,7 +69,9 @@ class Users::DossiersController < UsersController
def show
@facade = facade
@siret = current_user.siret if current_user.siret.present?
if current_user.siret.present?
@siret = current_user.siret
end
if @facade.procedure.for_individual? && current_user.loged_in_with_france_connect?
individual = @facade.dossier.individual
@ -165,7 +169,9 @@ class Users::DossiersController < UsersController
private
def check_siret
errors_valid_siret if !Siret.new(siret: siret).valid?
if !Siret.new(siret: siret).valid?
errors_valid_siret
end
end
def errors_valid_siret

View file

@ -36,14 +36,20 @@ class Users::PasswordsController < Devise::PasswordsController
def try_to_authenticate_gestionnaire
if user_signed_in?
gestionnaire = Gestionnaire.find_by(email: current_user.email)
sign_in gestionnaire if gestionnaire
if gestionnaire
sign_in gestionnaire
end
end
end
def try_to_authenticate_administrateur
if user_signed_in?
administrateur = Administrateur.find_by(email: current_user.email)
sign_in administrateur if administrateur
if administrateur
sign_in administrateur
end
end
end
end

View file

@ -13,7 +13,10 @@ class Users::RegistrationsController < Devise::RegistrationsController
# Allow pre-filling the user email from a query parameter
build_resource({ email: sign_up_params[:email] })
yield resource if block_given?
if block_given?
yield resource
end
respond_with resource
end

View file

@ -39,8 +39,13 @@ class Users::SessionsController < Sessions::SessionsController
# DELETE /resource/sign_out
def destroy
sign_out :gestionnaire if gestionnaire_signed_in?
sign_out :administrateur if administrateur_signed_in?
if gestionnaire_signed_in?
sign_out :gestionnaire
end
if administrateur_signed_in?
sign_out :administrateur
end
if user_signed_in?
connected_with_france_connect = current_user.loged_in_with_france_connect
@ -72,7 +77,9 @@ class Users::SessionsController < Sessions::SessionsController
end
def user_return_to_procedure_id
return nil if session["user_return_to"].nil?
if session["user_return_to"].nil?
return nil
end
NumberService.to_number session["user_return_to"].split("?procedure_id=").second
end

View file

@ -30,6 +30,8 @@ class ChampDecorator < Draper::Decorator
end
def description_with_links
description.gsub(URI.regexp, '<a target="_blank" href="\0">\0</a>') if description
if description
description.gsub(URI.regexp, '<a target="_blank" href="\0">\0</a>')
end
end
end

View file

@ -1,11 +1,15 @@
class TypeDePieceJustificativeDecorator < Draper::Decorator
delegate_all
def button_up(params)
h.link_to '', params[:url], class: up_classes, id: "btn_up_#{params[:index]}", remote: true, method: :post if display_up_button?(params[:index])
if display_up_button?(params[:index])
h.link_to '', params[:url], class: up_classes, id: "btn_up_#{params[:index]}", remote: true, method: :post
end
end
def button_down(params)
h.link_to '', params[:url], class: down_classes, id: "btn_down_#{params[:index]}", remote: true, method: :post if display_down_button?(params[:index])
if display_down_button?(params[:index])
h.link_to '', params[:url], class: down_classes, id: "btn_down_#{params[:index]}", remote: true, method: :post
end
end
private

View file

@ -10,9 +10,15 @@ class FileSizeValidator < ActiveModel::EachValidator
range = options.delete(:in) || options.delete(:within)
if range.present?
raise ArgumentError, ":in and :within must be a Range" if !range.is_a?(Range)
if !range.is_a?(Range)
raise ArgumentError, ":in and :within must be a Range"
end
options[:minimum], options[:maximum] = range.begin, range.end
options[:maximum] -= 1 if range.exclude_end?
if range.exclude_end?
options[:maximum] -= 1
end
end
super
@ -35,12 +41,18 @@ class FileSizeValidator < ActiveModel::EachValidator
end
def validate_each(record, attribute, value)
raise(ArgumentError, "A CarrierWave::Uploader::Base object was expected") if !value.kind_of? CarrierWave::Uploader::Base
if !value.kind_of? CarrierWave::Uploader::Base
raise(ArgumentError, "A CarrierWave::Uploader::Base object was expected")
end
value = (options[:tokenizer] || DEFAULT_TOKENIZER).call(value) if value.kind_of?(String)
if value.kind_of?(String)
value = (options[:tokenizer] || DEFAULT_TOKENIZER).call(value)
end
CHECKS.each do |key, validity_check|
next if !check_value = options[key]
if !check_value = options[key]
next
end
check_value =
case check_value
@ -50,16 +62,22 @@ class FileSizeValidator < ActiveModel::EachValidator
record.send(check_value)
end
value ||= [] if key == :maximum
if key == :maximum
value ||= []
end
value_size = value.size
next if value_size.send(validity_check, check_value)
if value_size.send(validity_check, check_value)
next
end
errors_options = options.except(*RESERVED_OPTIONS)
errors_options[:file_size] = help.number_to_human_size check_value
default_message = options[MESSAGES[key]]
errors_options[:message] ||= default_message if default_message
if default_message
errors_options[:message] ||= default_message
end
record.errors.add(attribute, MESSAGES[key], errors_options)
end

View file

@ -31,7 +31,9 @@ class Gestionnaire < ApplicationRecord
end
def follow(dossier)
return if follow?(dossier)
if follow?(dossier)
return
end
followed_dossiers << dossier
end

View file

@ -6,10 +6,15 @@ class ModuleAPICarto < ApplicationRecord
validates :cadastre, presence: true, allow_blank: true, allow_nil: false
def classes
modules = ''
modules = ''
modules += 'qp ' if quartiers_prioritaires?
modules += 'cadastre ' if cadastre?
if quartiers_prioritaires?
modules += 'qp '
end
if cadastre?
modules += 'cadastre '
end
modules
end

View file

@ -10,6 +10,8 @@ class Siret
before_validation :remove_whitespace
def remove_whitespace
siret.delete!(' ') if siret.present?
if siret.present?
siret.delete!(' ')
end
end
end

View file

@ -1,7 +1,9 @@
class ClamavService
def self.safe_file?(file_path)
if Rails.env == 'development'
return CLAMAV[:response] if CLAMAV[:mock?]
if CLAMAV[:mock?]
return CLAMAV[:response]
end
end
FileUtils.chmod 0666, file_path
@ -9,7 +11,10 @@ class ClamavService
client = ClamAV::Client.new
response = client.execute(ClamAV::Commands::ScanCommand.new(file_path))
return false if response.first.class == ClamAV::VirusResponse
if response.first.class == ClamAV::VirusResponse
return false
end
true
end
end

View file

@ -1,5 +1,5 @@
class NumberService
def self.to_number(string)
string.to_s if Float(string) rescue nil
string.to_s
end
end

View file

@ -48,6 +48,8 @@ class PieceJustificativeUploader < BaseUploader
end
def set_original_filename(file)
model.original_filename ||= file.original_filename if file.respond_to?(:original_filename)
if file.respond_to?(:original_filename)
model.original_filename ||= file.original_filename
end
end
end

View file

@ -4,7 +4,12 @@ class ProcedurePathFormatValidator < ActiveModel::Validator
end
def validate(record)
return false if record.path.blank?
record.errors[:path] << "Path invalide" if !path_regex.match(record.path)
if record.path.blank?
return false
end
if !path_regex.match(record.path)
record.errors[:path] << "Path invalide"
end
end
end

View file

@ -18,15 +18,17 @@ class CreateFranceConnectInformation < ActiveRecord::Migration
add_reference :france_connect_informations, :user, references: :users
User.all.each do |user|
FranceConnectInformation.create({
gender: user.gender,
given_name: user.given_name,
family_name: user.family_name,
birthdate: user.birthdate,
birthplace: user.birthplace,
france_connect_particulier_id: user.france_connect_particulier_id,
user_id: user.id
}) if user.france_connect_particulier_id.present?
if user.france_connect_particulier_id.present?
FranceConnectInformation.create({
gender: user.gender,
given_name: user.given_name,
family_name: user.family_name,
birthdate: user.birthdate,
birthplace: user.birthplace,
france_connect_particulier_id: user.france_connect_particulier_id,
user_id: user.id
})
end
end
remove_column :users, :gender