Skip to content

Commit fd5529d

Browse files
committed
refactor:permissionMeta参数重命名 close #128
1 parent 58e2577 commit fd5529d

9 files changed

Lines changed: 47 additions & 40 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<p align="center">
1313
<a href="http://flask.pocoo.org/docs/1.0/" rel="nofollow">
1414
<img src="https://img.shields.io/badge/flask-1.1.2-green.svg" alt="flask version" data-canonical-src="https://img.shields.io/badge/flask-1.1.2-green.svg" style="max-width:100%;"></a>
15-
<a href="https://pypi.org/project/Lin-CMS/" rel="nofollow"><img src="https://img.shields.io/badge/lin--cms-0.3.0a6-orange.svg" alt="lin--cms version" data-canonical-src="https://img.shields.io/badge/lin--cms-0.3.0a6-orange.svge" style="max-width:100%;"></a>
15+
<a href="https://pypi.org/project/Lin-CMS/" rel="nofollow"><img src="https://img.shields.io/badge/lin--cms-0.3.0a7-orange.svg" alt="lin--cms version" data-canonical-src="https://img.shields.io/badge/lin--cms-0.3.0a7-orange.svge" style="max-width:100%;"></a>
1616
<a href="https://doc.cms.talelin.com/" rel="nofollow"><img src="https://img.shields.io/badge/license-MIT-lightgrey.svg" alt="LISENCE" data-canonical-src="https://img.shields.io/badge/license-MIT-lightgrey.svg" style="max-width:100%;"></a>
1717
</p>
1818

@@ -35,9 +35,9 @@ Lin-CMS 是林间有风团队经过大量项目实践所提炼出的一套**内
3535

3636
### 当前最新版本
3737

38-
lin-cms-flask(当前示例工程):0.3.0a6
38+
lin-cms-flask(当前示例工程):0.3.0a7
3939

40-
lin-cms(核心库) :0.3.0a6
40+
lin-cms(核心库) :0.3.0a7
4141

4242
### 文档地址
4343

app/api/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
backend_name="flask",
1414
title="Lin-CMS API",
1515
mode="strict",
16-
version="0.3.0a6",
16+
version="0.3.0a7",
1717
path="/".join(str(uuid4()).split("-")),
1818
)
1919
else:
2020
api = SpecTree(
2121
backend_name="flask",
2222
title="Lin-CMS API",
2323
mode="strict",
24-
version="0.3.0a6",
24+
version="0.3.0a7",
2525
)

app/api/cms/admin.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131

3232

3333
@admin_api.route("/permission", methods=["GET"])
34-
@permission_meta(auth="查询所有可分配的权限", module="管理员", mount=False)
34+
@permission_meta(name="查询所有可分配的权限", module="管理员", mount=False)
3535
@admin_required
36-
def authority():
36+
def permissions():
3737
return get_ep_infos()
3838

3939

4040
@admin_api.route("/users", methods=["GET"])
41-
@permission_meta(auth="查询所有用户", module="管理员", mount=False)
41+
@permission_meta(name="查询所有用户", module="管理员", mount=False)
4242
@admin_required
4343
def get_admin_users():
4444
start, count = paginate()
@@ -116,7 +116,7 @@ def get_admin_users():
116116

117117

118118
@admin_api.route("/user/<int:uid>/password", methods=["PUT"])
119-
@permission_meta(auth="修改用户密码", module="管理员", mount=False)
119+
@permission_meta(name="修改用户密码", module="管理员", mount=False)
120120
@admin_required
121121
def change_user_password(uid):
122122
form = ResetPasswordForm().validate_for_api()
@@ -132,7 +132,7 @@ def change_user_password(uid):
132132

133133

134134
@admin_api.route("/user/<int:uid>", methods=["DELETE"])
135-
@permission_meta(auth="删除用户", module="管理员", mount=False)
135+
@permission_meta(name="删除用户", module="管理员", mount=False)
136136
@Logger(template="管理员删除了一个用户")
137137
@admin_required
138138
def delete_user(uid):
@@ -152,7 +152,7 @@ def delete_user(uid):
152152

153153

154154
@admin_api.route("/user/<int:uid>", methods=["PUT"])
155-
@permission_meta(auth="管理员更新用户信息", module="管理员", mount=False)
155+
@permission_meta(name="管理员更新用户信息", module="管理员", mount=False)
156156
@admin_required
157157
def update_user(uid):
158158
form = UpdateUserInfoForm().validate_for_api()
@@ -186,7 +186,7 @@ def update_user(uid):
186186

187187

188188
@admin_api.route("/group", methods=["GET"])
189-
@permission_meta(auth="查询所有分组及其权限", module="管理员", mount=False)
189+
@permission_meta(name="查询所有分组及其权限", module="管理员", mount=False)
190190
@admin_required
191191
def get_admin_groups():
192192
start, count = paginate()
@@ -228,7 +228,7 @@ def get_admin_groups():
228228

