check authz before consuming project action quota

This commit is contained in:
Ramnique Singh 2025-08-05 17:05:04 +05:30
parent cd6ff9a46f
commit 7592df8068
4 changed files with 12 additions and 12 deletions

View file

@ -52,9 +52,6 @@ export class CreateCachedTurnUseCase implements ICreateCachedTurnUseCase {
// extract projectid from conversation
const { projectId } = conversation;
// assert and consume quota
await this.usageQuotaPolicy.assertAndConsume(projectId);
// authz check
await this.projectActionAuthorizationPolicy.authorize({
caller: data.caller,
@ -63,6 +60,9 @@ export class CreateCachedTurnUseCase implements ICreateCachedTurnUseCase {
projectId,
});
// assert and consume quota
await this.usageQuotaPolicy.assertAndConsume(projectId);
// create cache entry
const key = nanoid();
const payload: z.infer<typeof CachedTurnRequest> = {

View file

@ -44,9 +44,6 @@ export class CreateConversationUseCase implements ICreateConversationUseCase {
let isLiveWorkflow = Boolean(data.isLiveWorkflow);
let workflow = data.workflow;
// assert and consume quota
await this.usageQuotaPolicy.assertAndConsume(projectId);
// authz check
await this.projectActionAuthorizationPolicy.authorize({
caller,
@ -55,6 +52,9 @@ export class CreateConversationUseCase implements ICreateConversationUseCase {
projectId,
});
// assert and consume quota
await this.usageQuotaPolicy.assertAndConsume(projectId);
// if workflow is not provided, fetch workflow
if (!workflow) {
const project = await projectsCollection.findOne({

View file

@ -59,9 +59,6 @@ export class FetchCachedTurnUseCase implements IFetchCachedTurnUseCase {
// extract projectid from conversation
const { projectId } = conversation;
// assert and consume quota
await this.usageQuotaPolicy.assertAndConsume(projectId);
// authz check
await this.projectActionAuthorizationPolicy.authorize({
caller: data.caller,
@ -70,6 +67,9 @@ export class FetchCachedTurnUseCase implements IFetchCachedTurnUseCase {
projectId,
});
// assert and consume quota
await this.usageQuotaPolicy.assertAndConsume(projectId);
// delete from cache
await this.cacheService.delete(`turn-${data.key}`);

View file

@ -51,9 +51,6 @@ export class RunConversationTurnUseCase implements IRunConversationTurnUseCase {
// extract projectid from conversation
const { id: conversationId, projectId } = conversation;
// assert and consume quota
await this.usageQuotaPolicy.assertAndConsume(projectId);
// authz check
await this.projectActionAuthorizationPolicy.authorize({
caller: data.caller,
@ -62,6 +59,9 @@ export class RunConversationTurnUseCase implements IRunConversationTurnUseCase {
projectId,
});
// assert and consume quota
await this.usageQuotaPolicy.assertAndConsume(projectId);
// Check billing auth
if (USE_BILLING) {
// get billing customer id for project