Skip to content

Commit

Permalink
Merge tag '2020-09-29-01' into issue/import-france
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/services/procedure_export_service.rb
  • Loading branch information
maatinito committed Oct 13, 2020
2 parents 5413287 + 05391be commit 0cafc4f
Show file tree
Hide file tree
Showing 29 changed files with 143 additions and 133 deletions.
37 changes: 34 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ Layout/SpaceInsideReferenceBrackets:
Layout/SpaceInsideStringInterpolation:
Enabled: true

Layout/Tab:
Layout/IndentationStyle:
Enabled: true

Layout/TrailingEmptyLines:
Expand Down Expand Up @@ -507,7 +507,7 @@ Lint/UselessAssignment:
Exclude:
- "spec/**/*"

Lint/UselessComparison:
Lint/BinaryOperatorWithIdenticalOperands:
Enabled: true

Lint/UselessElseWithoutRescue:
Expand Down Expand Up @@ -1046,7 +1046,7 @@ Style/MethodCalledOnDoEndBlock:
Style/MethodDefParentheses:
Enabled: true

Style/MethodMissingSuper:
Lint/MissingSuper:
Enabled: false

Style/MinMax:
Expand Down Expand Up @@ -1316,3 +1316,34 @@ Style/YodaCondition:

Style/ZeroLengthPredicate:
Enabled: true

