Merge pull request #5539 from betagouv/dev

2020-09-04-01
This commit is contained in:
Keirua 2020-09-04 11:39:25 +02:00 committed by GitHub
commit e9c18d3cad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 26 deletions

View file

@ -44,7 +44,6 @@ module NewAdministrateur
{
type_de_champ: type_de_champ.as_json(
except: [
:id,
:created_at,
:options,
:order_place,
@ -64,7 +63,7 @@ module NewAdministrateur
:piece_justificative_template_url,
:quartiers_prioritaires
]
).merge(id: TypeDeChamp.format_stable_id(type_de_champ.stable_id))
)
}
end

View file

@ -48,7 +48,13 @@ class Champ < ApplicationRecord
scope :private_only, -> { where(private: true) }
scope :ordered, -> { includes(:type_de_champ).order(:row, 'types_de_champ.order_place') }
scope :public_ordered, -> { public_only.joins(dossier: { revision: :revision_types_de_champ }).where('procedure_revision_types_de_champ.type_de_champ_id = champs.type_de_champ_id').order(:position) }
scope :private_ordered, -> { private_only.joins(dossier: { revision: :revision_types_de_champ_private }).where('procedure_revision_types_de_champ.type_de_champ_id = champs.type_de_champ_id').order(:position) }
# we need to do private champs order as manual join to avoid conflicting join names
scope :private_ordered, -> do
private_only.joins('INNER JOIN types_de_champ types_de_champ_private
ON types_de_champ_private.id = champs.type_de_champ_id AND types_de_champ_private.private = true
INNER JOIN procedure_revision_types_de_champ procedure_revision_types_de_champ_private
ON procedure_revision_types_de_champ_private.type_de_champ_id = types_de_champ_private.id').order(:position)
end
scope :root, -> { where(parent_id: nil) }

View file

@ -13,7 +13,6 @@
# created_at :datetime
# updated_at :datetime
# parent_id :bigint
# procedure_id :integer
# revision_id :bigint
# stable_id :bigint
#
@ -304,7 +303,7 @@ class TypeDeChamp < ApplicationRecord
def read_attribute_for_serialization(name)
if name == 'id'
self.class.format_stable_id(stable_id)
stable_id
else
super
end
@ -317,15 +316,11 @@ class TypeDeChamp < ApplicationRecord
# This is only needed for a clean migration without downtime. We want to ensure
# that if editor send a simple id because it was loaded before deployment
# we would still do the right thing.
def self.format_stable_id(stable_id)
"stable:#{stable_id}"
end
def self.to_stable_id(id_or_stable_id)
if id_or_stable_id.to_s =~ /^stable:/
id_or_stable_id.to_s.gsub(/^stable:/, '')
else
find(id_or_stable_id).stable_id
id_or_stable_id
end
end

View file

@ -0,0 +1,5 @@
class RemoveTypeDeChampProcedureId < ActiveRecord::Migration[6.0]
def change
remove_column :types_de_champ, :procedure_id
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_08_19_153016) do
ActiveRecord::Schema.define(version: 2020_09_02_103047) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -611,7 +611,6 @@ ActiveRecord::Schema.define(version: 2020_08_19_153016) do
t.string "libelle"
t.string "type_champ"
t.integer "order_place"
t.integer "procedure_id"
t.text "description"
t.boolean "mandatory", default: false
t.boolean "private", default: false, null: false
@ -623,7 +622,6 @@ ActiveRecord::Schema.define(version: 2020_08_19_153016) do
t.bigint "revision_id"
t.index ["parent_id"], name: "index_types_de_champ_on_parent_id"
t.index ["private"], name: "index_types_de_champ_on_private"
t.index ["procedure_id"], name: "index_types_de_champ_on_procedure_id"
t.index ["revision_id"], name: "index_types_de_champ_on_revision_id"
t.index ["stable_id"], name: "index_types_de_champ_on_stable_id"
end