Skip to content

Commit c316a65

Browse files
committed
doc production环境随机变更url
1 parent d514694 commit c316a65

5 files changed

Lines changed: 33 additions & 14 deletions

File tree

app/api/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,22 @@
22
:copyright: © 2020 by the Lin team.
33
:license: MIT, see LICENSE for more details.
44
"""
5+
import os
6+
from uuid import uuid4
7+
8+
from lin import SpecTree
9+
10+
if os.getenv("FLASK_ENV", "production") == "production":
11+
# spectree 暂未提供关闭文档功能,production部署变更随机路径
12+
lindoc = SpecTree(
13+
backend_name="flask",
14+
title="Lin-CMS API",
15+
mode="strict",
16+
path="/".join(str(uuid4()).split("-")),
17+
)
18+
else:
19+
lindoc = SpecTree(
20+
backend_name="flask",
21+
title="Lin-CMS API",
22+
mode="strict",
23+
)

app/api/cms/log.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import math
22

33
from flask import g
4-
from lin import DocResponse, lindoc, permission_meta
4+
from lin import DocResponse, permission_meta
55
from lin.db import db
66
from lin.jwt import group_required
77
from lin.logger import Log
88
from lin.redprint import Redprint
99
from sqlalchemy import text
1010

11+
from app.api import lindoc
1112
from app.validator.schema import (
1213
AuthorizationSchema,
1314
LogListSchema,
@@ -65,13 +66,11 @@ def get_users_for_log():
6566
"""
6667
获取所有记录行为日志的用户名
6768
"""
68-
usernames_dict = db.query(
69-
"""
70-
SELECT l.username
71-
FROM lin_log l
72-
WHERE l.delete_time IS NULL
73-
GROUP BY l.username
74-
HAVING COUNT(l.username) > 0
75-
"""
76-
).as_dict()
77-
return NameListSchema(items=[ud.get("username") for ud in usernames_dict])
69+
usernames = (
70+
db.session.query(Log.username)
71+
.filter_by(soft=False)
72+
.group_by(text("username"))
73+
.having(text("count(username) > 0"))
74+
.all()
75+
)
76+
return NameListSchema(items=[u.username for u in usernames])

app/api/v1/book.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
"""
77

88
from flask import g, request
9-
from lin import DocResponse, lindoc, permission_meta
9+
from lin import DocResponse, permission_meta
1010
from lin.exception import Success
1111
from lin.jwt import group_required, login_required
1212
from lin.redprint import Redprint
1313

14+
from app.api import lindoc
1415
from app.exception.api import BookNotFound
1516
from app.model.v1.book import Book
1617
from app.validator.schema import (

app/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def register_blueprints(app):
1616

1717

1818
def register_lindoc(app):
19-
from lin import lindoc
19+
from app.api import lindoc
2020

2121
lindoc.register(app)
2222

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Lin-CMS==0.3.0a5
1+
Lin-CMS==0.3.0a5
22
Flask-Cors==3.0.9
33
python-dotenv==0.15.0
44
oss2==2.13.1

0 commit comments

Comments
 (0)