-
Notifications
You must be signed in to change notification settings - Fork 3.2k
v0.3.2: improvement + fix + feat #708
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
Changes from all commits
b13f339
19ca9c7
27c248a
bdfe7e9
55a9adf
4c6c727
92fe353
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,7 +5,7 @@ import { getSession } from '@/lib/auth' | |||||||||||||
| import { env } from '@/lib/env' | ||||||||||||||
| import { createLogger } from '@/lib/logs/console-logger' | ||||||||||||||
| import { db } from '@/db' | ||||||||||||||
| import { invitation, member, permissions, workspaceInvitation, workspaceMember } from '@/db/schema' | ||||||||||||||
| import { invitation, member, permissions, workspaceInvitation } from '@/db/schema' | ||||||||||||||
|
|
||||||||||||||
| const logger = createLogger('OrganizationInvitationAcceptance') | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -135,18 +135,6 @@ export async function GET(req: NextRequest) { | |||||||||||||
| wsInvitation.expiresAt && | ||||||||||||||
| new Date().toISOString() <= wsInvitation.expiresAt.toISOString() | ||||||||||||||
| ) { | ||||||||||||||
| // Check if user isn't already a member of the workspace | ||||||||||||||
| const existingWorkspaceMember = await tx | ||||||||||||||
| .select() | ||||||||||||||
| .from(workspaceMember) | ||||||||||||||
| .where( | ||||||||||||||
| and( | ||||||||||||||
| eq(workspaceMember.workspaceId, wsInvitation.workspaceId), | ||||||||||||||
| eq(workspaceMember.userId, session.user.id) | ||||||||||||||
| ) | ||||||||||||||
| ) | ||||||||||||||
| .limit(1) | ||||||||||||||
|
|
||||||||||||||
| // Check if user doesn't already have permissions on the workspace | ||||||||||||||
| const existingPermission = await tx | ||||||||||||||
| .select() | ||||||||||||||
|
|
@@ -160,17 +148,7 @@ export async function GET(req: NextRequest) { | |||||||||||||
| ) | ||||||||||||||
| .limit(1) | ||||||||||||||
|
|
||||||||||||||
| if (existingWorkspaceMember.length === 0 && existingPermission.length === 0) { | ||||||||||||||
| // Add user as workspace member | ||||||||||||||
| await tx.insert(workspaceMember).values({ | ||||||||||||||
| id: randomUUID(), | ||||||||||||||
| workspaceId: wsInvitation.workspaceId, | ||||||||||||||
| userId: session.user.id, | ||||||||||||||
| role: wsInvitation.role, | ||||||||||||||
| joinedAt: new Date(), | ||||||||||||||
| updatedAt: new Date(), | ||||||||||||||
| }) | ||||||||||||||
|
|
||||||||||||||
| if (existingPermission.length === 0) { | ||||||||||||||
| // Add workspace permissions | ||||||||||||||
| await tx.insert(permissions).values({ | ||||||||||||||
| id: randomUUID(), | ||||||||||||||
|
|
@@ -311,17 +289,6 @@ export async function POST(req: NextRequest) { | |||||||||||||
| wsInvitation.expiresAt && | ||||||||||||||
| new Date().toISOString() <= wsInvitation.expiresAt.toISOString() | ||||||||||||||
| ) { | ||||||||||||||
|
Comment on lines
289
to
291
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: same date comparison issue here - use native Date objects instead of string conversion
Suggested change
|
||||||||||||||
| const existingWorkspaceMember = await tx | ||||||||||||||
| .select() | ||||||||||||||
| .from(workspaceMember) | ||||||||||||||
| .where( | ||||||||||||||
| and( | ||||||||||||||
| eq(workspaceMember.workspaceId, wsInvitation.workspaceId), | ||||||||||||||
| eq(workspaceMember.userId, session.user.id) | ||||||||||||||
| ) | ||||||||||||||
| ) | ||||||||||||||
| .limit(1) | ||||||||||||||
|
|
||||||||||||||
| const existingPermission = await tx | ||||||||||||||
| .select() | ||||||||||||||
| .from(permissions) | ||||||||||||||
|
|
@@ -334,16 +301,7 @@ export async function POST(req: NextRequest) { | |||||||||||||
| ) | ||||||||||||||
| .limit(1) | ||||||||||||||
|
|
||||||||||||||
| if (existingWorkspaceMember.length === 0 && existingPermission.length === 0) { | ||||||||||||||
| await tx.insert(workspaceMember).values({ | ||||||||||||||
| id: randomUUID(), | ||||||||||||||
| workspaceId: wsInvitation.workspaceId, | ||||||||||||||
| userId: session.user.id, | ||||||||||||||
| role: wsInvitation.role, | ||||||||||||||
| joinedAt: new Date(), | ||||||||||||||
| updatedAt: new Date(), | ||||||||||||||
| }) | ||||||||||||||
|
|
||||||||||||||
| if (existingPermission.length === 0) { | ||||||||||||||
| await tx.insert(permissions).values({ | ||||||||||||||
| id: randomUUID(), | ||||||||||||||
| userId: session.user.id, | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import { | |
| generateCronExpression, | ||
| getScheduleTimeValues, | ||
| getSubBlockValue, | ||
| validateCronExpression, | ||
| } from '@/lib/schedules/utils' | ||
| import { db } from '@/db' | ||
| import { workflowSchedule } from '@/db/schema' | ||
|
|
@@ -192,6 +193,18 @@ export async function POST(req: NextRequest) { | |
|
|
||
| cronExpression = generateCronExpression(defaultScheduleType, scheduleValues) | ||
|
|
||
| // Additional validation for custom cron expressions | ||
| if (defaultScheduleType === 'custom' && cronExpression) { | ||
| const validation = validateCronExpression(cronExpression) | ||
| if (!validation.isValid) { | ||
| logger.error(`[${requestId}] Invalid cron expression: ${validation.error}`) | ||
| return NextResponse.json( | ||
| { error: `Invalid cron expression: ${validation.error}` }, | ||
| { status: 400 } | ||
| ) | ||
| } | ||
| } | ||
|
Comment on lines
+196
to
+206
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: The validation check could fail silently if cronExpression is null. Consider adding null check or handling this case explicitly. |
||
|
|
||
| nextRunAt = calculateNextRunTime(defaultScheduleType, scheduleValues) | ||
|
|
||
| logger.debug( | ||
|
|
||
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.
style: Consider adding an explicit alias for permissions.createdAt since it's used as both joinedAt and createdAt in the response