diff --git a/db/migrate/20250825070005_create_account_saml_settings.rb b/db/migrate/20250825070005_create_account_saml_settings.rb index 6c0575fec..63aa0d0e4 100644 --- a/db/migrate/20250825070005_create_account_saml_settings.rb +++ b/db/migrate/20250825070005_create_account_saml_settings.rb @@ -9,6 +9,7 @@ class CreateAccountSamlSettings < ActiveRecord::Migration[7.1] t.string :sp_entity_id t.boolean :enforced_sso, default: false, null: false t.json :attribute_mappings, default: {} + t.json :role_mappings, default: {} t.timestamps end diff --git a/db/migrate/20250825070824_create_saml_role_mappings.rb b/db/migrate/20250825070824_create_saml_role_mappings.rb deleted file mode 100644 index f0ec78738..000000000 --- a/db/migrate/20250825070824_create_saml_role_mappings.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreateSamlRoleMappings < ActiveRecord::Migration[7.1] - def change - create_table :saml_role_mappings do |t| - t.references :account_saml_settings, null: false - t.string :saml_group_name, null: false - t.integer :role, default: 0, null: false - t.references :custom_role, null: true - - t.timestamps - end - end -end diff --git a/db/schema.rb b/db/schema.rb index 39a2de610..811032405 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[7.1].define(version: 2025_08_25_070824) do +ActiveRecord::Schema[7.1].define(version: 2025_08_25_070005) do # These extensions should be enabled to support this database enable_extension "pg_stat_statements" enable_extension "pg_trgm" @@ -1070,17 +1070,6 @@ ActiveRecord::Schema[7.1].define(version: 2025_08_25_070824) do t.index ["user_id"], name: "index_reporting_events_on_user_id" end - create_table "saml_role_mappings", force: :cascade do |t| - t.bigint "account_saml_settings_id", null: false - t.string "saml_group_name", null: false - t.integer "role", default: 0, null: false - t.bigint "custom_role_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["account_saml_settings_id"], name: "index_saml_role_mappings_on_account_saml_settings_id" - t.index ["custom_role_id"], name: "index_saml_role_mappings_on_custom_role_id" - end - create_table "sla_events", force: :cascade do |t| t.bigint "applied_sla_id", null: false t.bigint "conversation_id", null: false diff --git a/enterprise/app/models/account_saml_settings.rb b/enterprise/app/models/account_saml_settings.rb index f674cd814..9fef9f5db 100644 --- a/enterprise/app/models/account_saml_settings.rb +++ b/enterprise/app/models/account_saml_settings.rb @@ -20,7 +20,6 @@ # class AccountSamlSettings < ApplicationRecord belongs_to :account - has_many :saml_role_mappings, dependent: :destroy validates :account_id, presence: true validates :sso_url, presence: true, if: :enabled? diff --git a/enterprise/app/models/saml_role_mapping.rb b/enterprise/app/models/saml_role_mapping.rb deleted file mode 100644 index 4c3460dc2..000000000 --- a/enterprise/app/models/saml_role_mapping.rb +++ /dev/null @@ -1,48 +0,0 @@ -# == Schema Information -# -# Table name: saml_role_mappings -# -# id :bigint not null, primary key -# role :integer default("agent"), not null -# saml_group_name :string not null -# created_at :datetime not null -# updated_at :datetime not null -# account_saml_settings_id :bigint not null -# custom_role_id :bigint -# -# Indexes -# -# index_saml_role_mappings_on_account_saml_settings_id (account_saml_settings_id) -# index_saml_role_mappings_on_custom_role_id (custom_role_id) -# -class SamlRoleMapping < ApplicationRecord - belongs_to :account_saml_settings - belongs_to :custom_role, optional: true - - validates :saml_group_name, presence: true - validates :role, inclusion: { in: [0, 1] }, allow_nil: true - validate :role_or_custom_role_present - validate :not_both_role_and_custom_role - - enum role: { agent: 0, administrator: 1 } - - scope :for_group, ->(group_name) { where(saml_group_name: group_name) } - - def target_role - custom_role_id? ? :custom : role - end - - private - - def role_or_custom_role_present - return if role.present? || custom_role_id.present? - - errors.add(:base, 'Either role or custom_role must be present') - end - - def not_both_role_and_custom_role - return unless role.present? && custom_role_id.present? - - errors.add(:base, 'Cannot have both role and custom_role set') - end -end