refactor: move scenarios controller

Match it with inboxes implemetation
This commit is contained in:
Shivam Mishra
2025-07-09 18:41:41 +05:30
parent 14417ef14f
commit 62a7cfa188
8 changed files with 31 additions and 5 deletions
@@ -1,4 +1,5 @@
class Api::V1::Accounts::Captain::Assistants::ScenariosController < Api::V1::Accounts::BaseController
class Api::V1::Accounts::Captain::ScenariosController < Api::V1::Accounts::BaseController
before_action :current_account
before_action -> { check_authorization(Captain::Scenario) }
before_action :set_assistant
before_action :set_scenario, only: [:show, :update, :destroy]
@@ -10,7 +11,7 @@ class Api::V1::Accounts::Captain::Assistants::ScenariosController < Api::V1::Acc
def show; end
def create
@scenario = assistant_scenarios.create!(scenario_params)
@scenario = assistant_scenarios.create!(scenario_params.merge(account: Current.account))
end
def update
@@ -25,7 +26,11 @@ class Api::V1::Accounts::Captain::Assistants::ScenariosController < Api::V1::Acc
private
def set_assistant
@assistant = current_account.captain_assistants.find(params[:assistant_id])
@assistant = account_assistants.find(params[:assistant_id])
end
def account_assistants
@account_assistants ||= Current.account.captain_assistants
end
def set_scenario
@@ -0,0 +1,21 @@
class Captain::ScenarioPolicy < ApplicationPolicy
def index?
true
end
def show?
true
end
def create?
@account_user.administrator?
end
def update?
@account_user.administrator?
end
def destroy?
@account_user.administrator?
end
end
@@ -13,4 +13,4 @@ if scenario.assistant.present?
json.id scenario.assistant.id
json.name scenario.assistant.name
end
end
end
@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe 'Api::V1::Accounts::Captain::Assistants::Scenarios', type: :request do
RSpec.describe 'Api::V1::Accounts::Captain::Scenarios', type: :request do
let(:account) { create(:account) }
let(:admin) { create(:user, account: account, role: :administrator) }
let(:agent) { create(:user, account: account, role: :agent) }