diff --git a/app/models/university.rb b/app/models/university.rb index 4c1b31dc8af7e5fecc93d8e2057012a6f0ed2709..67325b68306114e5fb0e46d90d228a946f8d0ee7 100644 --- a/app/models/university.rb +++ b/app/models/university.rb @@ -2,22 +2,28 @@ # # Table name: universities # -# id :uuid not null, primary key -# address :string -# city :string -# country :string -# identifier :string -# invoice_amount :string -# invoice_date :date -# invoice_date_yday :integer -# mail_from_address :string -# mail_from_name :string -# name :string -# private :boolean -# sms_sender_name :string -# zipcode :string -# created_at :datetime not null -# updated_at :datetime not null +# id :uuid not null, primary key +# address :string +# city :string +# country :string +# has_sso :boolean default(FALSE) +# identifier :string +# invoice_amount :string +# invoice_date :date +# invoice_date_yday :integer +# mail_from_address :string +# mail_from_name :string +# name :string +# private :boolean +# sms_sender_name :string +# sso_cert :text +# sso_mapping :jsonb +# sso_name_identifier_format :string +# sso_provider :integer default("saml") +# sso_target_url :string +# zipcode :string +# created_at :datetime not null +# updated_at :datetime not null # class University < ApplicationRecord include WithPeopleAndOrganizations @@ -26,6 +32,7 @@ class University < ApplicationRecord include WithIdentifier include WithInvoice include WithResearch + include WithSso include WithUsers has_one_attached_deletable :logo diff --git a/app/models/university/with_sso.rb b/app/models/university/with_sso.rb new file mode 100644 index 0000000000000000000000000000000000000000..34f6afb8bccf895f1ab689f5b99552227bb37a5c --- /dev/null +++ b/app/models/university/with_sso.rb @@ -0,0 +1,18 @@ +module University::WithSso + extend ActiveSupport::Concern + + included do + enum sso_provider: { saml: 0, oauth2: 10 }, _prefix: :with_sso_via + end + + # Setter to serialize data as JSON + def sso_mapping=(value) + if value.empty? + value = nil + else + value = JSON.parse value if value.is_a? String + end + super(value) + end + +end diff --git a/db/migrate/20220428151735_add_sso_to_universities.rb b/db/migrate/20220428151735_add_sso_to_universities.rb new file mode 100644 index 0000000000000000000000000000000000000000..f94567dec6b3d27a0db995d404a556a96c89a726 --- /dev/null +++ b/db/migrate/20220428151735_add_sso_to_universities.rb @@ -0,0 +1,10 @@ +class AddSsoToUniversities < ActiveRecord::Migration[6.1] + def change + add_column :universities, :has_sso, :boolean, default: false + add_column :universities, :sso_provider, :integer, default: 0 + add_column :universities, :sso_target_url, :string + add_column :universities, :sso_cert, :text + add_column :universities, :sso_name_identifier_format, :string + add_column :universities, :sso_mapping, :jsonb + end +end diff --git a/db/schema.rb b/db/schema.rb index c2f1cfe2049432ecccfc93aa647a4922f421f974..651bf52d95e45dac88f192bdb7e51890ab5cdef4 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: 2022_04_27_094234) do +ActiveRecord::Schema.define(version: 2022_04_28_151735) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -629,6 +629,12 @@ ActiveRecord::Schema.define(version: 2022_04_27_094234) do t.date "invoice_date" t.integer "invoice_date_yday" t.string "invoice_amount" + t.boolean "has_sso", default: false + t.integer "sso_provider", default: 0 + t.string "sso_target_url" + t.text "sso_cert" + t.string "sso_name_identifier_format" + t.jsonb "sso_mapping" end create_table "university_organization_imports", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| diff --git a/test/fixtures/universities.yml b/test/fixtures/universities.yml index 0ce6f928742f8a5b7dd79ffe5a22572c0390e63d..112c47a9b4409afd2adaa9d16373f6702af8e1eb 100644 --- a/test/fixtures/universities.yml +++ b/test/fixtures/universities.yml @@ -2,22 +2,28 @@ # # Table name: universities # -# id :uuid not null, primary key -# address :string -# city :string -# country :string -# identifier :string -# invoice_amount :string -# invoice_date :date -# invoice_date_yday :integer -# mail_from_address :string -# mail_from_name :string -# name :string -# private :boolean -# sms_sender_name :string -# zipcode :string -# created_at :datetime not null -# updated_at :datetime not null +# id :uuid not null, primary key +# address :string +# city :string +# country :string +# has_sso :boolean default(FALSE) +# identifier :string +# invoice_amount :string +# invoice_date :date +# invoice_date_yday :integer +# mail_from_address :string +# mail_from_name :string +# name :string +# private :boolean +# sms_sender_name :string +# sso_cert :text +# sso_mapping :jsonb +# sso_name_identifier_format :string +# sso_provider :integer default("saml") +# sso_target_url :string +# zipcode :string +# created_at :datetime not null +# updated_at :datetime not null # default_university: name: Université de test