This pull request fixes the model annotation tooling due to previous incomplete migration from `annotate` to `annotaterb` gem (#12600). It also improves the handling of serialized values in the `InstallationConfig` model by ensuring a default value is set, simplifying the code, and removing a workaround for YAML deserialization. **Annotation tooling updates:** * Added `.annotaterb.yml` to configure the `annotate_rb` gem with project-specific options, centralizing annotation settings. * Replaced the custom `auto_annotate_models.rake` task with the standard rake task from `annotate_rb`, and added `lib/tasks/annotate_rb.rake` to load annotation tasks in development environments. [[1]](diffhunk://#diff-9450d2359e45f1db407b3871dde787a25d60bb721aed179a65ffd2692e95fb4bL1-L61) [[2]](diffhunk://#diff-578cdfc7ad56637e42472ea891ea286dff8803d9a1750afdbfeafec164d9b8b2R1-R8) **Model serialization improvements:** * Updated the `InstallationConfig` model to set a default value for the `serialized_value` attribute, ensuring it always has a hash with indifferent access and removing the need for a deserialization workaround in the `value` method. [[1]](diffhunk://#diff-b4bdde42c1ad0f584073818bd43dbd865b1b3b50d4701b131979f900d7c68297L22-R22) [[2]](diffhunk://#diff-b4bdde42c1ad0f584073818bd43dbd865b1b3b50d4701b131979f900d7c68297L36-L39) --------- Co-authored-by: Sojan Jose <sojan@pepalo.com>
62 lines
1.9 KiB
Ruby
62 lines
1.9 KiB
Ruby
# == Schema Information
|
|
#
|
|
# Table name: installation_configs
|
|
#
|
|
# id :bigint not null, primary key
|
|
# locked :boolean default(TRUE), not null
|
|
# name :string not null
|
|
# serialized_value :jsonb not null
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_installation_configs_on_name (name) UNIQUE
|
|
# index_installation_configs_on_name_and_created_at (name,created_at) UNIQUE
|
|
#
|
|
class InstallationConfig < ApplicationRecord
|
|
# https://stackoverflow.com/questions/72970170/upgrading-to-rails-6-1-6-1-causes-psychdisallowedclass-tried-to-load-unspecif
|
|
# https://discuss.rubyonrails.org/t/cve-2022-32224-possible-rce-escalation-bug-with-serialized-columns-in-active-record/81017
|
|
# FIX ME : fixes breakage of installation config. we need to migrate.
|
|
# Fix configuration in application.rb
|
|
serialize :serialized_value, coder: YAML, type: ActiveSupport::HashWithIndifferentAccess, default: {}.with_indifferent_access
|
|
|
|
before_validation :set_lock
|
|
validates :name, presence: true
|
|
validate :saml_sso_users_check, if: -> { name == 'ENABLE_SAML_SSO_LOGIN' }
|
|
|
|
# TODO: Get rid of default scope
|
|
# https://stackoverflow.com/a/1834250/939299
|
|
default_scope { order(created_at: :desc) }
|
|
scope :editable, -> { where(locked: false) }
|
|
|
|
after_commit :clear_cache
|
|
|
|
def value
|
|
serialized_value[:value]
|
|
end
|
|
|
|
def value=(value_to_assigned)
|
|
self.serialized_value = {
|
|
value: value_to_assigned
|
|
}.with_indifferent_access
|
|
end
|
|
|
|
private
|
|
|
|
def set_lock
|
|
self.locked = true if locked.nil?
|
|
end
|
|
|
|
def clear_cache
|
|
GlobalConfig.clear_cache
|
|
end
|
|
|
|
def saml_sso_users_check
|
|
return unless value == false || value == 'false'
|
|
return unless User.exists?(provider: 'saml')
|
|
|
|
errors.add(:base, 'Cannot disable SAML SSO login while users are using SAML authentication')
|
|
end
|
|
end
|