From db7c7f5edfb1464081d18854f98cd274f2ea7a7e Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Tue, 16 Dec 2025 17:13:42 +0530 Subject: [PATCH] feat: editor controller --- app/policies/captain/editor_policy.rb | 5 ++++ config/routes.rb | 3 +++ .../v1/accounts/captain/editor_controller.rb | 24 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 app/policies/captain/editor_policy.rb create mode 100644 enterprise/app/controllers/api/v1/accounts/captain/editor_controller.rb diff --git a/app/policies/captain/editor_policy.rb b/app/policies/captain/editor_policy.rb new file mode 100644 index 000000000..44e8b3c5f --- /dev/null +++ b/app/policies/captain/editor_policy.rb @@ -0,0 +1,5 @@ +class Captain::EditorPolicy < ApplicationPolicy + def process_event? + true + end +end diff --git a/config/routes.rb b/config/routes.rb index 0ac001612..b9eb8088a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -69,6 +69,9 @@ Rails.application.routes.draw do end resources :custom_tools resources :documents, only: [:index, :show, :create, :destroy] + resource :editor, only: [], controller: 'editor' do + post :process_event + end end resource :saml_settings, only: [:show, :create, :update, :destroy] resources :agent_bots, only: [:index, :create, :show, :update, :destroy] do diff --git a/enterprise/app/controllers/api/v1/accounts/captain/editor_controller.rb b/enterprise/app/controllers/api/v1/accounts/captain/editor_controller.rb new file mode 100644 index 000000000..58c2fb75f --- /dev/null +++ b/enterprise/app/controllers/api/v1/accounts/captain/editor_controller.rb @@ -0,0 +1,24 @@ +class Api::V1::Accounts::Captain::EditorController < Api::V1::Accounts::BaseController + before_action :check_authorization + + def process_event + result = Captain::EditorService.new( + account: Current.account, + event: params[:event] + ).perform + + if result.nil? + render json: { message: nil } + elsif result[:error] + render json: { error: result[:error] }, status: :unprocessable_entity + else + render json: { message: result[:message] } + end + end + + private + + def check_authorization + authorize(:'captain/editor') + end +end