Skip to content

Commit ab62d4d

Browse files
authored
Persisting checkbox state (#329)
* persist show_inactive state after activate/inactive * make ruff,flake8,black Signed-off-by: Keval Mahajan <[email protected]> * delete call persists the show_inactive state Signed-off-by: Keval Mahajan <[email protected]> * delete, edit, add transactions support persistance of show_inactive checkbox Signed-off-by: Keval Mahajan <[email protected]> * make black, ruff, flake8 Signed-off-by: Keval Mahajan <[email protected]> --------- Signed-off-by: Keval Mahajan <[email protected]>
1 parent 38630a1 commit ab62d4d

File tree

3 files changed

+213
-10
lines changed

3 files changed

+213
-10
lines changed

mcpgateway/admin.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ async def admin_add_server(request: Request, db: Session = Depends(get_db), user
154154
RedirectResponse: A redirect to the admin dashboard catalog section
155155
"""
156156
form = await request.form()
157+
is_inactive_checked = form.get("is_inactive_checked", "false")
157158
try:
158159
logger.debug(f"User {user} is adding a new server with name: {form['name']}")
160+
159161
server = ServerCreate(
160162
name=form.get("name"),
161163
description=form.get("description"),
@@ -167,11 +169,15 @@ async def admin_add_server(request: Request, db: Session = Depends(get_db), user
167169
await server_service.register_server(db, server)
168170

169171
root_path = request.scope.get("root_path", "")
172+
if is_inactive_checked.lower() == "true":
173+
return RedirectResponse(f"{root_path}/admin/?include_inactive=true#catalog", status_code=303)
170174
return RedirectResponse(f"{root_path}/admin#catalog", status_code=303)
171175
except Exception as e:
172176
logger.error(f"Error adding server: {e}")
173177

174178
root_path = request.scope.get("root_path", "")
179+
if is_inactive_checked.lower() == "true":
180+
return RedirectResponse(f"{root_path}/admin/?include_inactive=true#catalog", status_code=303)
175181
return RedirectResponse(f"{root_path}/admin#catalog", status_code=303)
176182

177183

@@ -207,6 +213,7 @@ async def admin_edit_server(
207213
RedirectResponse: A redirect to the admin dashboard catalog section with a status code of 303
208214
"""
209215
form = await request.form()
216+
is_inactive_checked = form.get("is_inactive_checked", "false")
210217
try:
211218
logger.debug(f"User {user} is editing server ID {server_id} with name: {form.get('name')}")
212219
server = ServerUpdate(
@@ -220,11 +227,16 @@ async def admin_edit_server(
220227
await server_service.update_server(db, server_id, server)
221228

222229
root_path = request.scope.get("root_path", "")
230+
231+
if is_inactive_checked.lower() == "true":
232+
return RedirectResponse(f"{root_path}/admin/?include_inactive=true#catalog", status_code=303)
223233
return RedirectResponse(f"{root_path}/admin#catalog", status_code=303)
224234
except Exception as e:
225235
logger.error(f"Error editing server: {e}")
226236

227237
root_path = request.scope.get("root_path", "")
238+
if is_inactive_checked.lower() == "true":
239+
return RedirectResponse(f"{root_path}/admin/?include_inactive=true#catalog", status_code=303)
228240
return RedirectResponse(f"{root_path}/admin#catalog", status_code=303)
229241

230242

@@ -256,12 +268,15 @@ async def admin_toggle_server(
256268
form = await request.form()
257269
logger.debug(f"User {user} is toggling server ID {server_id} with activate: {form.get('activate')}")
258270
activate = form.get("activate", "true").lower() == "true"
271+
is_inactive_checked = form.get("is_inactive_checked", "false")
259272
try:
260273
await server_service.toggle_server_status(db, server_id, activate)
261274
except Exception as e:
262275
logger.error(f"Error toggling server status: {e}")
263276

264277
root_path = request.scope.get("root_path", "")
278+
if is_inactive_checked.lower() == "true":
279+
return RedirectResponse(f"{root_path}/admin/?include_inactive=true#catalog", status_code=303)
265280
return RedirectResponse(f"{root_path}/admin#catalog", status_code=303)
266281

267282

@@ -289,7 +304,12 @@ async def admin_delete_server(server_id: str, request: Request, db: Session = De
289304
except Exception as e:
290305
logger.error(f"Error deleting server: {e}")
291306

307+
form = await request.form()
308+
is_inactive_checked = form.get("is_inactive_checked", "false")
292309
root_path = request.scope.get("root_path", "")
310+
311+
if is_inactive_checked.lower() == "true":
312+
return RedirectResponse(f"{root_path}/admin/?include_inactive=true#catalog", status_code=303)
293313
return RedirectResponse(f"{root_path}/admin#catalog", status_code=303)
294314

295315

@@ -398,12 +418,16 @@ async def admin_toggle_gateway(
398418
logger.debug(f"User {user} is toggling gateway ID {gateway_id}")
399419
form = await request.form()
400420
activate = form.get("activate", "true").lower() == "true"
421+
is_inactive_checked = form.get("is_inactive_checked", "false")
422+
401423
try:
402424
await gateway_service.toggle_gateway_status(db, gateway_id, activate)
403425
except Exception as e:
404426
logger.error(f"Error toggling gateway status: {e}")
405427

406428
root_path = request.scope.get("root_path", "")
429+
if is_inactive_checked.lower() == "true":
430+
return RedirectResponse(f"{root_path}/admin/?include_inactive=true#gateways", status_code=303)
407431
return RedirectResponse(f"{root_path}/admin#gateways", status_code=303)
408432

409433

@@ -650,6 +674,9 @@ async def admin_edit_tool(
650674
await tool_service.update_tool(db, tool_id, tool)
651675

652676
root_path = request.scope.get("root_path", "")
677+
is_inactive_checked = form.get("is_inactive_checked", "false")
678+
if is_inactive_checked.lower() == "true":
679+
return RedirectResponse(f"{root_path}/admin/?include_inactive=true#tools", status_code=303)
653680
return RedirectResponse(f"{root_path}/admin#tools", status_code=303)
654681
except ToolNameConflictError as e:
655682
return JSONResponse(content={"message": str(e), "success": False}, status_code=400)
@@ -679,7 +706,12 @@ async def admin_delete_tool(tool_id: str, request: Request, db: Session = Depend
679706
logger.debug(f"User {user} is deleting tool ID {tool_id}")
680707
await tool_service.delete_tool(db, tool_id)
681708

709+
form = await request.form()
710+
is_inactive_checked = form.get("is_inactive_checked", "false")
682711
root_path = request.scope.get("root_path", "")
712+
713+
if is_inactive_checked.lower() == "true":
714+
return RedirectResponse(f"{root_path}/admin/?include_inactive=true#tools", status_code=303)
683715
return RedirectResponse(f"{root_path}/admin#tools", status_code=303)
684716

685717

@@ -711,12 +743,15 @@ async def admin_toggle_tool(
711743
logger.debug(f"User {user} is toggling tool ID {tool_id}")
712744
form = await request.form()
713745
activate = form.get("activate", "true").lower() == "true"
746+
is_inactive_checked = form.get("is_inactive_checked", "false")
714747
try:
715748
await tool_service.toggle_tool_status(db, tool_id, activate, reachable=activate)
716749
except Exception as e:
717750
logger.error(f"Error toggling tool status: {e}")
718751

719752
root_path = request.scope.get("root_path", "")
753+
if is_inactive_checked.lower() == "true":
754+
return RedirectResponse(f"{root_path}/admin/?include_inactive=true#tools", status_code=303)
720755
return RedirectResponse(f"{root_path}/admin#tools", status_code=303)
721756

722757

@@ -825,6 +860,10 @@ async def admin_edit_gateway(
825860
await gateway_service.update_gateway(db, gateway_id, gateway)
826861

827862
root_path = request.scope.get("root_path", "")
863+
is_inactive_checked = form.get("is_inactive_checked", "false")
864+
865+
if is_inactive_checked.lower() == "true":
866+
return RedirectResponse(f"{root_path}/admin/?include_inactive=true#gateways", status_code=303)
828867
return RedirectResponse(f"{root_path}/admin#gateways", status_code=303)
829868

830869

@@ -850,7 +889,12 @@ async def admin_delete_gateway(gateway_id: str, request: Request, db: Session =
850889
logger.debug(f"User {user} is deleting gateway ID {gateway_id}")
851890
await gateway_service.delete_gateway(db, gateway_id)
852891

892+
form = await request.form()
893+
is_inactive_checked = form.get("is_inactive_checked", "false")
853894
root_path = request.scope.get("root_path", "")
895+
896+
if is_inactive_checked.lower() == "true":
897+
return RedirectResponse(f"{root_path}/admin/?include_inactive=true#gateways", status_code=303)
854898
return RedirectResponse(f"{root_path}/admin#gateways", status_code=303)
855899

856900

@@ -942,6 +986,10 @@ async def admin_edit_resource(
942986
await resource_service.update_resource(db, uri, resource)
943987

944988
root_path = request.scope.get("root_path", "")
989+
is_inactive_checked = form.get("is_inactive_checked", "false")
990+
991+
if is_inactive_checked.lower() == "true":
992+
return RedirectResponse(f"{root_path}/admin/?include_inactive=true#resources", status_code=303)
945993
return RedirectResponse(f"{root_path}/admin#resources", status_code=303)
946994

947995

@@ -967,7 +1015,12 @@ async def admin_delete_resource(uri: str, request: Request, db: Session = Depend
9671015
logger.debug(f"User {user} is deleting resource URI {uri}")
9681016
await resource_service.delete_resource(db, uri)
9691017

1018+
form = await request.form()
1019+
is_inactive_checked = form.get("is_inactive_checked", "false")
9701020
root_path = request.scope.get("root_path", "")
1021+
1022+
if is_inactive_checked.lower() == "true":
1023+
return RedirectResponse(f"{root_path}/admin/?include_inactive=true#resources", status_code=303)
9711024
return RedirectResponse(f"{root_path}/admin#resources", status_code=303)
9721025

9731026

@@ -999,12 +1052,15 @@ async def admin_toggle_resource(
9991052
logger.debug(f"User {user} is toggling resource ID {resource_id}")
10001053
form = await request.form()
10011054
activate = form.get("activate", "true").lower() == "true"
1055+
is_inactive_checked = form.get("is_inactive_checked", "false")
10021056
try:
10031057
await resource_service.toggle_resource_status(db, resource_id, activate)
10041058
except Exception as e:
10051059
logger.error(f"Error toggling resource status: {e}")
10061060

10071061
root_path = request.scope.get("root_path", "")
1062+
if is_inactive_checked.lower() == "true":
1063+
return RedirectResponse(f"{root_path}/admin/?include_inactive=true#resources", status_code=303)
10081064
return RedirectResponse(f"{root_path}/admin#resources", status_code=303)
10091065

10101066

@@ -1098,6 +1154,10 @@ async def admin_edit_prompt(
10981154
await prompt_service.update_prompt(db, name, prompt)
10991155

11001156
root_path = request.scope.get("root_path", "")
1157+
is_inactive_checked = form.get("is_inactive_checked", "false")
1158+
1159+
if is_inactive_checked.lower() == "true":
1160+
return RedirectResponse(f"{root_path}/admin/?include_inactive=true#prompts", status_code=303)
11011161
return RedirectResponse(f"{root_path}/admin#prompts", status_code=303)
11021162

11031163

@@ -1123,7 +1183,12 @@ async def admin_delete_prompt(name: str, request: Request, db: Session = Depends
11231183
logger.debug(f"User {user} is deleting prompt name {name}")
11241184
await prompt_service.delete_prompt(db, name)
11251185

1186+
form = await request.form()
1187+
is_inactive_checked = form.get("is_inactive_checked", "false")
11261188
root_path = request.scope.get("root_path", "")
1189+
1190+
if is_inactive_checked.lower() == "true":
1191+
return RedirectResponse(f"{root_path}/admin/?include_inactive=true#prompts", status_code=303)
11271192
return RedirectResponse(f"{root_path}/admin#prompts", status_code=303)
11281193

11291194

@@ -1155,12 +1220,15 @@ async def admin_toggle_prompt(
11551220
logger.debug(f"User {user} is toggling prompt ID {prompt_id}")
11561221
form = await request.form()
11571222
activate = form.get("activate", "true").lower() == "true"
1223+
is_inactive_checked = form.get("is_inactive_checked", "false")
11581224
try:
11591225
await prompt_service.toggle_prompt_status(db, prompt_id, activate)
11601226
except Exception as e:
11611227
logger.error(f"Error toggling prompt status: {e}")
11621228

11631229
root_path = request.scope.get("root_path", "")
1230+
if is_inactive_checked.lower() == "true":
1231+
return RedirectResponse(f"{root_path}/admin/?include_inactive=true#prompts", status_code=303)
11641232
return RedirectResponse(f"{root_path}/admin#prompts", status_code=303)
11651233

11661234

@@ -1210,7 +1278,12 @@ async def admin_delete_root(uri: str, request: Request, user: str = Depends(requ
12101278
logger.debug(f"User {user} is deleting root URI {uri}")
12111279
await root_service.remove_root(uri)
12121280

1281+
form = await request.form()
12131282
root_path = request.scope.get("root_path", "")
1283+
is_inactive_checked = form.get("is_inactive_checked", "false")
1284+
1285+
if is_inactive_checked.lower() == "true":
1286+
return RedirectResponse(f"{root_path}/admin/?include_inactive=true#roots", status_code=303)
12141287
return RedirectResponse(f"{root_path}/admin#roots", status_code=303)
12151288

12161289

0 commit comments

Comments
 (0)