-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Job distribution graph #152
Conversation
WalkthroughThe pull request introduces modifications to the job triggers fetching mechanism in the Changes
Possibly related PRs
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🧰 Additional context used🔇 Additional comments (3)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (3)
- apps/webservice/src/app/[workspaceSlug]/(job)/jobs/page.tsx (1 hunks)
- apps/webservice/src/app/[workspaceSlug]/systems/JobHistoryChart.tsx (2 hunks)
- packages/api/src/router/job.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (5)
apps/webservice/src/app/[workspaceSlug]/(job)/jobs/page.tsx (1)
24-26
: LGTM! Verify error handling and type definitions.The update to use
api.job.config.byWorkspaceId.list(workspace.id)
aligns with the reported API refactoring. The change is straightforward and doesn't affect the component's logic.To ensure the change is fully compatible, please verify:
- Error handling for the new API call
- Type definitions for the returned data
Run the following script to check for any type-related changes:
apps/webservice/src/app/[workspaceSlug]/systems/JobHistoryChart.tsx (4)
28-31
: Verify the updated query method and data structureThe query has been updated to
api.job.config.byWorkspaceId.list.useQuery
. Ensure that the data returned by this new endpoint matches the expected structure used in the component, especially when accessingreleaseJobTriggers.data
.
33-36
: Ensure correct timezone handling in daily counts queryThe
dailyCounts
query uses the client's timezone:timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,Verify that using the client's timezone aligns with the server's data and that it correctly reflects the desired timezone for all users, particularly in a multi-timezone context.
41-42
: Check date comparisons for timezone consistencyWhen comparing dates using
isSameDay(c.date, d)
:jobs: dailyCounts.data?.find((c) => isSameDay(c.date, d))?.count ?? 0,Ensure that both
c.date
andd
are in the same timezone or adjusted appropriately to prevent any mismatches due to timezone differences.
Line range hint
71-73
: Confirm data structure after query updateWith the updated query, verify that
releaseJobTriggers.data
has the expected structure. Ensure that accessingt.job.status
is valid and thatt.job
exists in the returned data.
packages/api/src/router/job.ts
Outdated
dailyCount: protectedProcedure | ||
.input( | ||
z.object({ | ||
workspaceId: z.string().uuid(), | ||
timezone: z.string(), | ||
}), | ||
) | ||
.query(async ({ ctx, input }) => { | ||
const dateTruncExpr = sql<Date>`date_trunc('day', ${releaseJobTrigger.createdAt} AT TIME ZONE 'UTC' AT TIME ZONE '${sql.raw(input.timezone)}')`; | ||
return ctx.db | ||
.select({ | ||
date: dateTruncExpr.as("date"), | ||
count: sql<number>`COUNT(*)`.as("count"), | ||
}) | ||
.from(releaseJobTrigger) | ||
.innerJoin( | ||
environment, | ||
eq(releaseJobTrigger.environmentId, environment.id), | ||
) | ||
.innerJoin(system, eq(environment.systemId, system.id)) | ||
.where(eq(system.workspaceId, input.workspaceId)) | ||
.groupBy(dateTruncExpr) | ||
.orderBy(dateTruncExpr); | ||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add missing authorization check to 'dailyCount' procedure
The dailyCount
procedure currently lacks an authorization check, which could allow unauthorized access to sensitive data. To ensure that only authorized users can access this endpoint, please add an authorizationCheck
similar to the one used in the list
procedure.
Apply this diff to add the authorization check:
dailyCount: protectedProcedure
+ .meta({
+ authorizationCheck: ({ canUser, input }) =>
+ canUser
+ .perform(Permission.SystemList)
+ .on({ type: "workspace", id: input.workspaceId }),
+ })
.input(
z.object({
workspaceId: z.string().uuid(),
timezone: z.string(),
}),
)
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
dailyCount: protectedProcedure | |
.input( | |
z.object({ | |
workspaceId: z.string().uuid(), | |
timezone: z.string(), | |
}), | |
) | |
.query(async ({ ctx, input }) => { | |
const dateTruncExpr = sql<Date>`date_trunc('day', ${releaseJobTrigger.createdAt} AT TIME ZONE 'UTC' AT TIME ZONE '${sql.raw(input.timezone)}')`; | |
return ctx.db | |
.select({ | |
date: dateTruncExpr.as("date"), | |
count: sql<number>`COUNT(*)`.as("count"), | |
}) | |
.from(releaseJobTrigger) | |
.innerJoin( | |
environment, | |
eq(releaseJobTrigger.environmentId, environment.id), | |
) | |
.innerJoin(system, eq(environment.systemId, system.id)) | |
.where(eq(system.workspaceId, input.workspaceId)) | |
.groupBy(dateTruncExpr) | |
.orderBy(dateTruncExpr); | |
}), | |
dailyCount: protectedProcedure | |
.meta({ | |
authorizationCheck: ({ canUser, input }) => | |
canUser | |
.perform(Permission.SystemList) | |
.on({ type: "workspace", id: input.workspaceId }), | |
}) | |
.input( | |
z.object({ | |
workspaceId: z.string().uuid(), | |
timezone: z.string(), | |
}), | |
) | |
.query(async ({ ctx, input }) => { | |
const dateTruncExpr = sql<Date>`date_trunc('day', ${releaseJobTrigger.createdAt} AT TIME ZONE 'UTC' AT TIME ZONE '${sql.raw(input.timezone)}')`; | |
return ctx.db | |
.select({ | |
date: dateTruncExpr.as("date"), | |
count: sql<number>`COUNT(*)`.as("count"), | |
}) | |
.from(releaseJobTrigger) | |
.innerJoin( | |
environment, | |
eq(releaseJobTrigger.environmentId, environment.id), | |
) | |
.innerJoin(system, eq(environment.systemId, system.id)) | |
.where(eq(system.workspaceId, input.workspaceId)) | |
.groupBy(dateTruncExpr) | |
.orderBy(dateTruncExpr); | |
}), |
}), | ||
) | ||
.query(async ({ ctx, input }) => { | ||
const dateTruncExpr = sql<Date>`date_trunc('day', ${releaseJobTrigger.createdAt} AT TIME ZONE 'UTC' AT TIME ZONE '${sql.raw(input.timezone)}')`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate 'timezone' input to prevent SQL injection
Using sql.raw(input.timezone)
directly interpolates user input into the SQL query, which could lead to SQL injection vulnerabilities if the input is not properly sanitized. To mitigate this risk, validate input.timezone
against a list of allowed timezones.
Apply this diff to validate the timezone input:
.input(
z.object({
workspaceId: z.string().uuid(),
- timezone: z.string(),
+ timezone: z.enum([
+ 'UTC',
+ 'America/New_York',
+ 'Europe/London',
+ 'Asia/Tokyo',
+ // Add all supported time zones
+ ]),
),
Alternatively, consider using a library like moment-timezone
to validate that the provided timezone is a valid IANA timezone identifier before using it in the SQL query.
Committable suggestion was skipped due to low confidence.
Summary by CodeRabbit
New Features
Bug Fixes
Refactor