diff --git a/front/lib/api/assistant/feedback.ts b/front/lib/api/assistant/feedback.ts index e5086d51f12d..999e338de41f 100644 --- a/front/lib/api/assistant/feedback.ts +++ b/front/lib/api/assistant/feedback.ts @@ -40,12 +40,7 @@ export async function getConversationFeedbacksForUser( auth: Authenticator, conversation: ConversationType | ConversationWithoutContentType ): Promise> { - const owner = auth.workspace(); - if (!owner) { - return new Err(new Error("workspace_not_found")); - } - const user = auth.user(); - if (!canAccessConversation(auth, conversation) || !user) { + if (!canAccessConversation(auth, conversation)) { return new Err(new ConversationError("conversation_access_restricted")); } @@ -80,13 +75,6 @@ export async function upsertMessageFeedback( isConversationShared?: boolean; } ) { - const owner = auth.workspace(); - if (!owner) { - return new Err({ - type: "workspace_not_found", - message: "The workspace you're trying to access was not found.", - }); - } const feedbackWithConversationContext = await AgentMessageFeedbackResource.getFeedbackWithConversationContext({ auth, @@ -106,7 +94,7 @@ export async function upsertMessageFeedback( await feedback.updateFields({ content, thumbDirection, - isConversationShared: false, + isConversationShared, }); return new Ok(undefined); } @@ -148,14 +136,6 @@ export async function deleteMessageFeedback( user: UserType; } ) { - const owner = auth.workspace(); - if (!owner) { - return new Err({ - type: "workspace_not_found", - message: "The workspace you're trying to access was not found.", - }); - } - if (!canAccessConversation(auth, conversation)) { return new Err({ type: "conversation_access_restricted", @@ -210,14 +190,7 @@ export async function getAgentFeedbacks({ Error > > { - const owner = auth.workspace(); - if (!owner || !auth.isUser()) { - return new Err(new Error("workspace_not_found")); - } - const plan = auth.plan(); - if (!plan) { - return new Err(new Error("plan_not_found")); - } + const owner = auth.getNonNullableWorkspace(); // Make sure the user has access to the agent const agentConfiguration = await getAgentConfiguration( diff --git a/front/lib/resources/agent_message_feedback_resource.ts b/front/lib/resources/agent_message_feedback_resource.ts index 2123c690ae55..4a169cd28f15 100644 --- a/front/lib/resources/agent_message_feedback_resource.ts +++ b/front/lib/resources/agent_message_feedback_resource.ts @@ -66,17 +66,13 @@ export class AgentMessageFeedbackResource extends BaseResource> { - try { - await this.model.destroy({ - where: { - id: this.id, - }, - transaction, - }); - return new Ok(undefined); - } catch (err) { - return new Err(err as Error); - } + await this.model.destroy({ + where: { + id: this.id, + }, + transaction, + }); + return new Ok(undefined); } async updateFields( @@ -217,14 +213,7 @@ export class AgentMessageFeedbackResource extends BaseResource> { - const owner = auth.workspace(); - if (!owner) { - return new Err(new Error("workspace_not_found")); - } - const user = auth.user(); - if (!user) { - return new Err(new Error("user_not_found")); - } + const user = auth.getNonNullableUser(); const feedbackForMessages = await Message.findAll({ where: { diff --git a/front/pages/api/w/[wId]/assistant/agent_configurations/[aId]/feedbacks.ts b/front/pages/api/w/[wId]/assistant/agent_configurations/[aId]/feedbacks.ts index 48071a8f47cb..9c5a43d49d38 100644 --- a/front/pages/api/w/[wId]/assistant/agent_configurations/[aId]/feedbacks.ts +++ b/front/pages/api/w/[wId]/assistant/agent_configurations/[aId]/feedbacks.ts @@ -28,7 +28,7 @@ async function handler( }); } - // Make sure the agent configuration is accessible by the user + // IMPORTANT: make sure the agent configuration is accessible by the user. const agentConfiguration = await getAgentConfiguration(auth, aId); if (!agentConfiguration) { return apiError(req, res, {