habulaj commited on
Commit
5ae58b5
·
verified ·
1 Parent(s): ff5a1fb

Update routes/collaboration.py

Browse files
Files changed (1) hide show
  1. routes/collaboration.py +36 -1
routes/collaboration.py CHANGED
@@ -27,7 +27,11 @@ SUPABASE_ROLE_HEADERS = {
27
  "Content-Type": "application/json"
28
  }
29
 
30
- # 🔍 Model
 
 
 
 
31
  class CreateCollaborationRequest(BaseModel):
32
  email: str
33
  password: str
@@ -65,6 +69,37 @@ async def verify_admin_token(user_token: str) -> str:
65
 
66
  return user_id
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  # ➕ Criar colaborador
69
  @router.post("/admin/create-collaboration")
70
  async def create_collaboration(
 
27
  "Content-Type": "application/json"
28
  }
29
 
30
+
31
+ class RemoveCollaborationRequest(BaseModel):
32
+ user_id: str
33
+
34
+ # 🔍 Model
35
  class CreateCollaborationRequest(BaseModel):
36
  email: str
37
  password: str
 
69
 
70
  return user_id
71
 
72
+ @router.post("/admin/remove-collaboration")
73
+ async def remove_collaboration(
74
+ body: RemoveCollaborationRequest,
75
+ user_token: str = Header(None, alias="User-key")
76
+ ):
77
+ try:
78
+ await verify_admin_token(user_token)
79
+
80
+ update_payload = {
81
+ "is_admin": False
82
+ }
83
+
84
+ async with aiohttp.ClientSession() as session:
85
+ async with session.patch(
86
+ f"{SUPABASE_URL}/rest/v1/User?id=eq.{body.user_id}",
87
+ headers=SUPABASE_ROLE_HEADERS,
88
+ json=update_payload
89
+ ) as response:
90
+
91
+ if response.status != 204:
92
+ error_detail = await response.text()
93
+ raise HTTPException(status_code=500, detail=f"Failed to update user admin status: {error_detail}")
94
+
95
+ return {"success": True, "message": "Colaborador removido com sucesso"}
96
+
97
+ except HTTPException as http_ex:
98
+ return {"success": False, "detail": http_ex.detail}
99
+ except Exception as e:
100
+ logging.error(f"❌ Unexpected error: {str(e)}")
101
+ return {"success": False, "detail": str(e)}
102
+
103
  # ➕ Criar colaborador
104
  @router.post("/admin/create-collaboration")
105
  async def create_collaboration(