优化curd函数在view的引入方式,优化权限与日志的装饰器
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
from markupsafe import escape, Markup
|
||||
|
||||
from applications.models import db
|
||||
from applications.models.admin_dept import Dept, DeptSchema
|
||||
from applications.models.admin_user import User
|
||||
@@ -18,9 +16,7 @@ def save_dept(req):
|
||||
email = req.get("email")
|
||||
leader = req.get("leader")
|
||||
parentId = req.get("parentId")
|
||||
parentName = req.get("parentName")
|
||||
phone = req.get("phone")
|
||||
selectParent_select_input = req.get("selectParent_select_input")
|
||||
sort = req.get("sort")
|
||||
status = req.get("status")
|
||||
dept = Dept(
|
||||
@@ -50,7 +46,6 @@ def enable_status(id):
|
||||
if d:
|
||||
db.session.commit()
|
||||
return True
|
||||
print('0')
|
||||
return False
|
||||
|
||||
|
||||
@@ -66,7 +61,7 @@ def disable_status(id):
|
||||
|
||||
def update_dept(json):
|
||||
id = json.get("deptId"),
|
||||
print(str(Markup(json.get("leader"))))
|
||||
print(json.get("leader"))
|
||||
data = {
|
||||
"dept_name": json.get("deptName"),
|
||||
"sort": json.get("sort"),
|
||||
@@ -4,12 +4,12 @@
|
||||
|
||||
from applications.models import db
|
||||
from applications.models.admin_dict import DictType, DictData, DictTypeSchema, DictDataSchema
|
||||
from applications.service.common.curd import model_to_dicts
|
||||
|
||||
|
||||
# 通过type_code获取字典dict
|
||||
# 例:get_dict('user_sex')
|
||||
# [{'key': '男', 'value': 'boy'}, {'key': '女', 'value': 'girl'}]
|
||||
from applications.service.common.curd import model_to_dicts
|
||||
|
||||
|
||||
def get_dict(typecode: str):
|
||||
@@ -32,7 +32,7 @@ def get_dict_type(page, limit, type_name):
|
||||
per_page=limit,
|
||||
error_out=False)
|
||||
count = DictType.query.count()
|
||||
data = model_to_dicts(Schema=DictTypeSchema,model=dict_all.items)
|
||||
data = model_to_dicts(Schema=DictTypeSchema, model=dict_all.items)
|
||||
return data, count
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ def get_dict_data(page, limit, type_code):
|
||||
per_page=limit,
|
||||
error_out=False)
|
||||
count = DictType.query.count()
|
||||
dict_dict = model_to_dicts(Schema=DictDataSchema,model=dict_all.items)
|
||||
dict_dict = model_to_dicts(Schema=DictDataSchema, model=dict_all.items)
|
||||
return dict_dict, count
|
||||
|
||||
|
||||
@@ -4,35 +4,20 @@ from flask_login import login_required
|
||||
from applications.service.admin_log import admin_log
|
||||
|
||||
|
||||
def authorize(power: str):
|
||||
def authorize(power: str, log: bool = False):
|
||||
def decorator(func):
|
||||
@login_required
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
if not power in session.get('permissions'):
|
||||
if log:
|
||||
admin_log(request=request, is_access=False)
|
||||
if request.method == 'GET':
|
||||
abort(403)
|
||||
else:
|
||||
return jsonify(success=False, msg="权限不足!")
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
def authorize_and_log(power: str):
|
||||
def decorator(func):
|
||||
@login_required
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
if not power in session['permissions']:
|
||||
admin_log(request=request, is_access=False)
|
||||
if request.method == 'GET':
|
||||
abort(403)
|
||||
else:
|
||||
return jsonify(success=False, msg="权限不足!")
|
||||
admin_log(request=request, is_access=True)
|
||||
if log:
|
||||
admin_log(request=request, is_access=True)
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
Reference in New Issue
Block a user