diff --git a/app/models/administrateur.rb b/app/models/administrateur.rb index cc8ad21b2..399190165 100644 --- a/app/models/administrateur.rb +++ b/app/models/administrateur.rb @@ -12,6 +12,8 @@ class Administrateur < ApplicationRecord has_many :services has_many :dossiers, -> { state_not_brouillon }, through: :procedures + has_one :user + before_validation -> { sanitize_email(:email) } scope :inactive, -> { where(active: false) } diff --git a/app/models/user.rb b/app/models/user.rb index 7332dee3f..ff6673191 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -18,6 +18,7 @@ class User < ApplicationRecord has_many :feedbacks, dependent: :destroy has_one :france_connect_information, dependent: :destroy belongs_to :instructeur + belongs_to :administrateur accepts_nested_attributes_for :france_connect_information diff --git a/db/migrate/20190809073736_link_user_and_administrateur.rb b/db/migrate/20190809073736_link_user_and_administrateur.rb new file mode 100644 index 000000000..34ca446dd --- /dev/null +++ b/db/migrate/20190809073736_link_user_and_administrateur.rb @@ -0,0 +1,6 @@ +class LinkUserAndAdministrateur < ActiveRecord::Migration[5.2] + def change + add_reference :users, :administrateur, index: true + add_foreign_key :users, :administrateurs + end +end diff --git a/db/schema.rb b/db/schema.rb index 4b29d1dae..fdbf8f457 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: 2019_08_08_144607) do +ActiveRecord::Schema.define(version: 2019_08_09_073736) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -597,6 +597,8 @@ ActiveRecord::Schema.define(version: 2019_08_08_144607) do t.datetime "locked_at" t.text "unconfirmed_email" t.bigint "instructeur_id" + t.bigint "administrateur_id" + t.index ["administrateur_id"], name: "index_users_on_administrateur_id" t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["email"], name: "index_users_on_email", unique: true t.index ["instructeur_id"], name: "index_users_on_instructeur_id" @@ -644,6 +646,7 @@ ActiveRecord::Schema.define(version: 2019_08_08_144607) do add_foreign_key "services", "administrateurs" add_foreign_key "trusted_device_tokens", "instructeurs" add_foreign_key "types_de_champ", "types_de_champ", column: "parent_id" + add_foreign_key "users", "administrateurs" add_foreign_key "users", "instructeurs" add_foreign_key "without_continuation_mails", "procedures" end