Skip to content

Commit 123f748

Browse files
committed
fix:标注搜索日志权限,追加time log字段(resolve #144)
1 parent 2cfe42a commit 123f748

2 files changed

Lines changed: 48 additions & 3 deletions

File tree

app/api/cms/log.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020

2121

2222
@log_api.route("")
23-
@log_api.route("/search")
2423
@permission_meta(name="查询日志", module="日志")
25-
# @group_required
24+
@group_required
2625
@api.validate(
2726
headers=AuthorizationSchema,
2827
query=LogQuerySearchSchema,
@@ -34,6 +33,36 @@ def get_logs():
3433
"""
3534
日志浏览查询(人员,时间, 关键字),分页展示
3635
"""
36+
logs = Log.query.filter()
37+
total = logs.count()
38+
items = (
39+
logs.order_by(text("create_time desc")).offset(g.offset).limit(g.count).all()
40+
)
41+
total_page = math.ceil(total / g.count)
42+
43+
return LogPageSchema(
44+
page=g.page,
45+
count=g.count,
46+
total=total,
47+
items=get_items_with_time_field(items),
48+
total_page=total_page,
49+
)
50+
51+
52+
@log_api.route("/search")
53+
@permission_meta(name="搜索日志", module="日志")
54+
@group_required
55+
@api.validate(
56+
headers=AuthorizationSchema,
57+
query=LogQuerySearchSchema,
58+
resp=DocResponse(r=LogPageSchema),
59+
before=LogQuerySearchSchema.offset_handler,
60+
tags=["日志"],
61+
)
62+
def search_logs():
63+
"""
64+
日志搜索(人员,时间, 关键字),分页展示
65+
"""
3766
if g.keyword:
3867
logs = Log.query.filter(Log.message.like(f"%{g.keyword}%"))
3968
else:
@@ -50,7 +79,11 @@ def get_logs():
5079
total_page = math.ceil(total / g.count)
5180

5281
return LogPageSchema(
53-
page=g.page, count=g.count, total=total, items=items, total_page=total_page
82+
page=g.page,
83+
count=g.count,
84+
total=total,
85+
items=get_items_with_time_field(items),
86+
total_page=total_page,
5487
)
5588

5689

@@ -74,3 +107,13 @@ def get_users_for_log():
74107
.all()
75108
)
76109
return UsernameListSchema(items=[u.username for u in usernames])
110+
111+
112+
# TODO:临时time字段, 等待lin 核心库中调整后移除
113+
def get_items_with_time_field(items):
114+
new_items = list()
115+
for item in items:
116+
item = dict(item)
117+
item["time"] = item["create_time"]
118+
new_items.append(item)
119+
return new_items

app/validator/schema.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
from datetime import datetime
23
from enum import Enum
34
from typing import Any, List, Optional
45

@@ -49,6 +50,7 @@ class LogSchema(BaseModel):
4950
method: str
5051
path: str
5152
permission: str
53+
time: datetime
5254

5355

5456
class BasePageSchema(BaseModel):

0 commit comments

Comments
 (0)