Token-authenticated requests to Agent Bots, Labels, and affected Captain endpoints return normal responses again. The regression was caused by duplicate `current_account` callbacks in subclasses moving account resolution behind the API entitlement check, leaving `Current.account` unset. ## Closes - https://linear.app/chatwoot/issue/CW-7641/5xx-errors-in-agent-bot-apis ## How to reproduce 1. Send `GET /api/v1/accounts/:account_id/agent_bots` with a valid administrator API access token. 2. Observe a `500` from `validate_token_api_access` because `Current.account` is `nil`. 3. With this change, account resolution runs in the base-controller order and the request succeeds. ## What changed - Removed redundant `current_account` callbacks from account-scoped controllers that already inherit the callback from `Api::V1::Accounts::BaseController`. - Kept the standalone direct-upload controller callback unchanged. - Added regression coverage for administrator API-token access to Agent Bots.
47 lines
1.0 KiB
Ruby
47 lines
1.0 KiB
Ruby
class Api::V1::Accounts::Captain::ScenariosController < Api::V1::Accounts::BaseController
|
|
before_action -> { check_authorization(Captain::Scenario) }
|
|
before_action :set_assistant
|
|
before_action :set_scenario, only: [:show, :update, :destroy]
|
|
|
|
def index
|
|
@scenarios = assistant_scenarios.enabled
|
|
end
|
|
|
|
def show; end
|
|
|
|
def create
|
|
@scenario = assistant_scenarios.create!(scenario_params.merge(account: Current.account))
|
|
end
|
|
|
|
def update
|
|
@scenario.update!(scenario_params)
|
|
end
|
|
|
|
def destroy
|
|
@scenario.destroy
|
|
head :no_content
|
|
end
|
|
|
|
private
|
|
|
|
def set_assistant
|
|
@assistant = account_assistants.find(params[:assistant_id])
|
|
end
|
|
|
|
def account_assistants
|
|
@account_assistants ||= Current.account.captain_assistants
|
|
end
|
|
|
|
def set_scenario
|
|
@scenario = assistant_scenarios.find(params[:id])
|
|
end
|
|
|
|
def assistant_scenarios
|
|
@assistant.scenarios
|
|
end
|
|
|
|
def scenario_params
|
|
params.require(:scenario).permit(:title, :description, :instruction, :enabled, tools: [])
|
|
end
|
|
end
|