7
7
from pwncore .config import config
8
8
from pwncore .models import Team , User , Team_Pydantic , User_Pydantic , Container
9
9
from pwncore .routes .auth import RequireJwt
10
+ from pwncore .routes .admin import ADMIN_HASH
10
11
11
12
# from pwncore.routes.leaderboard import gcache
12
13
13
- # Metadata at the top for instant caccessibility
14
+ # Metadata at the top for instant accessibility
14
15
metadata = {"name" : "team" , "description" : "Operations with teams" }
15
16
16
17
router = APIRouter (prefix = "/team" , tags = ["team" ])
@@ -120,58 +121,10 @@ async def get_team_containers(response: Response, jwt: RequireJwt):
120
121
121
122
return result
122
123
123
- @atomic ()
124
- @router .post ("/remove" )
125
- async def remove_member (user_info : UserRemoveBody , response : Response , jwt : RequireJwt ):
126
- team_id = jwt ["team_id" ]
127
- user = await User .get_or_none (team_id = team_id , tag = user_info .tag )
128
-
129
- if not user :
130
- response .status_code = 403
131
- return {"msg_code" : config .msg_codes ["user_not_in_team" ]}
132
-
133
- try :
134
- await user .delete ()
135
- except Exception :
136
- response .status_code = 500
137
- return {"msg_code" : config .msg_codes ["db_error" ]}
138
-
139
- return {"msg_code" : config .msg_codes ["user_removed" ]}
140
-
141
-
142
- @router .get ("/containers" )
143
- async def get_team_containers (response : Response , jwt : RequireJwt ):
144
- containers = await Container .filter (team_id = jwt ["team_id" ]).prefetch_related (
145
- "ports" , "problem"
146
- )
147
-
148
- result = {
149
- container .problem .id : await container .ports .all ().values_list ("port" , flat = True )
150
- for container in containers
151
- }
152
-
153
- return result
154
-
155
-
156
124
@atomic ()
157
125
@router .post ("team/{id}" )
158
126
async def upsert_table_tn (id : int , data : TableTNBody , request : Request , response : Response ):
159
127
admin_password = (await request .body ()).strip ()
160
128
161
129
if not bcrypt .verify (admin_password , ADMIN_HASH ):
162
- response .status_code = 401
163
- return {"msg_code" : "not_authorized" }
164
-
165
- team = await Team .get_or_none (id = id )
166
- if not team :
167
- response .status_code = 404
168
- return {"msg_code" : "team_not_found" }
169
-
170
- try :
171
- team .table_tn = data .table_tn
172
- await team .save ()
173
- except Exception :
174
- response .status_code = 500
175
- return {"msg_code" : "db_error" }
176
-
177
- return {"msg_code" : "tabletn_upserted" }
130
+ response .status_code = 401
0 commit comments