feat: update models
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
+1
-12
@@ -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
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user