Skip to content

Commit

Permalink
adapt code to new rubocop rules
Browse files Browse the repository at this point in the history
  • Loading branch information
aminedhobb committed Jan 28, 2025
1 parent dcd331d commit 5294a11
Show file tree
Hide file tree
Showing 42 changed files with 66 additions and 71 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ Style/StringConcatenation:
Style/SymbolArray:
Enabled: false

Style/SafeNavigationChainLength:
Max: 3

Rails/SkipsModelValidations:
Enabled: false

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def motif_category_attributes
end

def user_params
params.require(:user).permit(*PERMITTED_USER_PARAMS).to_h.deep_symbolize_keys
params.expect(user: [*PERMITTED_USER_PARAMS]).to_h.deep_symbolize_keys
end

def set_organisation
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/archives_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ def destroy # rubocop:disable Metrics/AbcSize
private

def archive_params
params.require(:archive).permit(:archiving_reason, :user_id, :organisation_id).to_h.deep_symbolize_keys
params.expect(archive: [:archiving_reason, :user_id, :organisation_id]).to_h.deep_symbolize_keys
end

def create_many_params
params.require(:archives).permit(:user_id, :archiving_reason, organisation_ids: []).to_h.deep_symbolize_keys
params.expect(archives: [:user_id, :archiving_reason, { organisation_ids: [] }]).to_h.deep_symbolize_keys
end

def set_user
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/brevo/mail_webhooks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def record_identifier
end

def brevo_webhook_params
params.permit(*PERMITTED_PARAMS).to_h.deep_symbolize_keys
params.expect(*PERMITTED_PARAMS).to_h.deep_symbolize_keys
end
end
end
3 changes: 2 additions & 1 deletion app/controllers/brevo/sms_webhooks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def record_identifier
end

def brevo_webhook_params
params.permit(*PERMITTED_PARAMS).to_h.deep_symbolize_keys
params.expect(*PERMITTED_PARAMS).to_h.deep_symbolize_keys
end
end
end

2 changes: 1 addition & 1 deletion app/controllers/carnet_de_bord/carnets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def create
private

def carnet_params
params.require(:carnet).permit(:user_id, :department_id)
params.expect(carnet: [:user_id, :department_id])
end

def set_user
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/category_configurations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def destroy
private

def category_configuration_params
params.require(:category_configuration).permit(*PERMITTED_PARAMS).to_h.deep_symbolize_keys
params.expect(category_configuration: PERMITTED_PARAMS).to_h.deep_symbolize_keys
end

def formatted_configuration_params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def set_authorized_agent_role_ids
end

def csv_export_authorizations_params
params.require(:csv_export_authorizations).permit(:organisation_id, agent_role_ids: [])
params.expect(csv_export_authorizations: [:organisation_id, { agent_role_ids: [] }])
end

def set_organisation
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/concerns/before_action_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def before_action(*names, &block)
end
end

def method_missing(method_name, *args)
def method_missing(method_name, *)
return super unless method_name.to_s.end_with?("for_#{action_name}")

splitted_method_name = method_name.to_s.split("_")
Expand All @@ -42,7 +42,7 @@ def method_missing(method_name, *args)
if respond_to?(matching_method, true)
send(matching_method)
else
super(matching_method, *args)
super(matching_method, *)
end
end

Expand Down
6 changes: 3 additions & 3 deletions app/controllers/concerns/users/filterable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def filter_users_by_orientation_type
.joins(orientations: :orientation_type)
.where(orientation_types: { name: params[:orientation_type] })
.where(orientations: { organisations: { department_id: current_department_id } })
.where("orientations.starts_at <= ?", Time.zone.now)
.where(orientations: { starts_at: ..Time.zone.now })
.where("orientations.ends_at IS NULL OR orientations.ends_at >= ?", Time.zone.now)
end

Expand Down Expand Up @@ -85,15 +85,15 @@ def filter_users_by_creation_date_after
def filter_users_by_creation_date_before
return if params[:creation_date_before].blank?

@users = @users.where("users.created_at < ?", params[:creation_date_before].to_date.end_of_day)
@users = @users.where(users: { created_at: ...params[:creation_date_before].to_date.end_of_day })
end

def filter_users_by_convocation_date_before
return if params[:convocation_date_before].blank?

@users = @users.joins(participations: :notifications)
.where(participations: { convocable: true, follow_up: @follow_ups })
.where("notifications.created_at < ?", params[:convocation_date_before].to_date.end_of_day)
.where(notifications: { created_at: ...params[:convocation_date_before].to_date.end_of_day })
end

