Skip to content

Commit

Permalink
Fix: calls with undefined user not going through
Browse files Browse the repository at this point in the history
  • Loading branch information
philipperolet committed Dec 9, 2023
1 parent 59d2e73 commit 70a11a6
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions front/lib/api/assistant/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function getAgentConfiguration(
agentConfiguration?: AgentConfiguration
): Promise<AgentConfigurationType | null> {
const owner = auth.workspace();
if (!owner) {
if (!owner || !auth.isUser()) {
throw new Error("Unexpected `auth` without `workspace`.");
}
const plan = auth.plan();
Expand All @@ -66,7 +66,7 @@ export async function getAgentConfiguration(
if (isGlobalAgentId(agentId)) {
return await getGlobalAgent(auth, agentId, null);
}

const user = auth.user();
const agent =
agentConfiguration ??
(await AgentConfiguration.findOne({
Expand All @@ -88,14 +88,16 @@ export async function getAgentConfiguration(
model: AgentDustAppRunConfiguration,
as: "dustAppRunConfiguration",
},
{
model: AgentUserRelation,
where: {
userId: auth.user()?.id,
},
attributes: ["relation"],
required: false,
},
...(user
? [
{
model: AgentUserRelation,
where: { userId: user.id },
attributes: ["relation"],
required: false,
},
]
: []),
],
limit: 1,
}));
Expand Down Expand Up @@ -247,6 +249,7 @@ export async function getAgentConfigurations(
throw new Error("Unexpected `auth` from outside workspace.");
}

const user = auth.user();
const baseAgentsSequelizeQuery = {
where: {
workspaceId: owner.id,
Expand All @@ -266,14 +269,16 @@ export async function getAgentConfigurations(
model: AgentDustAppRunConfiguration,
as: "dustAppRunConfiguration",
},
{
model: AgentUserRelation,
where: {
userId: auth.user()?.id,
},
attributes: ["relation"],
required: false,
},
...(user
? [
{
model: AgentUserRelation,
where: { userId: user.id },
attributes: ["relation"],
required: false,
},
]
: []),
],
};

Expand Down

0 comments on commit 70a11a6

Please sign in to comment.