diff --git a/app/decorators/type_de_champ_private_decorator.rb b/app/decorators/type_de_champ_private_decorator.rb deleted file mode 100644 index ea9f715a2..000000000 --- a/app/decorators/type_de_champ_private_decorator.rb +++ /dev/null @@ -1,2 +0,0 @@ -class TypeDeChampPrivateDecorator < TypeDeChampDecorator -end diff --git a/app/models/champ.rb b/app/models/champ.rb index ac45708a0..1b3f6cf4e 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -13,8 +13,8 @@ class Champ < ApplicationRecord before_save :multiple_select_to_string, if: Proc.new { type_champ == 'multiple_drop_down_list' } scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) } - scope :public_only, -> { where(type: 'ChampPublic').or(where(private: false)) } - scope :private_only, -> { where(type: 'ChampPrivate').or(where(private: true)) } + scope :public_only, -> { where(private: false) } + scope :private_only, -> { where(private: true) } PIECE_JUSTIFICATIVE_FILE_MAX_SIZE = 200.megabytes @@ -37,10 +37,6 @@ class Champ < ApplicationRecord !private? end - def private? - super || type == 'ChampPrivate' - end - def same_hour? num same_date? num, '%H' end diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 1facb4220..ac4eaffe4 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -27,8 +27,8 @@ class TypeDeChamp < ApplicationRecord belongs_to :procedure - scope :public_only, -> { where(type: 'TypeDeChampPublic').or(where(private: false)) } - scope :private_only, -> { where(type: 'TypeDeChampPrivate').or(where(private: true)) } + scope :public_only, -> { where(private: false) } + scope :private_only, -> { where(private: true) } has_many :champ, inverse_of: :type_de_champ, dependent: :destroy do def build(params = {}) @@ -71,10 +71,6 @@ class TypeDeChamp < ApplicationRecord type_champ.in?(['header_section', 'explication']) end - def private? - super || type == 'TypeDeChampPrivate' - end - def public? !private? end diff --git a/db/migrate/20180308110811_add_defaults_to_champs.rb b/db/migrate/20180308110811_add_defaults_to_champs.rb new file mode 100644 index 000000000..f623956fb --- /dev/null +++ b/db/migrate/20180308110811_add_defaults_to_champs.rb @@ -0,0 +1,6 @@ +class AddDefaultsToChamps < ActiveRecord::Migration[5.2] + def change + change_column :champs, :private, :boolean, default: false, null: false + change_column :types_de_champ, :private, :boolean, default: false, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 3054b8931..442360b51 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_03_07_101545) do +ActiveRecord::Schema.define(version: 2018_03_08_110811) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -160,7 +160,7 @@ ActiveRecord::Schema.define(version: 2018_03_07_101545) do t.string "type" t.datetime "created_at" t.datetime "updated_at" - t.boolean "private" + t.boolean "private", default: false, null: false t.integer "etablissement_id" t.index ["dossier_id"], name: "index_champs_on_dossier_id" t.index ["private"], name: "index_champs_on_private" @@ -468,7 +468,7 @@ ActiveRecord::Schema.define(version: 2018_03_07_101545) do t.text "description" t.boolean "mandatory", default: false t.string "type" - t.boolean "private" + t.boolean "private", default: false, null: false t.index ["private"], name: "index_types_de_champ_on_private" end