def filter_users_by_convocation_date_after
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/file_configurations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def update
private

def file_configuration_params
params.require(:file_configuration).permit(*PERMITTED_PARAMS).to_h.deep_symbolize_keys
params.expect(file_configuration: PERMITTED_PARAMS)
end

def formatted_params
Expand Down
12 changes: 2 additions & 10 deletions app/controllers/follow_ups_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
class FollowUpsController < ApplicationController
PERMITTED_PARAMS = [:user_id, :motif_category_id].freeze

before_action :set_user, only: [:create]

def create
@follow_up = FollowUp.new(**follow_up_params)
@follow_up = FollowUp.new(follow_up_params)
authorize @follow_up
if save_follow_up.success?
redirect_to request.referer
Expand All @@ -16,11 +12,7 @@ def create
private

def follow_up_params
params.require(:follow_up).permit(*PERMITTED_PARAMS).to_h.deep_symbolize_keys
end

def set_user
@user = policy_scope(User).preload(:archives).find(follow_up_params[:user_id])
params.expect(follow_up: [:user_id, :motif_category_id])
end

def save_follow_up
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/invitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def redirect
private

def invitation_params
params.require(:invitation).permit(
:format, :rdv_solidarites_lieu_id, { motif_category: [:id] }
params.expect(
invitation: [:format, :rdv_solidarites_lieu_id, { motif_category: [:id] }]
).to_h.deep_symbolize_keys
end

Expand Down
8 changes: 4 additions & 4 deletions app/controllers/messages_configurations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def edit; end

def create
@messages_configuration = MessagesConfiguration.new(organisation: @organisation)
@messages_configuration.assign_attributes(**formatted_params)
@messages_configuration.assign_attributes(formatted_params)
if @messages_configuration.save
flash.now[:success] = "Les réglages ont été modifiés avec succès"
redirect_to organisation_category_configurations_path(@organisation)
Expand All @@ -28,7 +28,7 @@ def create
end

def update
@messages_configuration.assign_attributes(**formatted_params)
@messages_configuration.assign_attributes(formatted_params)
if @messages_configuration.save
flash.now[:success] = "Les réglages ont été modifiés avec succès"
render :show
Expand All @@ -41,13 +41,13 @@ def update
private

def messages_configuration_params
params.require(:messages_configuration).permit(*PERMITTED_PARAMS).to_h.deep_symbolize_keys
params.expect(messages_configuration: PERMITTED_PARAMS)
end

def formatted_params
# we nullify some blank params
messages_configuration_params.to_h do |k, v|
[k, k.in?([:sms_sender_name, :letter_sender_name, :sender_city]) ? v.presence : v]
[k, k.to_sym.in?([:sms_sender_name, :letter_sender_name, :sender_city]) ? v.presence : v]
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def set_participation
end

def notification_params
params.require(:notification).permit(:format, :event)
params.expect(notification: [:format, :event])
end

def notify_participation
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/organisations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def show; end
def edit; end

def update
@organisation.assign_attributes(**organisation_params)
@organisation.assign_attributes(organisation_params)
authorize @organisation
if update_organisation.success?
render :show
Expand Down Expand Up @@ -62,7 +62,7 @@ def search
private

def organisation_params
params.require(:organisation).permit(*PERMITTED_PARAMS).to_h.deep_symbolize_keys
params.expect(organisation: PERMITTED_PARAMS)
end

def set_organisation
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/participations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ def set_participation
end

def participation_params
params.require(:participation).permit(:status)
params.expect(participation: [:status])
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def duplicate
private

def webhook_endpoint_params
params.require(:webhook_endpoint).permit(:target_id)
params.expect(webhook_endpoint: [:target_id])
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ def set_organisation
end

def tag_params
params.require(:tag).permit(:value)
params.expect(tag: [:value])
end
end
4 changes: 2 additions & 2 deletions app/controllers/users/orientations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def destroy
private

def orientation_params
params.require(:orientation).permit(:starts_at, :ends_at, :orientation_type_id,
:organisation_id, :agent_id)
params.expect(orientation: [:starts_at, :ends_at, :orientation_type_id,
:organisation_id, :agent_id])
end

def set_user
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/users/parcours_documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def destroy
private

def parcours_document_params
params.require(:parcours_document)
.permit(:type, :file, :user_id, :document_date)
.merge(agent: current_agent, user: @user)
.merge(department: current_department)
params
.expect(parcours_document: [:type, :file, :user_id, :document_date])
.merge(agent: current_agent, user: @user)
.merge(department: current_department)
end

def set_parcours_document
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users/referent_assignations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def destroy
private

def referent_assignation_params
params.require(:referent_assignation).permit(:agent_email, :agent_id)
params.expect(referent_assignation: [:agent_email, :agent_id])
end

def agent_id
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/users/searches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def search_in_department_organisations
end

def users_params
params.require(:users).permit(
nirs: [], department_internal_ids: [], uids: [], emails: [], phone_numbers: []
params.expect(
users: [nirs: [], department_internal_ids: [], uids: [], emails: [], phone_numbers: []]
).to_h.deep_symbolize_keys
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users/tag_assignations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def set_user
end

def tag_assignation_params
params.require(:tag_assignation).permit(tag_ids: [])
params.expect(tag_assignation: [tag_ids: []])
end

def department
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def update
private

def user_params
params.require(:user).permit(*PERMITTED_PARAMS).to_h.deep_symbolize_keys
params.expect(user: PERMITTED_PARAMS).to_h.deep_symbolize_keys
end

def restricted_user_attributes = UserPolicy.restricted_user_attributes_for(user: @user, agent: current_agent)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_organisations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def destroy
private

def users_organisation_params
params.require(:users_organisation).permit(:organisation_id, :user_id)
params.expect(users_organisation: [:organisation_id, :user_id])
end

def user_id
Expand Down
4 changes: 2 additions & 2 deletions app/dashboards/unavailable_creneau_log_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class UnavailableCreneauLogDashboard < Administrate::BaseDashboard
FORM_ATTRIBUTES = %i[].freeze

COLLECTION_FILTERS = {
created_before: ->(resources, value) { resources.where("created_at <= ?", value) },
created_after: ->(resources, value) { resources.where("created_at >= ?", value) }
created_before: ->(resources, value) { resources.where(created_at: ..value) },
created_after: ->(resources, value) { resources.where(created_at: value..) }
}.freeze

def display_resource(unavailable_creneau_log)
Expand Down
4 changes: 2 additions & 2 deletions app/jobs/concerns/locked_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ module LockedJobs

private

def perform_with_lock(&block)
def perform_with_lock(&)
# if the lock is not available, we raise an WithAdvisoryLock::FailedToAcquireLockError
# and the job will be retried
ActiveRecord::Base.with_advisory_lock!(
self.class.lock_key(*arguments), timeout_seconds: 0, &block
self.class.lock_key(*arguments), timeout_seconds: 0, &
)
end

Expand Down
6 changes: 3 additions & 3 deletions app/jobs/destroy_old_ressources_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def destroy_inactive_users # rubocop:disable Metrics/MethodLength
# we check the orgs because being added to an organisation is a sign that the user is in an active process
inactive_users =
User.left_outer_joins(:invitations, :participations, :users_organisations)
.where("users.created_at < ?", date_limit)
.where(users: { created_at: ...date_limit })
.where("NOT EXISTS (
SELECT 1
FROM invitations
Expand All @@ -38,7 +38,7 @@ def destroy_inactive_users # rubocop:disable Metrics/MethodLength
end

def destroy_useless_rdvs
useless_rdvs = Rdv.where.missing(:participations).where("rdvs.created_at < ?", date_limit)
useless_rdvs = Rdv.where.missing(:participations).where(rdvs: { created_at: ...date_limit })

# On envoit pas de webhook de destroy rgpd pour les rdvs du département 13
bdr_rdv_ids = useless_rdvs.joins(organisation: :department)
Expand All @@ -60,7 +60,7 @@ def destroy_useless_rdvs

def destroy_useless_notifications
# notifications with no participation_id are useless code-wise, so we can clean them manually
useless_notifications = Notification.where(participation_id: nil).where("created_at < ?", date_limit).destroy_all
useless_notifications = Notification.where(participation_id: nil).where(created_at: ...date_limit).destroy_all

MattermostClient.send_to_notif_channel(
"🚮 Les notifications suivantes ont été supprimées automatiquement : " \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def perform
private

def expired_archives
Archive.where("created_at < ?", 2.years.ago)
Archive.where(created_at: ...2.years.ago)
end

def notify_on_mattermost
Expand Down
4 changes: 2 additions & 2 deletions app/lib/redis_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module RedisConnection
Redis.new(url: Rails.configuration.x.redis_url)
end

def self.with_redis(&block)
CONNECTION_POOL.with(&block)
def self.with_redis(&)
CONNECTION_POOL.with(&)
end
end
Loading

0 comments on commit 5294a11

Please sign in to comment.