229229

230230
@admin_api.route("/group/all", methods=["GET"])
231-
@permission_meta(auth="查询所有分组", module="管理员", mount=False)
231+
@permission_meta(name="查询所有分组", module="管理员", mount=False)
232232
@admin_required
233233
def get_all_group():
234234
groups = manager.group_model.query.filter(
@@ -241,7 +241,7 @@ def get_all_group():
241241

242242

243243
@admin_api.route("/group/<int:gid>", methods=["GET"])
244-
@permission_meta(auth="查询一个分组及其权限", module="管理员", mount=False)
244+
@permission_meta(name="查询一个分组及其权限", module="管理员", mount=False)
245245
@admin_required
246246
def get_group(gid):
247247
group = manager.group_model.get(id=gid, one=True, soft=False)
@@ -254,7 +254,7 @@ def get_group(gid):
254254

255255

256256
@admin_api.route("/group", methods=["POST"])
257-
@permission_meta(auth="新建分组", module="管理员", mount=False)
257+
@permission_meta(name="新建分组", module="管理员", mount=False)
258258
@Logger(template="管理员新建了一个分组") # 记录日志
259259
@admin_required
260260
def create_group():
@@ -279,7 +279,7 @@ def create_group():
279279

280280

281281
@admin_api.route("/group/<int:gid>", methods=["PUT"])
282-
@permission_meta(auth="更新一个分组", module="管理员", mount=False)
282+
@permission_meta(name="更新一个分组", module="管理员", mount=False)
283283
@admin_required
284284
def update_group(gid):
285285
form = UpdateGroup().validate_for_api()
@@ -291,7 +291,7 @@ def update_group(gid):
291291

292292

293293
@admin_api.route("/group/<int:gid>", methods=["DELETE"])
294-
@permission_meta(auth="删除一个分组", module="管理员", mount=False)
294+
@permission_meta(name="删除一个分组", module="管理员", mount=False)
295295
@Logger(template="管理员删除一个分组") # 记录日志
296296
@admin_required
297297
def delete_group(gid):
@@ -315,7 +315,7 @@ def delete_group(gid):
315315

316316

317317
@admin_api.route("/permission/dispatch", methods=["POST"])
318-
@permission_meta(auth="分配单个权限", module="管理员", mount=False)
318+
@permission_meta(name="分配单个权限", module="管理员", mount=False)
319319
@admin_required
320320
def dispatch_auth():
321321
form = DispatchAuth().validate_for_api()
@@ -331,7 +331,7 @@ def dispatch_auth():
331331

332332

333333
@admin_api.route("/permission/dispatch/batch", methods=["POST"])
334-
@permission_meta(auth="分配多个权限", module="管理员", mount=False)
334+
@permission_meta(name="分配多个权限", module="管理员", mount=False)
335335
@admin_required
336336
def dispatch_auths():
337337
form = DispatchAuths().validate_for_api()
@@ -349,7 +349,7 @@ def dispatch_auths():
349349

350350

351351
@admin_api.route("/permission/remove", methods=["POST"])
352-
@permission_meta(auth="删除多个权限", module="管理员", mount=False)
352+
@permission_meta(name="删除多个权限", module="管理员", mount=False)
353353
@admin_required
354354
def remove_auths():
355355
form = RemoveAuths().validate_for_api()

app/api/cms/log.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
@log_api.route("")
2323
@log_api.route("/search")
24-
@permission_meta(auth="查询日志", module="日志")
24+
@permission_meta(name="查询日志", module="日志")
2525
@group_required
2626
@api.validate(
2727
headers=AuthorizationSchema,
@@ -55,7 +55,7 @@ def get_logs():
5555

5656

5757
@log_api.route("/users", methods=["GET"])
58-
@permission_meta(auth="查询日志记录的用户", module="日志")
58+
@permission_meta(name="查询日志记录的用户", module="日志")
5959
@group_required
6060
@api.validate(
6161
headers=AuthorizationSchema,

app/api/cms/user.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434

3535
@user_api.route("/register", methods=["POST"])
36-
@permission_meta(auth="注册", module="用户", mount=False)
36+
@permission_meta(name="注册", module="用户", mount=False)
3737
@Logger(template="管理员新建了一个用户") # 记录日志
3838
@admin_required
3939
def register():
@@ -48,7 +48,7 @@ def register():
4848

4949

5050
@user_api.route("/login", methods=["POST"])
51-
@permission_meta(auth="登录", module="用户", mount=False)
51+
@permission_meta(name="登录", module="用户", mount=False)
5252
def login():
5353
form = LoginForm().validate_for_api()
5454
user = manager.user_model.verify(form.username.data, form.password.data)
@@ -68,7 +68,7 @@ def login():
6868

6969

7070
@user_api.route("", methods=["PUT"])
71-
@permission_meta(auth="用户更新信息", module="用户", mount=False)
71+
@permission_meta(name="用户更新信息", module="用户", mount=False)
7272
@login_required
7373
def update():
7474
form = UpdateInfoForm().validate_for_api()
@@ -92,7 +92,7 @@ def update():
9292

9393

9494
@user_api.route("/change_password", methods=["PUT"])
95-
@permission_meta(auth="修改密码", module="用户", mount=False)
95+
@permission_meta(name="修改密码", module="用户", mount=False)
9696
@Logger(template="{user.username}修改了自己的密码") # 记录日志
9797
@login_required
9898
def change_password():
@@ -107,15 +107,15 @@ def change_password():
107107

108108

109109
@user_api.route("/information", methods=["GET"])
110-
@permission_meta(auth="查询自己信息", module="用户", mount=False)
110+
@permission_meta(name="查询自己信息", module="用户", mount=False)
111111
@login_required
112112
def get_information():
113113
current_user = get_current_user()
114114
return current_user
115115

116116

117117
@user_api.route("/refresh", methods=["GET"])
118-
@permission_meta(auth="刷新令牌", module="用户", mount=False)
118+
@permission_meta(name="刷新令牌", module="用户", mount=False)
119119
def refresh():
120120
try:
121121
verify_jwt_refresh_token_in_request()
@@ -132,7 +132,7 @@ def refresh():
132132

133133

134134
@user_api.route("/permissions", methods=["GET"])
135-
@permission_meta(auth="查询自己拥有的权限", module="用户", mount=False)
135+
@permission_meta(name="查询自己拥有的权限", module="用户", mount=False)
136136
@login_required
137137
def get_allowed_apis():
138138
user = get_current_user()

app/api/v1/book.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818
AuthorizationSchema,
1919
BookSchemaList,
2020
BookQuerySearchSchema,
21-
BookSchema,
21+
BookInSchema,
22+
BookOutSchema,
2223
)
2324

2425
book_api = Redprint("book")
2526

2627

2728
@book_api.route("/<int:id>", methods=["GET"])
2829
@api.validate(
29-
resp=DocResponse(BookNotFound, r=BookSchema),
30+
resp=DocResponse(BookNotFound, r=BookOutSchema),
3031
tags=["图书"],
3132
)
3233
def get_book(id: int):
@@ -35,7 +36,7 @@ def get_book(id: int):
3536
"""
3637
book = Book.get(id=id)
3738
if book:
38-
return BookSchema.parse_obj(book)
39+
return BookOutSchema.parse_obj(book)
3940
raise BookNotFound
4041

4142

@@ -74,7 +75,7 @@ def search():
7475
@login_required
7576
@api.validate(
7677
headers=AuthorizationSchema,
77-
json=BookSchema,
78+
json=BookInSchema,
7879
resp=DocResponse(Success(12)),
7980
tags=["图书"],
8081
)
@@ -91,7 +92,7 @@ def create_book():
9192
@login_required
9293
@api.validate(
9394
headers=AuthorizationSchema,
94-
json=BookSchema,
95+
json=BookInSchema,
9596
resp=DocResponse(Success(13)),
9697
tags=["图书"],
9798
)
@@ -100,7 +101,7 @@ def update_book(id: int):
100101
更新图书信息
101102
"""
102103
book_schema = request.context.json
103-
book = Book.query.filter_by(id=id, delete_time=None).first()
104+
book = Book.get(id=id)
104105
if book:
105106
book.update(
106107
id=id,
@@ -112,7 +113,7 @@ def update_book(id: int):
112113

113114

114115
@book_api.route("/<int:id>", methods=["DELETE"])
115-
@permission_meta(auth="删除图书", module="图书")
116+
@permission_meta(name="删除图书", module="图书")
116117
@group_required
117118
@api.validate(
118119
headers=AuthorizationSchema,

app/validator/schema.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,21 @@ class LogPageSchema(BasePageSchema):
6565
items: List[LogSchema]
6666

6767

68-
class BookSchema(BaseModel):
68+
class BookInSchema(BaseModel):
6969
title: str
7070
author: str
7171
image: str
7272
summary: str
7373

74+
class BookOutSchema(BaseModel):
75+
id: int
76+
title: str
77+
author: str
78+
image: str
79+
summary: str
7480

7581
class BookSchemaList(BaseModel):
76-
__root__: List[BookSchema]
82+
__root__: List[BookOutSchema]
7783

7884

7985
class Language(str, Enum):

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.0a6
1+
Lin-CMS==0.3.0a7
22
Flask-Cors==3.0.9
33
python-dotenv==0.15.0
44
oss2==2.13.1

requirements-prod.txt

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

0 commit comments

Comments
 (0)