From 2fa88a432b8f901bb2744bda3fdd819795b015df Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Tue, 20 Mar 2018 17:47:37 +0100 Subject: [PATCH 1/8] Add missing brackets around parameters in method definitions --- app/controllers/france_connect/particulier_controller.rb | 2 +- app/controllers/users/dossiers_controller.rb | 4 ++-- app/controllers/users/registrations_controller.rb | 2 +- app/controllers/users_controller.rb | 6 +++--- app/decorators/dossier_decorator.rb | 2 +- app/decorators/type_de_champ_decorator.rb | 6 +++--- app/decorators/type_de_piece_justificative_decorator.rb | 4 ++-- app/facades/admin_procedures_show_facades.rb | 2 +- app/facades/admin_types_de_champ_facades.rb | 8 ++++---- app/facades/invite_dossier_facades.rb | 2 +- app/lib/carto/geo_api/driver.rb | 2 +- app/lib/carto/sgmap/cadastre/adapter.rb | 2 +- app/mailers/administration_mailer.rb | 2 +- app/mailers/gestionnaire_mailer.rb | 6 +++--- app/mailers/invite_mailer.rb | 8 ++++---- app/mailers/welcome_mailer.rb | 2 +- app/models/champ.rb | 6 +++--- app/models/dossier.rb | 4 ++-- app/models/gestionnaire.rb | 2 +- app/models/procedure.rb | 8 ++++---- app/models/user.rb | 4 ++-- app/services/clamav_service.rb | 2 +- app/services/geojson_service.rb | 4 ++-- app/services/module_api_carto_service.rb | 8 ++++---- app/services/number_service.rb | 2 +- app/services/pieces_justificatives_service.rb | 2 +- app/services/previsualisation_service.rb | 2 +- app/services/render_partial_service.rb | 4 ++-- app/services/switch_devise_profile_service.rb | 2 +- app/services/sync_credentials_service.rb | 2 +- app/services/types_de_champ_service.rb | 2 +- app/services/user_routes_authorization_service.rb | 2 +- ...0160802113112_build_default_preference_list_dossier.rb | 4 ++-- .../20161007095443_reset_all_preference_list_dossier.rb | 8 ++++---- 34 files changed, 64 insertions(+), 64 deletions(-) diff --git a/app/controllers/france_connect/particulier_controller.rb b/app/controllers/france_connect/particulier_controller.rb index 8116e9b2b..c8a255ffa 100644 --- a/app/controllers/france_connect/particulier_controller.rb +++ b/app/controllers/france_connect/particulier_controller.rb @@ -34,7 +34,7 @@ class FranceConnect::ParticulierController < ApplicationController end end - def connect_france_connect_particulier user + 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? diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 0c384447f..59a93f2f6 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -257,11 +257,11 @@ class Users::DossiersController < UsersController redirect_to url_for users_dossiers_path end - def update_current_user_siret! siret + def update_current_user_siret!(siret) current_user.update(siret: siret) end - def facade id = params[:id] + def facade(id = params[:id]) DossierFacades.new id, current_user.email end end diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 3de89b1cd..526c97c4d 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -69,7 +69,7 @@ class Users::RegistrationsController < Devise::RegistrationsController private - def check_invite! user + def check_invite!(user) Invite.where(email: user.email).update_all user_id: user.id end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a3545612e..b4c35eefd 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,7 +5,7 @@ class UsersController < ApplicationController redirect_to root_path end - def current_user_dossier dossier_id = nil + def current_user_dossier(dossier_id = nil) dossier_id ||= params[:dossier_id] || params[:id] dossier = Dossier.find(dossier_id) @@ -15,7 +15,7 @@ class UsersController < ApplicationController raise ActiveRecord::RecordNotFound end - def authorized_routes? controller + def authorized_routes?(controller) if !UserRoutesAuthorizationService.authorized_route?(controller, current_user_dossier) redirect_to_root_path 'Le statut de votre dossier n\'autorise pas cette URL' end @@ -26,7 +26,7 @@ class UsersController < ApplicationController private - def redirect_to_root_path message + def redirect_to_root_path(message) flash.alert = message redirect_to url_for root_path end diff --git a/app/decorators/dossier_decorator.rb b/app/decorators/dossier_decorator.rb index 532be3f41..e42ba1496 100644 --- a/app/decorators/dossier_decorator.rb +++ b/app/decorators/dossier_decorator.rb @@ -16,7 +16,7 @@ class DossierDecorator < Draper::Decorator DossierDecorator.case_state_fr state end - def self.case_state_fr state = self.state + def self.case_state_fr(state = self.state) h.t("activerecord.attributes.dossier.state.#{state}") end end diff --git a/app/decorators/type_de_champ_decorator.rb b/app/decorators/type_de_champ_decorator.rb index 32cbbbdd6..1c2225159 100644 --- a/app/decorators/type_de_champ_decorator.rb +++ b/app/decorators/type_de_champ_decorator.rb @@ -1,7 +1,7 @@ class TypeDeChampDecorator < Draper::Decorator delegate_all - def button_up params + def button_up(params) h.link_to '', params[:url], class: up_classes, id: "btn_up_#{params[:index]}", remote: true, @@ -9,7 +9,7 @@ class TypeDeChampDecorator < Draper::Decorator style: display_up_button?(params[:index], params[:private]) ? '' : 'visibility: hidden;' end - def button_down params + def button_down(params) h.link_to '', params[:url], class: down_classes, id: "btn_down_#{params[:index]}", remote: true, @@ -39,7 +39,7 @@ class TypeDeChampDecorator < Draper::Decorator (index + 1) < count_type_de_champ(private) end - def count_type_de_champ private + def count_type_de_champ(private) if private @count_type_de_champ ||= procedure.types_de_champ_private.count else diff --git a/app/decorators/type_de_piece_justificative_decorator.rb b/app/decorators/type_de_piece_justificative_decorator.rb index a0737cafc..eb2bb6200 100644 --- a/app/decorators/type_de_piece_justificative_decorator.rb +++ b/app/decorators/type_de_piece_justificative_decorator.rb @@ -1,10 +1,10 @@ class TypeDePieceJustificativeDecorator < Draper::Decorator delegate_all - def button_up params + 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]) end - def button_down params + 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]) end diff --git a/app/facades/admin_procedures_show_facades.rb b/app/facades/admin_procedures_show_facades.rb index b099f5c43..34dbd2d3e 100644 --- a/app/facades/admin_procedures_show_facades.rb +++ b/app/facades/admin_procedures_show_facades.rb @@ -1,5 +1,5 @@ class AdminProceduresShowFacades - def initialize procedure + def initialize(procedure) @procedure = procedure end diff --git a/app/facades/admin_types_de_champ_facades.rb b/app/facades/admin_types_de_champ_facades.rb index eefe7e57c..6570e5bef 100644 --- a/app/facades/admin_types_de_champ_facades.rb +++ b/app/facades/admin_types_de_champ_facades.rb @@ -1,7 +1,7 @@ class AdminTypesDeChampFacades include Rails.application.routes.url_helpers - def initialize private, procedure + def initialize(private, procedure) @private = private @procedure = procedure end @@ -30,15 +30,15 @@ class AdminTypesDeChampFacades @private ? :types_de_champ_private : :types_de_champ end - def move_up_url ff + def move_up_url(ff) @private ? move_up_admin_procedure_types_de_champ_private_path(@procedure, ff.index) : move_up_admin_procedure_types_de_champ_path(@procedure, ff.index) end - def move_down_url ff + def move_down_url(ff) @private ? move_down_admin_procedure_types_de_champ_private_path(@procedure, ff.index) : move_down_admin_procedure_types_de_champ_path(@procedure, ff.index) end - def delete_url ff + def delete_url(ff) @private ? admin_procedure_type_de_champ_private_path(@procedure, ff.object.id) : admin_procedure_type_de_champ_path(@procedure, ff.object.id) end diff --git a/app/facades/invite_dossier_facades.rb b/app/facades/invite_dossier_facades.rb index 895e6a684..138e0e131 100644 --- a/app/facades/invite_dossier_facades.rb +++ b/app/facades/invite_dossier_facades.rb @@ -1,6 +1,6 @@ class InviteDossierFacades < DossierFacades # TODO rechercher en fonction de la personne/email - def initialize id, email + def initialize(id, email) @dossier = Invite.where(email: email, id: id).first!.dossier end end diff --git a/app/lib/carto/geo_api/driver.rb b/app/lib/carto/geo_api/driver.rb index d37e17e87..45f664427 100644 --- a/app/lib/carto/geo_api/driver.rb +++ b/app/lib/carto/geo_api/driver.rb @@ -23,7 +23,7 @@ module Carto private - def self.call api_url + def self.call(api_url) RestClient.get api_url, params: { fields: :nom } rescue RestClient::ServiceUnavailable nil diff --git a/app/lib/carto/sgmap/cadastre/adapter.rb b/app/lib/carto/sgmap/cadastre/adapter.rb index ae9d0bce5..8f71b731c 100644 --- a/app/lib/carto/sgmap/cadastre/adapter.rb +++ b/app/lib/carto/sgmap/cadastre/adapter.rb @@ -16,7 +16,7 @@ class CARTO::SGMAP::Cadastre::Adapter end end - def filter_properties properties + def filter_properties(properties) { surface_intersection: properties[:surface_intersection], surface_parcelle: properties[:surface_parcelle], diff --git a/app/mailers/administration_mailer.rb b/app/mailers/administration_mailer.rb index a7954908c..ffc86f402 100644 --- a/app/mailers/administration_mailer.rb +++ b/app/mailers/administration_mailer.rb @@ -1,7 +1,7 @@ class AdministrationMailer < ApplicationMailer layout 'mailers/layout' - def new_admin_email admin, administration + def new_admin_email(admin, administration) @admin = admin @administration = administration diff --git a/app/mailers/gestionnaire_mailer.rb b/app/mailers/gestionnaire_mailer.rb index aaff2c253..4f3c88113 100644 --- a/app/mailers/gestionnaire_mailer.rb +++ b/app/mailers/gestionnaire_mailer.rb @@ -1,7 +1,7 @@ class GestionnaireMailer < ApplicationMailer layout 'mailers/layout' - def new_gestionnaire email, password + def new_gestionnaire(email, password) send_mail email, password, "Vous avez été nommé accompagnateur sur demarches-simplifiees.fr" end @@ -21,12 +21,12 @@ class GestionnaireMailer < ApplicationMailer private - def vars_mailer email, args + def vars_mailer(email, args) @args = args @email = email end - def send_mail email, args, subject + def send_mail(email, args, subject) vars_mailer email, args mail(to: email, subject: subject) diff --git a/app/mailers/invite_mailer.rb b/app/mailers/invite_mailer.rb index f8ff6e5c6..48c326464 100644 --- a/app/mailers/invite_mailer.rb +++ b/app/mailers/invite_mailer.rb @@ -1,11 +1,11 @@ class InviteMailer < ApplicationMailer - def invite_user invite + def invite_user(invite) vars_mailer invite send_mail invite.email, "demarches-simplifiees.fr - Participez à l'élaboration d'un dossier", invite.email_sender if invite.user.present? end - def invite_guest invite + def invite_guest(invite) vars_mailer invite send_mail invite.email, "Invitation - #{invite.email_sender} vous invite à consulter un dossier sur demarches-simplifiees.fr", invite.email_sender @@ -13,11 +13,11 @@ class InviteMailer < ApplicationMailer private - def vars_mailer invite + def vars_mailer(invite) @invite = invite end - def send_mail email, subject, reply_to + def send_mail(email, subject, reply_to) mail(to: email, subject: subject, reply_to: reply_to) diff --git a/app/mailers/welcome_mailer.rb b/app/mailers/welcome_mailer.rb index 81075ea34..65b309eda 100644 --- a/app/mailers/welcome_mailer.rb +++ b/app/mailers/welcome_mailer.rb @@ -1,5 +1,5 @@ class WelcomeMailer < ApplicationMailer - def welcome_email user + def welcome_email(user) @user = user mail(to: user.email, diff --git a/app/models/champ.rb b/app/models/champ.rb index 1b3f6cf4e..c1ff823f5 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -37,11 +37,11 @@ class Champ < ApplicationRecord !private? end - def same_hour? num + def same_hour?(num) same_date? num, '%H' end - def same_minute? num + def same_minute?(num) same_date? num, '%M' end @@ -53,7 +53,7 @@ class Champ < ApplicationRecord end end - def same_date? num, compare + def same_date?(num, compare) if type_champ == 'datetime' && value.present? if value.to_datetime.strftime(compare) == num return true diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 1ec85c57e..9d2aaaa43 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -193,11 +193,11 @@ class Dossier < ApplicationRecord en_instruction? || accepte? || refuse? || sans_suite? end - def owner? email + def owner?(email) user.email == email end - def invite_by_user? email + def invite_by_user?(email) (invites_user.pluck :email).include? email end diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 6fc42851d..73ee2a1b9 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -146,7 +146,7 @@ class Gestionnaire < ApplicationRecord private - def valid_couple_table_attr? table, column + def valid_couple_table_attr?(table, column) couples = [ { table: :dossier, diff --git a/app/models/procedure.rb b/app/models/procedure.rb index daddb0ab7..3e1378feb 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -66,19 +66,19 @@ class Procedure < ApplicationRecord types_de_champ + types_de_champ_private end - def self.active id + def self.active(id) publiees.find(id) end - def switch_types_de_champ index_of_first_element + def switch_types_de_champ(index_of_first_element) switch_list_order(types_de_champ_ordered, index_of_first_element) end - def switch_types_de_champ_private index_of_first_element + def switch_types_de_champ_private(index_of_first_element) switch_list_order(types_de_champ_private_ordered, index_of_first_element) end - def switch_types_de_piece_justificative index_of_first_element + def switch_types_de_piece_justificative(index_of_first_element) switch_list_order(types_de_piece_justificative, index_of_first_element) end diff --git a/app/models/user.rb b/app/models/user.rb index 83c030beb..7140bf745 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -23,7 +23,7 @@ class User < ApplicationRecord before_validation -> { sanitize_email(:email) } - def self.find_for_france_connect email, siret + def self.find_for_france_connect(email, siret) user = User.find_by(email: email) if user.nil? return User.create(email: email, password: Devise.friendly_token[0, 20], siret: siret) @@ -37,7 +37,7 @@ class User < ApplicationRecord loged_in_with_france_connect.present? end - def invite? dossier_id + def invite?(dossier_id) invites.pluck(:dossier_id).include?(dossier_id.to_i) end end diff --git a/app/services/clamav_service.rb b/app/services/clamav_service.rb index 7c7e9be67..e8e04a021 100644 --- a/app/services/clamav_service.rb +++ b/app/services/clamav_service.rb @@ -1,5 +1,5 @@ class ClamavService - def self.safe_file? file_path + def self.safe_file?(file_path) if Rails.env == 'development' return CLAMAV[:response] if CLAMAV[:mock?] end diff --git a/app/services/geojson_service.rb b/app/services/geojson_service.rb index 27a80aa4e..7bcf59bdc 100644 --- a/app/services/geojson_service.rb +++ b/app/services/geojson_service.rb @@ -1,5 +1,5 @@ class GeojsonService - def self.to_json_polygon_for_qp coordinates + def self.to_json_polygon_for_qp(coordinates) polygon = { geo: { type: "Polygon", @@ -10,7 +10,7 @@ class GeojsonService polygon.to_json end - def self.to_json_polygon_for_cadastre coordinates + def self.to_json_polygon_for_cadastre(coordinates) polygon = { geom: { type: "Feature", diff --git a/app/services/module_api_carto_service.rb b/app/services/module_api_carto_service.rb index 492a2543d..50206bf64 100644 --- a/app/services/module_api_carto_service.rb +++ b/app/services/module_api_carto_service.rb @@ -1,5 +1,5 @@ class ModuleApiCartoService - def self.save_qp! dossier, json_latlngs + def self.save_qp!(dossier, json_latlngs) if dossier.procedure.module_api_carto.quartiers_prioritaires? qp_list = generate_qp JSON.parse(json_latlngs) @@ -11,7 +11,7 @@ class ModuleApiCartoService end end - def self.save_cadastre! dossier, json_latlngs + def self.save_cadastre!(dossier, json_latlngs) if dossier.procedure.module_api_carto.cadastre? cadastre_list = generate_cadastre JSON.parse(json_latlngs) @@ -23,7 +23,7 @@ class ModuleApiCartoService end end - def self.generate_qp coordinates + def self.generate_qp(coordinates) coordinates.inject({}) { |acc, coordinate| acc.merge CARTO::SGMAP::QuartiersPrioritaires::Adapter.new( coordinate.map { |element| [element['lng'], element['lat']] } @@ -31,7 +31,7 @@ class ModuleApiCartoService } end - def self.generate_cadastre coordinates + def self.generate_cadastre(coordinates) coordinates.flat_map do |coordinate| CARTO::SGMAP::Cadastre::Adapter.new( coordinate.map { |element| [element['lng'], element['lat']] } diff --git a/app/services/number_service.rb b/app/services/number_service.rb index 722b5cac4..bc399d5ef 100644 --- a/app/services/number_service.rb +++ b/app/services/number_service.rb @@ -1,5 +1,5 @@ class NumberService - def self.to_number string + def self.to_number(string) string.to_s if Float(string) rescue nil end end diff --git a/app/services/pieces_justificatives_service.rb b/app/services/pieces_justificatives_service.rb index a99e1334f..52a5d5249 100644 --- a/app/services/pieces_justificatives_service.rb +++ b/app/services/pieces_justificatives_service.rb @@ -15,7 +15,7 @@ class PiecesJustificativesService .compact() end - def self.upload_one! dossier, user, params + def self.upload_one!(dossier, user, params) content = params[:piece_justificative][:content] if ClamavService.safe_file? content.path pj = PieceJustificative.new(content: content, diff --git a/app/services/previsualisation_service.rb b/app/services/previsualisation_service.rb index 7f8a9e692..dbca1fc90 100644 --- a/app/services/previsualisation_service.rb +++ b/app/services/previsualisation_service.rb @@ -1,5 +1,5 @@ class PrevisualisationService - def self.delete_all_champs dossier + def self.delete_all_champs(dossier) Champ.where(dossier_id: dossier.id, type_de_champ_id: dossier.procedure.types_de_champ.ids).delete_all end end diff --git a/app/services/render_partial_service.rb b/app/services/render_partial_service.rb index 186c8f633..82ef25a54 100644 --- a/app/services/render_partial_service.rb +++ b/app/services/render_partial_service.rb @@ -1,7 +1,7 @@ class RenderPartialService attr_accessor :controller, :method - def initialize controller, method + def initialize(controller, method) @controller = controller @method = method end @@ -14,7 +14,7 @@ class RenderPartialService retrieve_left_panel end - def self.left_panel_exist? left_panel_url + def self.left_panel_exist?(left_panel_url) file = left_panel_url.split('/').last File.exist?(Rails.root.join('app','views', 'layouts', 'left_panels', "_#{file}.html.haml")) diff --git a/app/services/switch_devise_profile_service.rb b/app/services/switch_devise_profile_service.rb index 814efac83..d5fcde170 100644 --- a/app/services/switch_devise_profile_service.rb +++ b/app/services/switch_devise_profile_service.rb @@ -1,5 +1,5 @@ class SwitchDeviseProfileService - def initialize warden + def initialize(warden) @warden = warden end diff --git a/app/services/sync_credentials_service.rb b/app/services/sync_credentials_service.rb index 4b3fa3072..9b723d076 100644 --- a/app/services/sync_credentials_service.rb +++ b/app/services/sync_credentials_service.rb @@ -1,5 +1,5 @@ class SyncCredentialsService - def initialize klass, email_before_last_save, email, encrypted_password + def initialize(klass, email_before_last_save, email, encrypted_password) @klass = klass @email_before_last_save = email_before_last_save @email = email diff --git a/app/services/types_de_champ_service.rb b/app/services/types_de_champ_service.rb index 614e6b5fe..f4b1796ca 100644 --- a/app/services/types_de_champ_service.rb +++ b/app/services/types_de_champ_service.rb @@ -72,7 +72,7 @@ class TypesDeChampService (tdca[:order_place].to_i + 1) != tdca[:custom_order_place].to_i end - def self.clean_value value + def self.clean_value(value) value.split("\r\n").map{ |v| v.strip }.join("\r\n") end end diff --git a/app/services/user_routes_authorization_service.rb b/app/services/user_routes_authorization_service.rb index 5507cdbbd..a60c5b415 100644 --- a/app/services/user_routes_authorization_service.rb +++ b/app/services/user_routes_authorization_service.rb @@ -1,5 +1,5 @@ class UserRoutesAuthorizationService - def self.authorized_route? controller, dossier + def self.authorized_route?(controller, dossier) auth = controller.route_authorization auth[:states].include?(dossier.state.to_sym) && diff --git a/db/migrate/20160802113112_build_default_preference_list_dossier.rb b/db/migrate/20160802113112_build_default_preference_list_dossier.rb index 69efaefe1..4c4206780 100644 --- a/db/migrate/20160802113112_build_default_preference_list_dossier.rb +++ b/db/migrate/20160802113112_build_default_preference_list_dossier.rb @@ -19,7 +19,7 @@ class BuildDefaultPreferenceListDossier < ActiveRecord::Migration end end - def valid_couple_table_attr? table, column + def valid_couple_table_attr?(table, column) couples = [ { table: :dossier, @@ -110,7 +110,7 @@ class BuildDefaultPreferenceListDossier < ActiveRecord::Migration } end - def self.create_column libelle, table, attr, attr_decorate, bootstrap_lg + def self.create_column(libelle, table, attr, attr_decorate, bootstrap_lg) { libelle: libelle, table: table, diff --git a/db/migrate/20161007095443_reset_all_preference_list_dossier.rb b/db/migrate/20161007095443_reset_all_preference_list_dossier.rb index d0d08f4d3..4a64b721b 100644 --- a/db/migrate/20161007095443_reset_all_preference_list_dossier.rb +++ b/db/migrate/20161007095443_reset_all_preference_list_dossier.rb @@ -3,7 +3,7 @@ class ResetAllPreferenceListDossier < ActiveRecord::Migration belongs_to :gestionnaire belongs_to :procedure - def self.available_columns_for procedure_id = nil + def self.available_columns_for(procedure_id = nil) columns = { dossier: columns_dossier, procedure: columns_procedure, @@ -78,7 +78,7 @@ class ResetAllPreferenceListDossier < ActiveRecord::Migration } end - def self.create_column libelle, table, attr, attr_decorate, bootstrap_lg + def self.create_column(libelle, table, attr, attr_decorate, bootstrap_lg) { libelle: libelle, table: table, @@ -95,7 +95,7 @@ class ResetAllPreferenceListDossier < ActiveRecord::Migration has_many :assign_to, dependent: :destroy has_many :procedures, through: :assign_to - def build_default_preferences_list_dossier procedure_id = nil + def build_default_preferences_list_dossier(procedure_id = nil) PreferenceListDossier.available_columns_for(procedure_id).each do |table| table.second.each do |column| if valid_couple_table_attr? table.first, column.first @@ -117,7 +117,7 @@ class ResetAllPreferenceListDossier < ActiveRecord::Migration private - def valid_couple_table_attr? table, column + def valid_couple_table_attr?(table, column) couples = [ { table: :dossier, From ecc0f884176cff647536891cf26f0623958d7c45 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 20 Mar 2018 17:54:45 +0100 Subject: [PATCH 2/8] Enable the cop that checks for brackets in method definitions --- .rubocop.yml | 2 +- ...2017_10_30_copy_commentaire_piece_justificative_to_file.rake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 6c9c0f40a..191080540 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -990,7 +990,7 @@ Style/MethodCalledOnDoEndBlock: Enabled: false Style/MethodDefParentheses: - Enabled: false + Enabled: true Style/MethodMissing: Enabled: false diff --git a/lib/tasks/2017_10_30_copy_commentaire_piece_justificative_to_file.rake b/lib/tasks/2017_10_30_copy_commentaire_piece_justificative_to_file.rake index 8f7591941..5da2e35e2 100644 --- a/lib/tasks/2017_10_30_copy_commentaire_piece_justificative_to_file.rake +++ b/lib/tasks/2017_10_30_copy_commentaire_piece_justificative_to_file.rake @@ -26,7 +26,7 @@ namespace :'2017_10_30_copy_commentaire_piece_justificative_to_file' do return name.mb_chars.to_s end - def process_commentaire commentaire + def process_commentaire(commentaire) puts "Processing commentaire #{commentaire.id}" if commentaire.piece_justificative.present? # https://github.com/carrierwaveuploader/carrierwave#uploading-files-from-a-remote-location From 04b4fac89c6ac7e1127b905a380dac6b889376da Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Wed, 21 Mar 2018 19:58:37 +0100 Subject: [PATCH 3/8] Upgrade loofah 2.2.0 -> 2.2.1 to fix CVE-2018-8048 --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3d82d807f..497a70518 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -457,7 +457,7 @@ GEM activesupport (>= 4.0) logstash-event (~> 1.2.0) request_store - loofah (2.2.0) + loofah (2.2.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) lumberjack (1.0.12) From 9e566596fac580b647ae00f62eeffeb8179336fd Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 20 Mar 2018 16:33:51 +0100 Subject: [PATCH 4/8] [fix #1601] show pipedrive demandes in manager --- README.md | 8 +++- .../manager/demandes_controller.rb | 47 +++++++++++++++++++ app/models/demande.rb | 9 ++++ app/views/manager/demandes/index.html.erb | 34 ++++++++++++++ config/routes.rb | 2 + 5 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 app/controllers/manager/demandes_controller.rb create mode 100644 app/models/demande.rb create mode 100644 app/views/manager/demandes/index.html.erb diff --git a/README.md b/README.md index c375c5a97..138540bc1 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,13 @@ client_id: '' client_secret: '' ``` -*Note : les valeurs pour ces deux paramètres sont renseignées dans le Keepass* +## Connexion a Pipedrive + +Dans le fichier `config/intializers/token.rb`, ajouter + +`PIPEDRIVE_TOKEN = 'token'` + +*Note : les valeurs pour ces paramètres sont renseignées dans le Keepass* ## Création des comptes initiaux diff --git a/app/controllers/manager/demandes_controller.rb b/app/controllers/manager/demandes_controller.rb new file mode 100644 index 000000000..87e7bcb74 --- /dev/null +++ b/app/controllers/manager/demandes_controller.rb @@ -0,0 +1,47 @@ +module Manager + class DemandesController < Manager::ApplicationController + PIPEDRIVE_PEOPLE_URL = 'https://api.pipedrive.com/v1/persons' + PIPEDRIVE_POSTE_ATTRIBUTE_ID = '33a790746f1713d712fe97bcce9ac1ca6374a4d6' + PIPEDRIVE_DEV_ID = '2748449' + + def index + @pending_demandes = pending_demandes + end + + private + + def pending_demandes + already_approved_emails = Administrateur + .where(email: demandes.map { |d| d[:email] }) + .pluck(:email) + + demandes.reject { |demande| already_approved_emails.include?(demande[:email]) } + end + + def demandes + @demandes ||= fetch_demandes + end + + def fetch_demandes + params = { + start: 0, + limit: 500, + user_id: PIPEDRIVE_DEV_ID, + api_token: PIPEDRIVE_TOKEN + } + + response = RestClient.get(PIPEDRIVE_PEOPLE_URL, { params: params }) + json = JSON.parse(response.body) + + json['data'].map do |datum| + { + person_id: datum['id'], + nom: datum['name'], + poste: datum[PIPEDRIVE_POSTE_ATTRIBUTE_ID], + email: datum.dig('email', 0, 'value'), + organisation: datum['org_name'] + } + end + end + end +end diff --git a/app/models/demande.rb b/app/models/demande.rb new file mode 100644 index 000000000..132282727 --- /dev/null +++ b/app/models/demande.rb @@ -0,0 +1,9 @@ +class Demande + def self.model_name + self + end + + def self.human(*args) + "Demandes" + end +end diff --git a/app/views/manager/demandes/index.html.erb b/app/views/manager/demandes/index.html.erb new file mode 100644 index 000000000..21470f7b2 --- /dev/null +++ b/app/views/manager/demandes/index.html.erb @@ -0,0 +1,34 @@ +<% content_for(:title) do %> + <%= display_resource_name('Demandes') %> +<% end %> + + + +
+ + + <% keys = @pending_demandes.first.keys %> + + <% keys.each do |key| %> + + <% end %> + + + <% @pending_demandes.each do |demande| %> + + <% keys.each do |key| %> + + <% end %> + + <% end %> + +
+ <%= key %> +
+ <%= demande[key] %> +
+
diff --git a/config/routes.rb b/config/routes.rb index 3c2c56c1e..2dcbd0b23 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,6 +10,8 @@ Rails.application.routes.draw do post 'reinvite', on: :member end + resources :demandes, only: [:index] + authenticate :administration do match "/delayed_job" => DelayedJobWeb, :anchor => false, :via => [:get, :post] end From 9eb28faa10e5bdf99885c2252aade24e16f54b4b Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 21 Mar 2018 10:28:17 +0100 Subject: [PATCH 5/8] [fix #1601] accept demandes in manager --- .../manager/demandes_controller.rb | 27 +++++++++++++++++++ app/views/manager/demandes/index.html.erb | 7 +++++ config/routes.rb | 1 + 3 files changed, 35 insertions(+) diff --git a/app/controllers/manager/demandes_controller.rb b/app/controllers/manager/demandes_controller.rb index 87e7bcb74..513bbcf38 100644 --- a/app/controllers/manager/demandes_controller.rb +++ b/app/controllers/manager/demandes_controller.rb @@ -3,13 +3,40 @@ module Manager PIPEDRIVE_PEOPLE_URL = 'https://api.pipedrive.com/v1/persons' PIPEDRIVE_POSTE_ATTRIBUTE_ID = '33a790746f1713d712fe97bcce9ac1ca6374a4d6' PIPEDRIVE_DEV_ID = '2748449' + PIPEDRIVE_CAMILLE_ID = '3189424' def index @pending_demandes = pending_demandes end + def create_administrateur + administrateur = current_administration.invite_admin(create_administrateur_params[:email]) + + if administrateur.errors.empty? + change_person_owner(create_administrateur_params[:person_id], PIPEDRIVE_CAMILLE_ID) + flash.notice = "Administrateur créé" + redirect_to manager_demandes_path + else + flash.now.alert = administrateur.errors.full_messages + @pending_demandes = pending_demandes + render :index + end + end + private + def change_person_owner(person_id, owner_id) + url = PIPEDRIVE_PEOPLE_URL + "/#{person_id}?api_token=#{PIPEDRIVE_TOKEN}" + + params = { 'owner_id': owner_id } + + RestClient.put(url, params.to_json, { content_type: :json }) + end + + def create_administrateur_params + params.require(:administrateur).permit(:email, :person_id) + end + def pending_demandes already_approved_emails = Administrateur .where(email: demandes.map { |d| d[:email] }) diff --git a/app/views/manager/demandes/index.html.erb b/app/views/manager/demandes/index.html.erb index 21470f7b2..526619635 100644 --- a/app/views/manager/demandes/index.html.erb +++ b/app/views/manager/demandes/index.html.erb @@ -18,6 +18,8 @@ <%= key %> <% end %> + + <% @pending_demandes.each do |demande| %> @@ -27,6 +29,11 @@ <%= demande[key] %> <% end %> + + <%= button_to('Créer', + manager_demandes_create_administrateur_path, + params: { administrateur: { email: demande[:email], person_id: demande[:person_id] } }) %> + <% end %> diff --git a/config/routes.rb b/config/routes.rb index 2dcbd0b23..e694b323b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,6 +11,7 @@ Rails.application.routes.draw do end resources :demandes, only: [:index] + post 'demandes/create_administrateur' authenticate :administration do match "/delayed_job" => DelayedJobWeb, :anchor => false, :via => [:get, :post] From c413dfa127f43813e9608ebb154e0b4dbc04cf57 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 22 Mar 2018 09:15:32 +0100 Subject: [PATCH 6/8] [#1677] No longer create `InviteGestionnaire`s --- app/controllers/invites_controller.rb | 3 +- spec/controllers/invites_controller_spec.rb | 69 +++++++++++---------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb index 6405bca0f..1e029e731 100644 --- a/app/controllers/invites_controller.rb +++ b/app/controllers/invites_controller.rb @@ -30,11 +30,10 @@ class InvitesController < ApplicationController private def gestionnaire_or_user? - if !user_signed_in? && !gestionnaire_signed_in? + if !user_signed_in? return redirect_to root_path end @current_devise_profil = current_user if user_signed_in? - @current_devise_profil = current_gestionnaire if gestionnaire_signed_in? end end diff --git a/spec/controllers/invites_controller_spec.rb b/spec/controllers/invites_controller_spec.rb index 2e6c47bfd..3765184e1 100644 --- a/spec/controllers/invites_controller_spec.rb +++ b/spec/controllers/invites_controller_spec.rb @@ -17,8 +17,7 @@ describe InvitesController, type: :controller do let(:signed_in_profile) { create(:gestionnaire) } shared_examples_for "he can not create invitation" do - it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) } - it { expect { subject rescue nil }.to change(InviteGestionnaire, :count).by(0) } + it { expect { subject rescue nil }.to change(Invite, :count).by(0) } end context 'when gestionnaire has no access to dossier' do @@ -36,18 +35,47 @@ describe InvitesController, type: :controller do signed_in_profile.procedures << dossier.procedure end - it { expect { subject }.to change(InviteGestionnaire, :count).by(1) } + it_behaves_like "he can not create invitation" context 'when is a user who is loged' do + let(:user) { create(:user) } before do - sign_in create(:user) + dossier.update(user: user) + sign_in(user) end - it { expect { subject }.to change(InviteGestionnaire, :count).by(1) } + it { expect { subject }.to change(InviteUser, :count).by(1) } + end + end + end + + context "when user is signed_in" do + let(:signed_in_profile) { create(:user) } + + shared_examples_for "he can not create a invite" do + it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) } + it { expect { subject rescue nil }.to change(InviteUser, :count).by(0) } + end + + context 'when user has no access to dossier' do + it_behaves_like "he can not create a invite" + end + + context 'when user is invited on dossier' do + before { Invite.create(user: signed_in_profile, email: signed_in_profile.email, dossier: dossier) } + + it_behaves_like "he can not create a invite" + end + + context 'when user has access to dossier' do + before do + dossier.update(user: signed_in_profile) end + it { expect { subject }.to change(InviteUser, :count).by(1) } + context 'when email is assign to an user' do - let! (:user) { create(:user, email: email) } + let! (:user_invite) { create(:user, email: email) } before do subject @@ -62,7 +90,7 @@ describe InvitesController, type: :controller do end end - it { expect(invite.user).to eq user } + it { expect(invite.user).to eq user_invite } it { expect(flash[:notice]).to be_present } end @@ -124,32 +152,5 @@ describe InvitesController, type: :controller do end end end - - context "when user is signed_in" do - let(:signed_in_profile) { create(:user) } - - shared_examples_for "he can not create a invite" do - it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) } - it { expect { subject rescue nil }.to change(InviteUser, :count).by(0) } - end - - context 'when user has no access to dossier' do - it_behaves_like "he can not create a invite" - end - - context 'when user is invited on dossier' do - before { Invite.create(user: signed_in_profile, email: signed_in_profile.email, dossier: dossier) } - - it_behaves_like "he can not create a invite" - end - - context 'when user has access to dossier' do - before do - dossier.update(user: signed_in_profile) - end - - it { expect { subject }.to change(InviteUser, :count).by(1) } - end - end end end From cab670b1ad94d35481400fa992251a5938d2d05b Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 22 Mar 2018 09:31:07 +0100 Subject: [PATCH 7/8] [#1677] Simplify code --- app/controllers/invites_controller.rb | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb index 1e029e731..8e5518d7f 100644 --- a/app/controllers/invites_controller.rb +++ b/app/controllers/invites_controller.rb @@ -1,16 +1,15 @@ class InvitesController < ApplicationController - before_action :gestionnaire_or_user? + before_action :ensure_user_signed_in def create - email_sender = @current_devise_profil.email - - class_var = @current_devise_profil.class == User ? InviteUser : InviteGestionnaire - dossier = @current_devise_profil.dossiers.find(params[:dossier_id]) - email = params[:email].downcase - user = User.find_by(email: email) - invite = class_var.create(dossier: dossier, user: user, email: email, email_sender: email_sender) + invite = InviteUser.create( + dossier: current_user.dossiers.find(params[:dossier_id]), + user: User.find_by(email: email), + email: email, + email_sender: current_user.email + ) if invite.valid? if invite.user.present? @@ -29,11 +28,9 @@ class InvitesController < ApplicationController private - def gestionnaire_or_user? + def ensure_user_signed_in if !user_signed_in? return redirect_to root_path end - - @current_devise_profil = current_user if user_signed_in? end end From 5b04fa2a4c24b9f61b1b6ce47689804cfe902b10 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 21 Mar 2018 11:01:06 +0100 Subject: [PATCH 8/8] [Fix #1687] Align sign in/up form to the top --- app/assets/stylesheets/new_design/layouts.scss | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/assets/stylesheets/new_design/layouts.scss b/app/assets/stylesheets/new_design/layouts.scss index af089682b..d155581a3 100644 --- a/app/assets/stylesheets/new_design/layouts.scss +++ b/app/assets/stylesheets/new_design/layouts.scss @@ -16,7 +16,7 @@ @media (min-width: $two-columns-breakpoint) { flex-direction: row; - align-items: center; + align-items: stretch; justify-content: center; } } @@ -25,7 +25,6 @@ padding: $two-columns-padding 0 0; width: 100%; max-width: 500px; - margin: auto; @media (min-width: $two-columns-breakpoint) { padding: $two-columns-padding;