Spaces:
3SCError404
/
Paused

dushyantsingh0 commited on
Commit
1e63a5f
·
1 Parent(s): 6ce1162

backend stabilization

Browse files
Files changed (1) hide show
  1. core/deps.py +15 -6
core/deps.py CHANGED
@@ -129,11 +129,16 @@ async def get_current_user_from_token(token: str, db: AsyncSession, portal: Opti
129
  raise credentials_exception
130
 
131
  # Construct a lightweight user-like object for Downstream dependencies
132
- # FastAPI expects a User model instance sometimes, but many routes just need attributes
133
- # We'll use a Simple Namespace or similar to maintain compatibility
134
  from types import SimpleNamespace
135
  user_ns = SimpleNamespace(**user)
136
 
 
 
 
 
 
 
 
137
  from uuid import UUID
138
  # Safely parse active_ws_id
139
  ws_id = None
@@ -142,11 +147,15 @@ async def get_current_user_from_token(token: str, db: AsyncSession, portal: Opti
142
  ws_id = UUID(active_ws_id)
143
  except (ValueError, TypeError):
144
  pass
145
- setattr(user_ns, "workspace_id", ws_id)
146
- setattr(user_ns, "role", active_role or user_ns.role)
147
 
148
- # Add flag for platform admin
149
- setattr(user_ns, "is_platform_admin", str(user_ns.role) == "3sc_admin")
 
 
 
 
 
 
150
 
151
  # --- STRICT PORTAL ISOLATION (Backend Guard) ---
152
  role_str = str(user_ns.role).lower()
 
129
  raise credentials_exception
130
 
131
  # Construct a lightweight user-like object for Downstream dependencies
 
 
132
  from types import SimpleNamespace
133
  user_ns = SimpleNamespace(**user)
134
 
135
+ # 0.5 Ensure property compatibility (Shim for SQLAlchemy properties)
136
+ # The dictionary 'user' contains column names like _legacy_role
137
+ if not hasattr(user_ns, "role"):
138
+ user_ns.role = user.get("role") or user.get("_legacy_role") or user.get("global_role")
139
+ if not hasattr(user_ns, "workspace_id"):
140
+ user_ns.workspace_id = user.get("workspace_id") or user.get("_legacy_workspace_id")
141
+
142
  from uuid import UUID
143
  # Safely parse active_ws_id
144
  ws_id = None
 
147
  ws_id = UUID(active_ws_id)
148
  except (ValueError, TypeError):
149
  pass
 
 
150
 
151
+ if ws_id: user_ns.workspace_id = ws_id
152
+ if active_role: user_ns.role = active_role
153
+
154
+ # Add flag for platform admin (Check both email and role for hardening)
155
+ user_ns.is_platform_admin = (
156
+ str(user_ns.role) == "3sc_admin" or
157
+ user.get("global_role") == "superadmin"
158
+ )
159
 
160
  # --- STRICT PORTAL ISOLATION (Backend Guard) ---
161
  role_str = str(user_ns.role).lower()