You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* improvement(sidebar): full sidebar UI complete, adding collapsed state styling improvements
* improvement(ui): full sidebar state
* improvement(ui/ux): finished sidebar styling
* improvement(ui): scrollable workflows
* improvement(ui/ux): added loading state
* improvement(sidebar): adding loading for user and plan
* fix: skeleton only on initial load
* improvement(control-bar): adjusted styling
* feat(workspaces): added schema for workspaces and setup workspace header UI
* feat(workspaces): added route to fetch for workspace header
* fix: deployment error
* fix: deployment error
* feat(workspaces): added workspace id to workflow table
* feat(workspaces): ran migrations to dev
* feat(workspaces): completed connecting registries to workspaces and added migration route
* fix(workspaces): N+1 database queries
* improvement(ui/ux): sidebar
* hotfix(sidebar): hid top nav section
* fix(ux): adding workflow over header dropdown
// CRITICAL SAFEGUARD: Prevent wiping out existing workflows
88
160
// If client is sending empty workflows object, first check if user has existing workflows
89
161
if(Object.keys(clientWorkflows).length===0){
90
-
constexistingWorkflows=awaitdb
91
-
.select()
92
-
.from(workflow)
93
-
.where(eq(workflow.userId,session.user.id))
162
+
letexistingWorkflows;
163
+
164
+
if(workspaceId){
165
+
existingWorkflows=awaitdb
166
+
.select()
167
+
.from(workflow)
168
+
.where(and(
169
+
eq(workflow.userId,session.user.id),
170
+
eq(workflow.workspaceId,workspaceId)
171
+
));
172
+
}else{
173
+
existingWorkflows=awaitdb
174
+
.select()
175
+
.from(workflow)
176
+
.where(eq(workflow.userId,session.user.id));
177
+
}
94
178
95
179
// If user has existing workflows, but client sends empty, reject the sync
96
180
if(existingWorkflows.length>0){
97
181
logger.warn(
98
-
`[${requestId}] Prevented data loss: Client attempted to sync empty workflows while DB has ${existingWorkflows.length} workflows`
182
+
`[${requestId}] Prevented data loss: Client attempted to sync empty workflows while DB has ${existingWorkflows.length} workflows in workspace ${workspaceId||'default'}`
99
183
)
100
184
returnNextResponse.json(
101
185
{
@@ -107,11 +191,41 @@ export async function POST(req: NextRequest) {
107
191
}
108
192
}
109
193
194
+
// Validate that the workspace exists if one is specified
195
+
if(workspaceId){
196
+
constworkspaceExists=awaitdb
197
+
.select({id: workspace.id})
198
+
.from(workspace)
199
+
.where(eq(workspace.id,workspaceId))
200
+
.then(rows=>rows.length>0)
201
+
202
+
if(!workspaceExists){
203
+
logger.warn(`[${requestId}] Attempt to sync workflows to non-existent workspace: ${workspaceId}`)
204
+
returnNextResponse.json({
205
+
error: 'Workspace not found',
206
+
code: 'WORKSPACE_NOT_FOUND'
207
+
},{status: 404})
208
+
}
209
+
}
210
+
110
211
// Get all workflows for the user from the database
111
-
constdbWorkflows=awaitdb
112
-
.select()
113
-
.from(workflow)
114
-
.where(eq(workflow.userId,session.user.id))
212
+
// If workspaceId is provided, only get workflows for that workspace
213
+
letdbWorkflows;
214
+
215
+
if(workspaceId){
216
+
dbWorkflows=awaitdb
217
+
.select()
218
+
.from(workflow)
219
+
.where(and(
220
+
eq(workflow.userId,session.user.id),
221
+
eq(workflow.workspaceId,workspaceId)
222
+
))
223
+
}else{
224
+
dbWorkflows=awaitdb
225
+
.select()
226
+
.from(workflow)
227
+
.where(eq(workflow.userId,session.user.id))
228
+
}
115
229
116
230
constnow=newDate()
117
231
constoperations: Promise<any>[]=[]
@@ -130,13 +244,17 @@ export async function POST(req: NextRequest) {
0 commit comments