- {map ? footer : null}
);
}
diff --git a/app/models/administrateur.rb b/app/models/administrateur.rb
index ebd1e9470..7bdaa90fa 100644
--- a/app/models/administrateur.rb
+++ b/app/models/administrateur.rb
@@ -12,8 +12,7 @@ class Administrateur < ApplicationRecord
include ActiveRecord::SecureToken
has_and_belongs_to_many :instructeurs
- has_many :administrateurs_procedures
- has_many :procedures, through: :administrateurs_procedures
+ has_and_belongs_to_many :procedures
has_many :services
has_one :user, dependent: :nullify
diff --git a/app/models/champs/phone_champ.rb b/app/models/champs/phone_champ.rb
index baa032d5b..ac2c51449 100644
--- a/app/models/champs/phone_champ.rb
+++ b/app/models/champs/phone_champ.rb
@@ -20,14 +20,43 @@
# type_de_champ_id :integer
#
class Champs::PhoneChamp < Champs::TextChamp
+ # We want to allow:
+ # * international (e164) phone numbers
+ # * “french format” (ten digits with a leading 0)
+ # * DROM numbers
+ #
+ # However, we need to special-case some ten-digit numbers,
+ # because the ARCEP assigns some blocks of "O6 XX XX XX XX" numbers to DROM operators.
+ # Guadeloupe | GP | +590 | 0690XXXXXX, 0691XXXXXX
+ # Guyane | GF | +594 | 0694XXXXXX
+ # Martinique | MQ | +596 | 0696XXXXXX, 0697XXXXXX
+ # Réunion | RE | +262 | 0692XXXXXX, 0693XXXXXX
+ # Mayotte | YT | +262 | 0692XXXXXX, 0693XXXXXX
+ # Nouvelle-Calédonie | NC | +687 |
+ # Polynésie française | PF | +689 | 40XXXXXX, 45XXXXXX, 87XXXXXX, 88XXXXXX, 89XXXXXX
+ #
+ # Cf: Plan national de numérotation téléphonique,
+ # https://www.arcep.fr/uploads/tx_gsavis/05-1085.pdf “Numéros mobiles à 10 chiffres”, page 6
+ #
+ # See issue #6996.
+ DEFAULT_COUNTRY_CODES = [:FR, :GP, :GF, :MQ, :RE, :YT, :NC, :PF].freeze
+
validates :value,
phone: {
possible: true,
allow_blank: true,
message: I18n.t(:not_a_phone, scope: 'activerecord.errors.messages')
- }, unless: -> { Phonelib.valid_for_country?(value, :pf) }
+ }, unless: -> { Phonelib.valid_for_countries?(value, DEFAULT_COUNTRY_CODES) }
def to_s
- value.present? ? Phonelib.parse(value).full_national : ''
+ return '' if value.blank?
+
+ if Phonelib.valid_for_countries?(value, DEFAULT_COUNTRY_CODES)
+ Phonelib.parse_for_countries(value, DEFAULT_COUNTRY_CODES).full_national
+ else
+ # When he phone number is possible for the default countries, but not strictly valid,
+ # `full_national` could mess up the formatting. In this case just return the original.
+ value
+ end
end
end
diff --git a/db/migrate/20220301160753_add_administrateur_foreign_key_to_administrateurs_procedure.rb b/db/migrate/20220301160753_add_administrateur_foreign_key_to_administrateurs_procedure.rb
new file mode 100644
index 000000000..d8d0bbb0a
--- /dev/null
+++ b/db/migrate/20220301160753_add_administrateur_foreign_key_to_administrateurs_procedure.rb
@@ -0,0 +1,15 @@
+class AddAdministrateurForeignKeyToAdministrateursProcedure < ActiveRecord::Migration[6.1]
+ def up
+ # Sanity check
+ say_with_time 'Removing AdministrateursProcedures where the associated Administrateur no longer exists ' do
+ deleted_administrateur_ids = AdministrateursProcedure.where.missing(:administrateur).pluck(:administrateur_id)
+ AdministrateursProcedure.where(administrateur_id: deleted_administrateur_ids).delete_all
+ end
+
+ add_foreign_key :administrateurs_procedures, :administrateurs
+ end
+
+ def down
+ remove_foreign_key :administrateurs_procedures, :administrateurs
+ end
+end
diff --git a/doc/DEPLOYMENT.md b/doc/DEPLOYMENT.md
new file mode 100644
index 000000000..1b975066d
--- /dev/null
+++ b/doc/DEPLOYMENT.md
@@ -0,0 +1,61 @@
+# Deployment documentation
+
+demarches-simplifiees.fr is a standard Rails app, and can be deployed using standard methods (PaaS, Docker, bare-metal, etc.) Deployments are engineered not to require any downtime.
+
+## 1. Deploying demarches-simplifiees.fr
+
+Usually, a deployment goes like this (in pseudo-code):
+
+```
+# Run database schema migrations (e.g. `bin/rails db:migrate`)
+# For each server:
+ # Stop the server
+ # Get the new code (e.g. `git clone git@github.com:betagouv/demarches-simplifiees.fr.git`)
+ # Install new dependencies (e.g. `bundle install && yarn install`)
+ # Restart the app server
+# Run data migrations (e.g. `rake after_party:run`)
+```
+
+On the main instance, this deployment flow is implemented using [`mina`](https://github.com/mina-deploy/mina), which automatically sshs to the application servers, run the appropriate commands (see `lib/tasks/deploy.rake` and `config/deploy.rb`), and restarts the puma webserver in a way that ensures zero-downtime deployments.
+A deploy on multiple application servers is typically done using:
+```shell
+DOMAINS="web1 web2" BRANCH="main" bin/rake deploy
+```
+
+But of course other methods can be used.
+
+## 2. Upgrading demarches-simplifiees.fr
+
+### 2.1 Standard upgrade path
+
+Theoretically, only deploying each version sequentially is fully supported. This means that to deploy the version N+3, the upgrade plan should be to deploy the version N+1, N+2 and then only N+3, in that order.
+
+Release notes for each version are available on [GitHub's Releases page](https://github.com/betagouv/demarches-simplifiees.fr/releases). Since 2022, when a release includes a database schema or data migration is present, this is mentionned in the release notes.
+
+### 2.2 Upgrading several releases at once
+
+Upgrading from several releases at once (like migrating directly from a version N to a version N+3) is theoretically unsupported. This is because database schema migrations and data migrations have to run in the exact order they were created, along the application code as it was when the migration was written.
+That said, it is possible to batch the upgrade of several releases at once, _provided that the data migrations run in the correct order_.
+
+The rule of thumb is that _an intermediary upgrade should be done before every database schema migration that follows a data migration_.
+
+_NB: There are some plans to improve this, and contributions are welcome. See https://github.com/betagouv/demarches-simplifiees.fr/issues/6970_
+
+# Historical notes
+
+- During 2021, some older data migration tasks were deleted from the repository. This has to be checked manually when upgrading from an older version.
+ ```
+ lib/tasks/deployment/20200326133630_cleanup_deleted_dossiers.rake
+ lib/tasks/deployment/20200401123317_process_expired_dossiers_en_construction.rake
+ lib/tasks/deployment/20200527124112_fix_champ_etablissement.rake
+ lib/tasks/deployment/20200528124044_fix_dossier_etablissement.rake
+ lib/tasks/deployment/20200618121241_drop_down_list_options_to_json.rake
+ lib/tasks/deployment/20200625113026_migrate_revisions.rake
+ lib/tasks/deployment/20200630154829_add_traitements_from_dossiers.rake
+ lib/tasks/deployment/20200708101123_add_default_skip_validation_to_piece_justificative.rake
+ lib/tasks/deployment/20200728150458_fix_cloned_revisions.rake
+ lib/tasks/deployment/20200813111957_fix_geo_areas_geometry.rake
+ lib/tasks/deployment/20201001161931_migrate_filters_to_use_stable_id.rake
+ lib/tasks/deployment/20201006123842_setup_first_stats.rake
+ lib/tasks/deployment/20201218163035_fix_types_de_champ_revisions.rake
+ ```
diff --git a/doc/adr-csrf-forgery.md b/doc/architecture-decision-records/adr-csrf-forgery.md
similarity index 100%
rename from doc/adr-csrf-forgery.md
rename to doc/architecture-decision-records/adr-csrf-forgery.md
diff --git a/lib/core_ext/phonelib.rb b/lib/core_ext/phonelib.rb
new file mode 100644
index 000000000..1345a0c75
--- /dev/null
+++ b/lib/core_ext/phonelib.rb
@@ -0,0 +1,14 @@
+# Class extensions to the Phonelib module, which allow parsing using several countries at once.
+module Phonelib
+ # Variation of `.valid_for_country`, that can check several countries at once.
+ def self.valid_for_countries?(value, countries)
+ countries.any? { |country| valid_for_country?(value, country) }
+ end
+
+ # Variation of `Phonelib.parse`, which parses the given string using the first country
+ # for which the phone number is valid.
+ def self.parse_for_countries(value, passed_countries = [])
+ valid_country = passed_countries.find { |country| valid_for_country?(value, country) }
+ parse(value, valid_country)
+ end
+end
diff --git a/package.json b/package.json
index 293825ee3..85524e4e0 100644
--- a/package.json
+++ b/package.json
@@ -47,6 +47,7 @@
"@2fd/graphdoc": "^2.4.0",
"@types/debounce": "^1.2.1",
"@types/geojson": "^7946.0.8",
+ "@types/is-hotkey": "^0.1.7",
"@types/mapbox__mapbox-gl-draw": "^1.2.3",
"@types/rails__ujs": "^6.0.1",
"@types/react": "^17.0.38",
diff --git a/spec/models/administrateur_spec.rb b/spec/models/administrateur_spec.rb
index 55e6c4d32..ce21fb67a 100644
--- a/spec/models/administrateur_spec.rb
+++ b/spec/models/administrateur_spec.rb
@@ -3,7 +3,7 @@ describe Administrateur, type: :model do
describe 'associations' do
it { is_expected.to have_and_belong_to_many(:instructeurs) }
- it { is_expected.to have_many(:procedures) }
+ it { is_expected.to have_and_belong_to_many(:procedures) }
end
describe "#renew_api_token" do
diff --git a/spec/models/champs/phone_champ_spec.rb b/spec/models/champs/phone_champ_spec.rb
index 4d1f12f6e..275986c33 100644
--- a/spec/models/champs/phone_champ_spec.rb
+++ b/spec/models/champs/phone_champ_spec.rb
@@ -22,6 +22,10 @@ describe Champs::PhoneChamp do
expect(champ_with_value("+1(0) - 123456789")).to be_valid
expect(champ_with_value("+49 2109 87654321")).to be_valid
expect(champ_with_value("012345678")).to be_valid
+ # DROM numbers should be valid
+ expect(champ_with_value("06 96 04 78 07")).to be_valid
+ expect(champ_with_value("05 94 22 31 31")).to be_valid
+ expect(champ_with_value("+594 5 94 22 31 31")).to be_valid
# polynesian numbers should not return errors in any way
## landline numbers start with 40 or 45
expect(champ_with_value("45187272")).to be_valid
@@ -36,9 +40,27 @@ describe Champs::PhoneChamp do
expect(champ_with_value("88473500")).to be_valid
expect(champ_with_value("89473500")).to be_valid
end
+ end
- def champ_with_value(number)
- phone_champ.tap { |c| c.value = number }
+ describe '#to_s' do
+ context 'for valid phone numbers' do
+ it 'returns the national part of the number, formatted nicely' do
+ expect(champ_with_value("0115789055").to_s).to eq("01 15 78 90 55")
+ expect(champ_with_value("+33115789055").to_s).to eq("01 15 78 90 55")
+ # DROM phone numbers are formatted differently – but still formatted
+ expect(champ_with_value("0696047807").to_s).to eq("0696 04 78 07")
+ expect(champ_with_value("45187272").to_s).to eq("45187272")
+ end
+ end
+
+ context 'for possible (but not valid) phone numbers' do
+ it 'returns the original' do
+ expect(champ_with_value("1234").to_s).to eq("1234")
+ end
end
end
+
+ def champ_with_value(number)
+ phone_champ.tap { |c| c.value = number }
+ end
end
diff --git a/yarn.lock b/yarn.lock
index cf3335137..92b14afda 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2383,6 +2383,11 @@
dependencies:
"@types/node" "*"
+"@types/is-hotkey@^0.1.7":
+ version "0.1.7"
+ resolved "https://registry.yarnpkg.com/@types/is-hotkey/-/is-hotkey-0.1.7.tgz#30ec6d4234895230b576728ef77e70a52962f3b3"
+ integrity sha512-yB5C7zcOM7idwYZZ1wKQ3pTfjA9BbvFqRWvKB46GFddxnJtHwi/b9y84ykQtxQPg5qhdpg4Q/kWU3EGoCTmLzQ==
+
"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz#4ba8ddb720221f432e443bd5f9117fd22cfd4762"