## Description Hardens the Captain model override preferences API so account-level overrides follow the same feature-router contract used by runtime LLM calls. The API now permits model and feature keys from `llm.yml`, removes blank model overrides, rejects invalid saved model combinations, and returns each feature's effective model, provider, and source for UI clients. Fixes https://linear.app/chatwoot/issue/CW-7425/test-new-models ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality not to work as expected) - [ ] This change requires a documentation update ## How Has This Been Tested? Verified the account preferences API and account model validation behavior for valid overrides, invalid model values, unknown feature keys, blank override removal, and effective model/provider/source payload metadata. - `eval "$(rbenv init -)" && bundle exec rspec spec/controllers/api/v1/accounts/captain/preferences_controller_spec.rb spec/models/account_spec.rb spec/models/concerns/captain_featurable_spec.rb spec/lib/llm/feature_router_spec.rb` - `eval "$(rbenv init -)" && bundle exec rubocop app/controllers/api/v1/accounts/captain/preferences_controller.rb app/models/concerns/account_settings_schema.rb app/models/concerns/captain_featurable.rb spec/controllers/api/v1/accounts/captain/preferences_controller_spec.rb spec/models/account_spec.rb spec/models/concerns/captain_featurable_spec.rb spec/lib/llm/feature_router_spec.rb` - `git diff --check` ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
72 lines
2.6 KiB
Ruby
72 lines
2.6 KiB
Ruby
class SuperAdmin::AccountsController < SuperAdmin::ApplicationController
|
|
# Overwrite any of the RESTful controller actions to implement custom behavior
|
|
# For example, you may want to send an email after a foo is updated.
|
|
#
|
|
# def update
|
|
# super
|
|
# send_foo_updated_email(requested_resource)
|
|
# end
|
|
|
|
# Override this method to specify custom lookup behavior.
|
|
# This will be used to set the resource for the `show`, `edit`, and `update`
|
|
# actions.
|
|
#
|
|
# def find_resource(param)
|
|
# Foo.find_by!(slug: param)
|
|
# end
|
|
|
|
# The result of this lookup will be available as `requested_resource`
|
|
|
|
# Override this if you have certain roles that require a subset
|
|
# this will be used to set the records shown on the `index` action.
|
|
#
|
|
# def scoped_resource
|
|
# if current_user.super_admin?
|
|
# resource_class
|
|
# else
|
|
# resource_class.with_less_stuff
|
|
# end
|
|
# end
|
|
|
|
# Override `resource_params` if you want to transform the submitted
|
|
# data before it's persisted. For example, the following would turn all
|
|
# empty values into nil values. It uses other APIs such as `resource_class`
|
|
# and `dashboard`:
|
|
#
|
|
def resource_params
|
|
permitted_params = super
|
|
permitted_params[:limits] = permitted_params[:limits].to_h.compact if permitted_params.key?(:limits)
|
|
permitted_params[:captain_models] = permitted_params[:captain_models].to_h.compact_blank.presence if permitted_params.key?(:captain_models)
|
|
permitted_params[:selected_feature_flags] = params[:enabled_features].keys.map(&:to_sym) if params[:enabled_features].present?
|
|
permitted_params
|
|
end
|
|
|
|
# See https://administrate-prototype.herokuapp.com/customizing_controller_actions
|
|
# for more information
|
|
|
|
def seed
|
|
Internal::SeedAccountJob.perform_later(requested_resource)
|
|
# rubocop:disable Rails/I18nLocaleTexts
|
|
redirect_back(fallback_location: [namespace, requested_resource], notice: 'Account seeding triggered')
|
|
# rubocop:enable Rails/I18nLocaleTexts
|
|
end
|
|
|
|
def reset_cache
|
|
requested_resource.reset_cache_keys
|
|
# rubocop:disable Rails/I18nLocaleTexts
|
|
redirect_back(fallback_location: [namespace, requested_resource], notice: 'Cache keys cleared')
|
|
# rubocop:enable Rails/I18nLocaleTexts
|
|
end
|
|
|
|
def destroy
|
|
account = Account.find(params[:id])
|
|
|
|
DeleteObjectJob.perform_later(account) if account.present?
|
|
# rubocop:disable Rails/I18nLocaleTexts
|
|
redirect_back(fallback_location: [namespace, requested_resource], notice: 'Account deletion is in progress.')
|
|
# rubocop:enable Rails/I18nLocaleTexts
|
|
end
|
|
end
|
|
|
|
SuperAdmin::AccountsController.prepend_mod_with('SuperAdmin::AccountsController')
|