Spaces:
Paused

dushyantsingh0 commited on
Commit
86e1bc3
·
1 Parent(s): 1c89e32

backend stabilization

Browse files
api/v1/tickets.py CHANGED
@@ -710,15 +710,25 @@ async def update_ticket(
710
 
711
  if "assigned_to" in update_data and update_data["assigned_to"]:
712
  assignee_id = update_data["assigned_to"]
713
- assignee_stmt = select(User).where(
714
- User.id == assignee_id,
715
- User.workspace_id == current_user.workspace_id,
716
- User.is_active == True,
717
- User.deleted_at.is_(None)
 
 
 
 
 
 
 
 
 
 
718
  )
719
  assignee_res = await db.execute(assignee_stmt)
720
  if not assignee_res.scalar_one_or_none():
721
- raise HTTPException(status_code=400, detail="Target assignee not found or is inactive")
722
 
723
  if "status" in update_data:
724
  new_status = update_data["status"]
 
710
 
711
  if "assigned_to" in update_data and update_data["assigned_to"]:
712
  assignee_id = update_data["assigned_to"]
713
+ from models.user_workspace import UserWorkspace
714
+ # Enhanced validation: Check if user is in the workspace OR has a global staff role
715
+ assignee_stmt = (
716
+ select(User)
717
+ .outerjoin(UserWorkspace, User.id == UserWorkspace.user_id)
718
+ .where(
719
+ User.id == assignee_id,
720
+ User.is_active == True,
721
+ User.deleted_at.is_(None),
722
+ or_(
723
+ UserWorkspace.workspace_id == current_user.workspace_id,
724
+ User._legacy_role.in_([UserRole.SC_ADMIN, UserRole.SC_LEAD, UserRole.SC_AGENT]),
725
+ User.global_role.isnot(None)
726
+ )
727
+ )
728
  )
729
  assignee_res = await db.execute(assignee_stmt)
730
  if not assignee_res.scalar_one_or_none():
731
+ raise HTTPException(status_code=400, detail="Target assignee not found, is inactive, or lacks access to this workspace")
732
 
733
  if "status" in update_data:
734
  new_status = update_data["status"]
check_job_error.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ from sqlalchemy import select
3
+ from core.database import async_session_factory
4
+ from models.worker_job import WorkerJob
5
+
6
+ async def check():
7
+ async with async_session_factory() as db:
8
+ stmt = select(WorkerJob).order_by(WorkerJob.created_at.desc()).limit(1)
9
+ res = await db.execute(stmt)
10
+ job = res.scalar_one_or_none()
11
+ if job:
12
+ print(f"Task: {job.task_name}")
13
+ print(f"Status: {job.status}")
14
+ print(f"Error: {job.error}")
15
+ print(f"Result: {job.result}")
16
+ else:
17
+ print("No jobs.")
18
+
19
+ if __name__ == "__main__":
20
+ asyncio.run(check())
core/deps.py CHANGED
@@ -172,14 +172,14 @@ async def get_current_super_admin(
172
  current_user: User = Depends(get_current_user)
173
  ) -> User:
174
  """
175
- Strict guard for Super-Admin (SC_ADMIN) roles only.
176
  Used for infrastructure and job monitoring.
177
  """
178
  role_str = str(current_user.role).lower()
179
- if role_str != "3sc_admin":
180
  raise HTTPException(
181
  status_code=status.HTTP_403_FORBIDDEN,
182
- detail="Access Denied: 3SC Super Administrator Only — This diagnostic module is restricted to internal operations leads."
183
  )
184
  return current_user
185
 
 
172
  current_user: User = Depends(get_current_user)
173
  ) -> User:
174
  """
175
+ Strict guard for operations leadership (SC_ADMIN, SC_LEAD).
176
  Used for infrastructure and job monitoring.
177
  """
178
  role_str = str(current_user.role).lower()
179
+ if role_str not in ["3sc_admin", "3sc_lead"]:
180
  raise HTTPException(
181
  status_code=status.HTTP_403_FORBIDDEN,
182
+ detail="Access Denied: 3SC Operations Leadership Only — This diagnostic module is restricted to internal admins and leads."
183
  )
184
  return current_user
185
 
frontend/apps/internal/src/components/WorkerLab.tsx CHANGED
@@ -34,9 +34,9 @@ export const WorkerLab: React.FC = () => {
34
  try {
35
  setRefreshing(true);
36
  const [histRes, statsRes, activeRes] = await Promise.all([
37
- api.get('/api/v1/worker/history/'),
38
- api.get('/api/v1/worker/stats/'),
39
- api.get('/api/v1/worker/active/')
40
  ]);
41
  setJobs(histRes.data);
42
  setStats(statsRes.data);
 
34
  try {
35
  setRefreshing(true);
36
  const [histRes, statsRes, activeRes] = await Promise.all([
37
+ api.get('worker/history/'),
38
+ api.get('worker/stats/'),
39
+ api.get('worker/active/')
40
  ]);
41
  setJobs(histRes.data);
42
  setStats(statsRes.data);
nexus_worker.py CHANGED
@@ -56,9 +56,10 @@ async def on_job_start(ctx):
56
  job = res.scalar_one_or_none()
57
 
58
  if not job:
 
59
  job = WorkerJob(
60
  id=job_id,
61
- task_name=ctx.get("job_name", "unknown"),
62
  status=JobStatus.RUNNING,
63
  args=sanitize_for_db(ctx.get("args", [])),
64
  kwargs=sanitize_for_db(ctx.get("kwargs", {})),
 
56
  job = res.scalar_one_or_none()
57
 
58
  if not job:
59
+ task_name = ctx.get("job_name") or ctx.get("function") or str(ctx.get("job_id", "unknown"))
60
  job = WorkerJob(
61
  id=job_id,
62
+ task_name=task_name,
63
  status=JobStatus.RUNNING,
64
  args=sanitize_for_db(ctx.get("args", [])),
65
  kwargs=sanitize_for_db(ctx.get("kwargs", {})),
verify_job_name.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ from sqlalchemy import select
3
+ from core.database import async_session_factory
4
+ from models.worker_job import WorkerJob
5
+
6
+ async def verify():
7
+ async with async_session_factory() as db:
8
+ stmt = select(WorkerJob).order_by(WorkerJob.created_at.desc()).limit(1)
9
+ res = await db.execute(stmt)
10
+ job = res.scalar_one_or_none()
11
+ if job:
12
+ print(f"LATEST_JOB_NAME: {job.task_name}")
13
+ print(f"STATUS: {job.status}")
14
+ else:
15
+ print("NO_JOBS_FOUND")
16
+
17
+ if __name__ == "__main__":
18
+ asyncio.run(verify())