Rails/ActiveRecordCallbacksOrder:
Enabled: false
Rails/AfterCommitOverride:
Enabled: true
Rails/FindById:
Enabled: true
Rails/Inquiry:
Enabled: true
Rails/MailerName:
Enabled: true
Rails/MatchRoute:
Enabled: true
Rails/NegateInclude:
Enabled: false
Rails/Pluck:
Enabled: false
Rails/PluckInWhere:
Enabled: true
Rails/RenderInline:
Enabled: true
Rails/RenderPlainText:
Enabled: true
Rails/ShortI18n:
Enabled: true
Rails/SquishedSQLHeredocs:
Enabled: true
Rails/WhereExists:
Enabled: true
Rails/WhereNot:
Enabled: true
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ source 'https://rubygems.org'
gem 'aasm'
gem 'active_link_to' # Automatically set a class on active links
gem 'active_model_serializers'
gem 'active_storage_validations'
gem 'activestorage-openstack'
gem 'active_storage_validations'
gem 'administrate'
gem 'after_party'
gem 'anchored'
Expand All @@ -31,13 +31,13 @@ gem 'flipper-active_record'
gem 'flipper-ui'
gem 'font-awesome-rails'
gem 'fugit'
gem 'geo_coord', require: "geo/coord"
gem 'geocoder'
gem 'geo_coord', require: "geo/coord"
gem 'gon'
gem 'graphql'
gem 'graphql-batch'
gem 'graphql-rails_logger'
gem 'graphql_playground-rails'
gem 'graphql-rails_logger'
gem 'groupdate'
gem 'haml-rails'
gem 'hashie'
Expand Down Expand Up @@ -120,8 +120,8 @@ group :development, :test do
gem 'graphql-schema_comparator'
gem 'mina', git: 'https://github.com/mina-deploy/mina.git', require: false # Deploy
gem 'pry-byebug'
gem 'rspec-rails'
gem 'rspec_junit_formatter', require: false
gem 'rspec-rails'
gem 'ruby-debug-ide', require: false
gem 'simple_xlsx_reader'
gem 'spring' # Spring speeds up development by keeping your application running in the background
Expand Down
37 changes: 21 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ GEM
bootstrap-wysihtml5-rails (0.3.3.8)
railties (>= 3.0)
brakeman (4.9.1)
browser (4.2.0)
browser (5.0.0)
builder (3.2.4)
byebug (11.1.3)
capybara (3.33.0)
Expand Down Expand Up @@ -265,7 +265,7 @@ GEM
et-orbi (~> 1.1, >= 1.1.8)
raabro (~> 1.1)
geo_coord (0.1.0)
geocoder (1.6.2)
geocoder (1.6.3)
globalid (0.4.2)
activesupport (>= 4.2.0)
gon (6.3.2)
Expand Down Expand Up @@ -344,7 +344,6 @@ GEM
iban-tools (1.1.0)
ice_nine (0.11.2)
ipaddress (0.8.3)
jaro_winkler (1.5.4)
jquery-rails (4.4.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
Expand All @@ -354,7 +353,7 @@ GEM
aes_key_wrap
bindata
jsonapi-renderer (0.2.2)
jwt (2.2.1)
jwt (2.2.2)
kaminari (1.2.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.1)
Expand Down Expand Up @@ -450,7 +449,7 @@ GEM
webfinger (>= 1.0.1)
orm_adapter (0.5.0)
parallel (1.19.2)
parser (2.7.1.4)
parser (2.7.1.5)
ast (~> 2.4.1)
pdf-core (0.7.0)
pg (1.2.3)
Expand Down Expand Up @@ -557,7 +556,7 @@ GEM
execjs
railties (>= 3.2)
tilt
regexp_parser (1.7.1)
regexp_parser (1.8.0)
request_store (1.5.0)
rack (>= 1.4)
responders (3.0.1)
Expand Down Expand Up @@ -602,23 +601,28 @@ GEM
rspec-support (3.9.3)
rspec_junit_formatter (0.4.1)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (0.81.0)
jaro_winkler (~> 1.5.1)
rubocop (0.92.0)
parallel (~> 1.10)
parser (>= 2.7.0.1)
parser (>= 2.7.1.5)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.7)
rexml
rubocop-ast (>= 0.5.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-performance (1.5.2)
rubocop (>= 0.71.0)
rubocop-rails (2.5.2)
activesupport
rubocop-ast (0.7.0)
parser (>= 2.7.1.5)
strscan (>= 1.0.0)
rubocop-performance (1.8.1)
rubocop (>= 0.87.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.8.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 0.72.0)
rubocop-rails_config (0.10.0)
rubocop (>= 0.87.0)
rubocop-rails_config (0.12.6)
railties (>= 5.0)
rubocop (~> 0.80)
rubocop (~> 0.82)
rubocop-performance (~> 1.3)
rubocop-rails (~> 2.0)
rubocop-rspec-focused (1.0.0)
Expand Down Expand Up @@ -690,6 +694,7 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
strscan (1.0.3)
swd (1.1.2)
activesupport (>= 3)
attr_required (>= 0.0.5)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/champs/numero_dn_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def show
if @dn.empty?
return @status = :empty
end
if @dn !~ /\d{6,7}/
if !/\d{6,7}/.match?(@dn)
return @status = :bad_dn_format
end
begin
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def avis_usage
if weekly_dossiers_count == 0
result = 0
else
weekly_dossier_with_avis_count = weekly_dossiers.filter { |dossier| dossier.avis.present? }.count
weekly_dossier_with_avis_count = weekly_dossiers.count { |dossier| dossier.avis.present? }
result = percentage(weekly_dossier_with_avis_count, weekly_dossiers_count)
end

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/champ_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def geo_area_label(geo_area)
when GeoArea.sources.fetch(:cadastre)
capture do
concat "Parcelle n° #{geo_area.numero} - Feuille #{geo_area.code_arr} #{geo_area.section} #{geo_area.feuille} - #{geo_area.surface_parcelle.round} m"
concat content_tag(:sup, "2")
concat tag.sup("2")
end
when GeoArea.sources.fetch(:quartier_prioritaire)
"#{geo_area.commune} : #{geo_area.nom}"
Expand All @@ -48,7 +48,7 @@ def geo_area_label(geo_area)
if geo_area.area.present?
capture do
concat "Une aire de surface #{geo_area.area} m"
concat content_tag(:sup, "2")
concat tag.sup("2")
end
else
"Une aire de surface inconnue"
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/dossier_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def dossier_legacy_state(dossier)
def status_badge(state)
status_text = dossier_display_state(state, lower: true)
status_class = state.tr('_', '-')
content_tag(:span, status_text, class: "label #{status_class} ")
tag.span(status_text, class: "label #{status_class} ")
end

def deletion_reason_badge(reason)
Expand All @@ -87,7 +87,7 @@ def deletion_reason_badge(reason)
status_class = 'unknown'
end

content_tag(:span, status_text, class: "label #{status_class} ")
tag.span(status_text, class: "label #{status_class} ")
end

def demandeur_dossier(dossier)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/procedure_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def procedure_lien(procedure)
end

def procedure_libelle(procedure)
parts = procedure.brouillon? ? [content_tag(:span, 'démarche en test', class: 'badge')] : []
parts = procedure.brouillon? ? [tag.span('démarche en test', class: 'badge')] : []
parts << procedure.libelle
safe_join(parts, ' ')
end
Expand Down
4 changes: 4 additions & 0 deletions app/jobs/api_entreprise/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ class ApiEntreprise::Job < ApplicationJob

DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS = 5

# If by the time the job runs the Etablissement has been deleted
# (it can happen through EtablissementUpdateJob for instance), ignore the job
discard_on ActiveRecord::RecordNotFound

rescue_from(ApiEntreprise::API::ResourceNotFound) do |exception|
error(self, exception)
end
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ApplicationMailer < ActionMailer::Base
end

rescue_from Net::SMTPServerBusy do |error|
if error.message =~ /unexpected recipients/
if /unexpected recipients/.match?(error.message)
message.perform_deliveries = false
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/devise_user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DeviseUserMailer < Devise::Mailer
end

rescue_from Net::SMTPServerBusy do |error|
if error.message =~ /unexpected recipients/
if /unexpected recipients/.match?(error.message)
message.perform_deliveries = false
end
end
Expand Down
31 changes: 3 additions & 28 deletions app/models/champs/piece_justificative_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,9 @@
class Champs::PieceJustificativeChamp < Champ
MAX_SIZE = 200.megabytes

ACCEPTED_FORMATS = [
"text/plain",
"application/pdf",
"application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/vnd.ms-powerpoint",
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
"application/vnd.oasis.opendocument.text",
"application/vnd.oasis.opendocument.presentation",
"application/vnd.oasis.opendocument.spreadsheet",
"image/png",
"image/jpeg"
]

# TODO: once we're running on Rails 6, re-enable this validation.
# See https://github.com/betagouv/demarches-simplifiees.fr/issues/4926
#
# validates :piece_justificative_file,
# content_type: ACCEPTED_FORMATS,
# size: { less_than: MAX_SIZE }

before_save :update_skip_pj_validation
validates :piece_justificative_file,
size: { less_than: MAX_SIZE },
if: -> { !type_de_champ.skip_pj_validation }

def main_value_name
:piece_justificative_file
Expand All @@ -63,8 +42,4 @@ def for_api
piece_justificative_file.service_url
end
end

def update_skip_pj_validation
type_de_champ.update(skip_pj_validation: true)
end
end
8 changes: 4 additions & 4 deletions app/models/champs/repetition_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ def for_tag

return "" if rows.empty?

header = content_tag(:tr, rows[0].map { |c| content_tag(:th, c.libelle) }.reduce(&:+))
header = tag.tr(rows[0].map { |c| tag.th(c.libelle) }.reduce(&:+))
lines = rows.map do |champs|
content_tag(:tr, champs.map do |champ|
content_tag(:td, champ)
tag.tr(champs.map do |champ|
tag.td(champ)
end.reduce(&:+))
end.reduce(&:+)
content_tag(:table, header + lines)
tag.table(header + lines)
end

def rows_for_export
Expand Down
4 changes: 2 additions & 2 deletions app/models/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# updated_at :datetime not null
#
class Export < ApplicationRecord
MAX_DUREE_CONSERVATION_EXPORT = 15.minutes
MAX_DUREE_CONSERVATION_EXPORT = 1.hour

enum format: {
csv: 'csv',
Expand All @@ -24,7 +24,7 @@ class Export < ApplicationRecord

scope :stale, -> { where('updated_at < ?', (Time.zone.now - MAX_DUREE_CONSERVATION_EXPORT)) }

after_save_commit :compute_async
after_create_commit :compute_async

def compute_async
ExportJob.perform_later(self)
Expand Down
3 changes: 1 addition & 2 deletions app/models/procedure_presentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@ def valid_column?(table, column, extra_columns = {})
def valid_columns_for_table(table)
@column_whitelist ||= fields
.group_by { |field| field['table'] }
.map { |table, fields| [table, Set.new(fields.pluck('column'))] }
.to_h
.transform_values { |fields| Set.new(fields.pluck('column')) }

@column_whitelist[table] || []
end
Expand Down
Loading

0 comments on commit 0cafc4f

Please sign in to comment.