fix(captain): harden FAQ suggestion review flow
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
class Api::V1::Accounts::Captain::FaqSuggestionsController < Api::V1::Accounts::BaseController
|
||||
before_action :current_account
|
||||
before_action -> { check_authorization(Captain::Assistant) }
|
||||
before_action :check_admin_authorization?
|
||||
before_action :set_suggestions
|
||||
before_action :set_suggestion, except: [:index]
|
||||
|
||||
@@ -23,9 +23,11 @@ class Api::V1::Accounts::Captain::FaqSuggestionsController < Api::V1::Accounts::
|
||||
end
|
||||
|
||||
def update
|
||||
raise ActiveRecord::RecordNotFound unless @suggestion.open?
|
||||
@suggestion.with_lock do
|
||||
raise ActiveRecord::RecordNotFound unless @suggestion.open?
|
||||
|
||||
@suggestion.update!(suggestion_params)
|
||||
@suggestion.update!(suggestion_params)
|
||||
end
|
||||
end
|
||||
|
||||
def approve
|
||||
@@ -34,9 +36,11 @@ class Api::V1::Accounts::Captain::FaqSuggestionsController < Api::V1::Accounts::
|
||||
end
|
||||
|
||||
def dismiss
|
||||
raise ActiveRecord::RecordNotFound unless @suggestion.open?
|
||||
@suggestion.with_lock do
|
||||
raise ActiveRecord::RecordNotFound unless @suggestion.open?
|
||||
|
||||
@suggestion.dismissed!
|
||||
@suggestion.dismissed!
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -31,14 +31,6 @@ class Captain::AssistantPolicy < ApplicationPolicy
|
||||
@account_user.administrator?
|
||||
end
|
||||
|
||||
def approve?
|
||||
update?
|
||||
end
|
||||
|
||||
def dismiss?
|
||||
update?
|
||||
end
|
||||
|
||||
def destroy?
|
||||
@account_user.administrator?
|
||||
end
|
||||
|
||||
@@ -85,6 +85,8 @@ class Captain::Llm::ConversationFaqService < Llm::BaseAiService
|
||||
|
||||
def attach_observation(suggestion, faq)
|
||||
suggestion.with_lock do
|
||||
next unless suggestion.open?
|
||||
|
||||
existing_observation = suggestion.observations.find_by(conversation: conversation)
|
||||
next existing_observation if existing_observation
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ RSpec.describe Captain::AssistantPolicy, type: :policy do
|
||||
end
|
||||
end
|
||||
|
||||
permissions :tools?, :create?, :update?, :approve?, :dismiss?, :destroy?, :sync?, :drilldown? do
|
||||
permissions :tools?, :create?, :update?, :destroy?, :sync?, :drilldown? do
|
||||
context 'when administrator' do
|
||||
it { expect(assistant_policy).to permit(administrator_context, assistant) }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user