-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpatch_main_pool.py
More file actions
66 lines (59 loc) · 2.23 KB
/
Copy pathpatch_main_pool.py
File metadata and controls
66 lines (59 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import re
with open("backend/app/main.py", "r") as f:
content = f.read()
# Replace read_tenant_settings
old_read = """@app.get("/api/settings", response_model=dict)
async def read_tenant_settings(
account: CurrentAccount,
conn: asyncpg.Connection = Depends(get_db),
):
row = await conn.fetchrow("SELECT brand_name FROM tenant_settings WHERE id = 1")
if not row:
return {"brandName": "LineageWeave"}
return {"brandName": row["brand_name"]}"""
new_read = """@app.get("/api/settings", response_model=dict)
async def read_tenant_settings(
account: CurrentAccount = Depends(get_current_account),
pool: asyncpg.Pool = Depends(get_pool),
):
async with pool.acquire() as conn:
row = await conn.fetchrow("SELECT brand_name FROM tenant_settings WHERE id = 1")
if not row:
return {"brandName": "LineageWeave"}
return {"brandName": row["brand_name"]}"""
# Replace update_tenant_settings
old_update = """@app.patch("/api/settings", response_model=dict)
async def update_tenant_settings(
payload: dict,
account: CurrentAccount,
conn: asyncpg.Connection = Depends(get_db),
):
# Only admins can change settings
_require_post_admin(account)
brand_name = payload.get("brandName", "LineageWeave")
await conn.execute(
"INSERT INTO tenant_settings (id, brand_name) VALUES (1, $1) "
"ON CONFLICT (id) DO UPDATE SET brand_name = $1",
brand_name
)
return {"brandName": brand_name}"""
new_update = """@app.patch("/api/settings", response_model=dict)
async def update_tenant_settings(
payload: dict,
account: CurrentAccount = Depends(get_current_account),
pool: asyncpg.Pool = Depends(get_pool),
):
# Only admins can change settings
_require_post_admin(account)
brand_name = payload.get("brandName", "LineageWeave")
async with pool.acquire() as conn:
await conn.execute(
"INSERT INTO tenant_settings (id, brand_name) VALUES (1, $1) "
"ON CONFLICT (id) DO UPDATE SET brand_name = $1",
brand_name
)
return {"brandName": brand_name}"""
content = content.replace(old_read, new_read)
content = content.replace(old_update, new_update)
with open("backend/app/main.py", "w") as f:
f.write(content)