优化curd函数在view的引入方式,优化权限与日志的装饰器
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
from markupsafe import escape, Markup
|
|
||||||
|
|
||||||
from applications.models import db
|
from applications.models import db
|
||||||
from applications.models.admin_dept import Dept, DeptSchema
|
from applications.models.admin_dept import Dept, DeptSchema
|
||||||
from applications.models.admin_user import User
|
from applications.models.admin_user import User
|
||||||
@@ -18,9 +16,7 @@ def save_dept(req):
|
|||||||
email = req.get("email")
|
email = req.get("email")
|
||||||
leader = req.get("leader")
|
leader = req.get("leader")
|
||||||
parentId = req.get("parentId")
|
parentId = req.get("parentId")
|
||||||
parentName = req.get("parentName")
|
|
||||||
phone = req.get("phone")
|
phone = req.get("phone")
|
||||||
selectParent_select_input = req.get("selectParent_select_input")
|
|
||||||
sort = req.get("sort")
|
sort = req.get("sort")
|
||||||
status = req.get("status")
|
status = req.get("status")
|
||||||
dept = Dept(
|
dept = Dept(
|
||||||
@@ -50,7 +46,6 @@ def enable_status(id):
|
|||||||
if d:
|
if d:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return True
|
return True
|
||||||
print('0')
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@@ -66,7 +61,7 @@ def disable_status(id):
|
|||||||
|
|
||||||
def update_dept(json):
|
def update_dept(json):
|
||||||
id = json.get("deptId"),
|
id = json.get("deptId"),
|
||||||
print(str(Markup(json.get("leader"))))
|
print(json.get("leader"))
|
||||||
data = {
|
data = {
|
||||||
"dept_name": json.get("deptName"),
|
"dept_name": json.get("deptName"),
|
||||||
"sort": json.get("sort"),
|
"sort": json.get("sort"),
|
||||||
@@ -4,12 +4,12 @@
|
|||||||
|
|
||||||
from applications.models import db
|
from applications.models import db
|
||||||
from applications.models.admin_dict import DictType, DictData, DictTypeSchema, DictDataSchema
|
from applications.models.admin_dict import DictType, DictData, DictTypeSchema, DictDataSchema
|
||||||
|
from applications.service.common.curd import model_to_dicts
|
||||||
|
|
||||||
|
|
||||||
# 通过type_code获取字典dict
|
# 通过type_code获取字典dict
|
||||||
# 例:get_dict('user_sex')
|
# 例:get_dict('user_sex')
|
||||||
# [{'key': '男', 'value': 'boy'}, {'key': '女', 'value': 'girl'}]
|
# [{'key': '男', 'value': 'boy'}, {'key': '女', 'value': 'girl'}]
|
||||||
from applications.service.common.curd import model_to_dicts
|
|
||||||
|
|
||||||
|
|
||||||
def get_dict(typecode: str):
|
def get_dict(typecode: str):
|
||||||
@@ -4,34 +4,19 @@ from flask_login import login_required
|
|||||||
from applications.service.admin_log import admin_log
|
from applications.service.admin_log import admin_log
|
||||||
|
|
||||||
|
|
||||||
def authorize(power: str):
|
def authorize(power: str, log: bool = False):
|
||||||
def decorator(func):
|
def decorator(func):
|
||||||
@login_required
|
@login_required
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
if not power in session.get('permissions'):
|
if not power in session.get('permissions'):
|
||||||
if request.method == 'GET':
|
if log:
|
||||||
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)
|
admin_log(request=request, is_access=False)
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
abort(403)
|
abort(403)
|
||||||
else:
|
else:
|
||||||
return jsonify(success=False, msg="权限不足!")
|
return jsonify(success=False, msg="权限不足!")
|
||||||
|
if log:
|
||||||
admin_log(request=request, is_access=True)
|
admin_log(request=request, is_access=True)
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,4 @@ from flask import session
|
|||||||
def init_template_global(app):
|
def init_template_global(app):
|
||||||
@app.template_global()
|
@app.template_global()
|
||||||
def authorize(power):
|
def authorize(power):
|
||||||
# print(power)
|
|
||||||
# print(session.get('permissions'))
|
|
||||||
return bool(power in session.get('permissions'))
|
return bool(power in session.get('permissions'))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
from flask import Blueprint, render_template, request, jsonify
|
from flask import Blueprint, render_template, request, jsonify
|
||||||
from applications.service.admin import dept as dept_curd
|
from applications.service.admin import dept_curd as dept_curd
|
||||||
from applications.service.common.response import table_api, success_api, fail_api
|
from applications.service.common.response import success_api, fail_api
|
||||||
from applications.service.route_auth import authorize_and_log, authorize
|
from applications.service.route_auth import authorize
|
||||||
|
|
||||||
admin_dept = Blueprint('adminDept', __name__, url_prefix='/admin/dept')
|
admin_dept = Blueprint('adminDept', __name__, url_prefix='/admin/dept')
|
||||||
|
|
||||||
|
|
||||||
@admin_dept.route('/')
|
@admin_dept.route('/')
|
||||||
@authorize_and_log("admin:dept:main")
|
@authorize("admin:dept:main", log=True)
|
||||||
def main():
|
def main():
|
||||||
return render_template('admin/dept/main.html')
|
return render_template('admin/dept/main.html')
|
||||||
|
|
||||||
|
|
||||||
@admin_dept.route('/data')
|
@admin_dept.route('/data')
|
||||||
@authorize_and_log("admin:dept:main")
|
@authorize("admin:dept:main", log=True)
|
||||||
def data():
|
def data():
|
||||||
power_data = dept_curd.get_dept_dict()
|
power_data = dept_curd.get_dept_dict()
|
||||||
res = {
|
res = {
|
||||||
@@ -23,13 +23,13 @@ def data():
|
|||||||
|
|
||||||
|
|
||||||
@admin_dept.route('/add')
|
@admin_dept.route('/add')
|
||||||
@authorize_and_log("admin:dept:add")
|
@authorize("admin:dept:add", log=True)
|
||||||
def add():
|
def add():
|
||||||
return render_template('admin/dept/add.html')
|
return render_template('admin/dept/add.html')
|
||||||
|
|
||||||
|
|
||||||
@admin_dept.route('/tree')
|
@admin_dept.route('/tree')
|
||||||
@authorize_and_log("admin:dept:main")
|
@authorize("admin:dept:main", log=True)
|
||||||
def tree():
|
def tree():
|
||||||
power_data = dept_curd.get_dept_dict()
|
power_data = dept_curd.get_dept_dict()
|
||||||
res = {
|
res = {
|
||||||
@@ -41,7 +41,7 @@ def tree():
|
|||||||
|
|
||||||
|
|
||||||
@admin_dept.route('/save', methods=['POST'])
|
@admin_dept.route('/save', methods=['POST'])
|
||||||
@authorize_and_log("admin:dept:edit")
|
@authorize("admin:dept:edit", log=True)
|
||||||
def save():
|
def save():
|
||||||
req = request.json
|
req = request.json
|
||||||
dept_curd.save_dept(req)
|
dept_curd.save_dept(req)
|
||||||
@@ -49,7 +49,7 @@ def save():
|
|||||||
|
|
||||||
|
|
||||||
@admin_dept.route('/edit', methods=['GET', 'POST'])
|
@admin_dept.route('/edit', methods=['GET', 'POST'])
|
||||||
@authorize_and_log("admin:dept:edit")
|
@authorize("admin:dept:edit", log=True)
|
||||||
def edit():
|
def edit():
|
||||||
id = request.args.get("deptId")
|
id = request.args.get("deptId")
|
||||||
dept = dept_curd.get_dept_by_id(id)
|
dept = dept_curd.get_dept_by_id(id)
|
||||||
@@ -58,7 +58,7 @@ def edit():
|
|||||||
|
|
||||||
# 启用
|
# 启用
|
||||||
@admin_dept.route('/enable', methods=['PUT'])
|
@admin_dept.route('/enable', methods=['PUT'])
|
||||||
@authorize_and_log("admin:dept:edit")
|
@authorize("admin:dept:edit", log=True)
|
||||||
def enable():
|
def enable():
|
||||||
id = request.json.get('deptId')
|
id = request.json.get('deptId')
|
||||||
if id:
|
if id:
|
||||||
@@ -71,7 +71,7 @@ def enable():
|
|||||||
|
|
||||||
# 禁用
|
# 禁用
|
||||||
@admin_dept.route('/disable', methods=['PUT'])
|
@admin_dept.route('/disable', methods=['PUT'])
|
||||||
@authorize_and_log("admin:dept:edit")
|
@authorize("admin:dept:edit", log=True)
|
||||||
def disenable():
|
def disenable():
|
||||||
id = request.json.get('deptId')
|
id = request.json.get('deptId')
|
||||||
if id:
|
if id:
|
||||||
@@ -83,7 +83,7 @@ def disenable():
|
|||||||
|
|
||||||
|
|
||||||
@admin_dept.route('/update', methods=['PUT'])
|
@admin_dept.route('/update', methods=['PUT'])
|
||||||
@authorize_and_log("admin:dept:edit")
|
@authorize("admin:dept:edit", log=True)
|
||||||
def update():
|
def update():
|
||||||
res = dept_curd.update_dept(request.json)
|
res = dept_curd.update_dept(request.json)
|
||||||
if not res:
|
if not res:
|
||||||
@@ -92,7 +92,7 @@ def update():
|
|||||||
|
|
||||||
|
|
||||||
@admin_dept.route('/remove/<int:id>', methods=['DELETE'])
|
@admin_dept.route('/remove/<int:id>', methods=['DELETE'])
|
||||||
@authorize_and_log("admin:dept:remove")
|
@authorize("admin:dept:remove", log=True)
|
||||||
def remove(id):
|
def remove(id):
|
||||||
res = dept_curd.remove_dept(id)
|
res = dept_curd.remove_dept(id)
|
||||||
if res:
|
if res:
|
||||||
|
|||||||
@@ -1,43 +1,40 @@
|
|||||||
from flask import Blueprint, render_template, request, jsonify
|
from flask import Blueprint, render_template, request, jsonify
|
||||||
|
|
||||||
from applications.models.admin_dict import DictType, DictData
|
from applications.models.admin_dict import DictType, DictData
|
||||||
from applications.service.admin.dict import get_dict_type, get_dict_data, save_dict_type, save_dict_data, \
|
from applications.service.admin import dict_curd
|
||||||
delete_type_by_id, delete_data_by_id, update_dict_type, enable_dict_type_status, disable_dict_type_status, \
|
|
||||||
enable_dict_data_status, disable_dict_data_status, update_dict_data
|
|
||||||
from applications.service.common.response import table_api, success_api, fail_api
|
from applications.service.common.response import table_api, success_api, fail_api
|
||||||
from applications.service.route_auth import authorize_and_log
|
from applications.service.route_auth import authorize
|
||||||
|
|
||||||
admin_dict = Blueprint('adminDict', __name__, url_prefix='/admin/dict')
|
admin_dict = Blueprint('adminDict', __name__, url_prefix='/admin/dict')
|
||||||
|
|
||||||
|
|
||||||
# 数据字典
|
# 数据字典
|
||||||
@admin_dict.route('/')
|
@admin_dict.route('/')
|
||||||
@authorize_and_log("admin:dict:main")
|
@authorize("admin:dict:main", log=True)
|
||||||
def main():
|
def main():
|
||||||
return render_template('admin/dict/main.html')
|
return render_template('admin/dict/main.html')
|
||||||
|
|
||||||
|
|
||||||
@admin_dict.route('/dictType/data')
|
@admin_dict.route('/dictType/data')
|
||||||
@authorize_and_log("admin:dict:main")
|
@authorize("admin:dict:main", log=True)
|
||||||
def dictType_data():
|
def dictType_data():
|
||||||
page = request.args.get('page', type=int)
|
page = request.args.get('page', type=int)
|
||||||
limit = request.args.get('limit', type=int)
|
limit = request.args.get('limit', type=int)
|
||||||
type_name = request.args.get('typeName', type=str)
|
type_name = request.args.get('typeName', type=str)
|
||||||
data, count = get_dict_type(page=page, limit=limit, type_name=type_name)
|
data, count = dict_curd.get_dict_type(page=page, limit=limit, type_name=type_name)
|
||||||
return table_api(data=data,count=count)
|
return table_api(data=data,count=count)
|
||||||
|
|
||||||
|
|
||||||
@admin_dict.route('/dictType/add')
|
@admin_dict.route('/dictType/add')
|
||||||
@authorize_and_log("admin:dict:add")
|
@authorize("admin:dict:add", log=True)
|
||||||
def dictType_add():
|
def dictType_add():
|
||||||
return render_template('admin/dict/add.html')
|
return render_template('admin/dict/add.html')
|
||||||
|
|
||||||
|
|
||||||
@admin_dict.route('/dictType/save', methods=['POST'])
|
@admin_dict.route('/dictType/save', methods=['POST'])
|
||||||
@authorize_and_log("admin:dict:add")
|
@authorize("admin:dict:add", log=True)
|
||||||
def dictType_save():
|
def dictType_save():
|
||||||
req_json = request.json
|
req_json = request.json
|
||||||
res = save_dict_type(req_json=req_json)
|
res = dict_curd.save_dict_type(req_json=req_json)
|
||||||
if res == None:
|
if res == None:
|
||||||
return fail_api(msg="增加失败")
|
return fail_api(msg="增加失败")
|
||||||
return success_api(msg="增加成功")
|
return success_api(msg="增加成功")
|
||||||
@@ -45,7 +42,7 @@ def dictType_save():
|
|||||||
|
|
||||||
# 编辑字典类型
|
# 编辑字典类型
|
||||||
@admin_dict.route('/dictType/edit', methods=['GET', 'POST'])
|
@admin_dict.route('/dictType/edit', methods=['GET', 'POST'])
|
||||||
@authorize_and_log("admin:dict:edit")
|
@authorize("admin:dict:edit", log=True)
|
||||||
def dictType_edit():
|
def dictType_edit():
|
||||||
id = request.args.get('dictTypeId', type=str)
|
id = request.args.get('dictTypeId', type=str)
|
||||||
dict_type = DictType.query.filter_by(id=id).first()
|
dict_type = DictType.query.filter_by(id=id).first()
|
||||||
@@ -54,20 +51,20 @@ def dictType_edit():
|
|||||||
|
|
||||||
# 编辑字典类型
|
# 编辑字典类型
|
||||||
@admin_dict.route('/dictType/update', methods=['PUT'])
|
@admin_dict.route('/dictType/update', methods=['PUT'])
|
||||||
@authorize_and_log("admin:dict:edit")
|
@authorize("admin:dict:edit", log=True)
|
||||||
def dictType_update():
|
def dictType_update():
|
||||||
req_json = request.json
|
req_json = request.json
|
||||||
update_dict_type(req_json)
|
dict_curd.update_dict_type(req_json)
|
||||||
return success_api(msg="更新成功")
|
return success_api(msg="更新成功")
|
||||||
|
|
||||||
|
|
||||||
# 启用字典
|
# 启用字典
|
||||||
@admin_dict.route('/dictType/enable', methods=['PUT'])
|
@admin_dict.route('/dictType/enable', methods=['PUT'])
|
||||||
@authorize_and_log("admin:dict:edit")
|
@authorize("admin:dict:edit", log=True)
|
||||||
def dictType_enable():
|
def dictType_enable():
|
||||||
id = request.json.get('id')
|
id = request.json.get('id')
|
||||||
if id:
|
if id:
|
||||||
res = enable_dict_type_status(id)
|
res = dict_curd.enable_dict_type_status(id)
|
||||||
if not res:
|
if not res:
|
||||||
return fail_api(msg="出错啦")
|
return fail_api(msg="出错啦")
|
||||||
return success_api("启动成功")
|
return success_api("启动成功")
|
||||||
@@ -76,11 +73,11 @@ def dictType_enable():
|
|||||||
|
|
||||||
# 禁用字典
|
# 禁用字典
|
||||||
@admin_dict.route('/dictType/disable', methods=['PUT'])
|
@admin_dict.route('/dictType/disable', methods=['PUT'])
|
||||||
@authorize_and_log("admin:dict:edit")
|
@authorize("admin:dict:edit", log=True)
|
||||||
def dictType_disenable():
|
def dictType_disenable():
|
||||||
id = request.json.get('id')
|
id = request.json.get('id')
|
||||||
if id:
|
if id:
|
||||||
res = disable_dict_type_status(id)
|
res = dict_curd.disable_dict_type_status(id)
|
||||||
if not res:
|
if not res:
|
||||||
return fail_api(msg="出错啦")
|
return fail_api(msg="出错啦")
|
||||||
return success_api("禁用成功")
|
return success_api("禁用成功")
|
||||||
@@ -89,27 +86,27 @@ def dictType_disenable():
|
|||||||
|
|
||||||
# 删除字典类型
|
# 删除字典类型
|
||||||
@admin_dict.route('/dictType/remove/<int:id>', methods=['DELETE'])
|
@admin_dict.route('/dictType/remove/<int:id>', methods=['DELETE'])
|
||||||
@authorize_and_log("admin:dict:remove")
|
@authorize("admin:dict:remove", log=True)
|
||||||
def dictType_delete(id):
|
def dictType_delete(id):
|
||||||
res = delete_type_by_id(id)
|
res = dict_curd.delete_type_by_id(id)
|
||||||
if not res:
|
if not res:
|
||||||
return fail_api(msg="删除失败")
|
return fail_api(msg="删除失败")
|
||||||
return success_api(msg="删除成功")
|
return success_api(msg="删除成功")
|
||||||
|
|
||||||
|
|
||||||
@admin_dict.route('/dictData/data')
|
@admin_dict.route('/dictData/data')
|
||||||
@authorize_and_log("admin:dict:main")
|
@authorize("admin:dict:main", log=True)
|
||||||
def dictCode_data():
|
def dictCode_data():
|
||||||
page = request.args.get('page', type=int)
|
page = request.args.get('page', type=int)
|
||||||
limit = request.args.get('limit', type=int)
|
limit = request.args.get('limit', type=int)
|
||||||
type_code = request.args.get('typeCode', type=str)
|
type_code = request.args.get('typeCode', type=str)
|
||||||
data, count = get_dict_data(page=page, limit=limit, type_code=type_code)
|
data, count = dict_curd.get_dict_data(page=page, limit=limit, type_code=type_code)
|
||||||
return table_api(data=data,count=count)
|
return table_api(data=data,count=count)
|
||||||
|
|
||||||
|
|
||||||
# 增加字典数据
|
# 增加字典数据
|
||||||
@admin_dict.route('/dictData/add')
|
@admin_dict.route('/dictData/add')
|
||||||
@authorize_and_log("admin:dict:add")
|
@authorize("admin:dict:add", log=True)
|
||||||
def dictData_add():
|
def dictData_add():
|
||||||
type_code = request.args.get('typeCode', type=str)
|
type_code = request.args.get('typeCode', type=str)
|
||||||
return render_template('admin/dict/data/add.html', type_code=type_code)
|
return render_template('admin/dict/data/add.html', type_code=type_code)
|
||||||
@@ -117,7 +114,7 @@ def dictData_add():
|
|||||||
|
|
||||||
# 增加字典数据
|
# 增加字典数据
|
||||||
@admin_dict.route('/dictData/save', methods=['POST'])
|
@admin_dict.route('/dictData/save', methods=['POST'])
|
||||||
@authorize_and_log("admin:dict:add")
|
@authorize("admin:dict:add", log=True)
|
||||||
def dictData_save():
|
def dictData_save():
|
||||||
req_json = request.json
|
req_json = request.json
|
||||||
res = save_dict_data(req_json=req_json)
|
res = save_dict_data(req_json=req_json)
|
||||||
@@ -128,7 +125,7 @@ def dictData_save():
|
|||||||
|
|
||||||
# 编辑字典数据
|
# 编辑字典数据
|
||||||
@admin_dict.route('/dictData/edit', methods=['GET', 'POST'])
|
@admin_dict.route('/dictData/edit', methods=['GET', 'POST'])
|
||||||
@authorize_and_log("admin:dict:edit")
|
@authorize("admin:dict:edit", log=True)
|
||||||
def dictData_edit():
|
def dictData_edit():
|
||||||
id = request.args.get('dataId', type=str)
|
id = request.args.get('dataId', type=str)
|
||||||
dict_data = DictData.query.filter_by(id=id).first()
|
dict_data = DictData.query.filter_by(id=id).first()
|
||||||
@@ -137,7 +134,7 @@ def dictData_edit():
|
|||||||
|
|
||||||
# 编辑字典数据
|
# 编辑字典数据
|
||||||
@admin_dict.route('/dictData/update', methods=['PUT'])
|
@admin_dict.route('/dictData/update', methods=['PUT'])
|
||||||
@authorize_and_log("admin:dict:edit")
|
@authorize("admin:dict:edit", log=True)
|
||||||
def dictData_update():
|
def dictData_update():
|
||||||
req_json = request.json
|
req_json = request.json
|
||||||
update_dict_data(req_json)
|
update_dict_data(req_json)
|
||||||
@@ -146,7 +143,7 @@ def dictData_update():
|
|||||||
|
|
||||||
# 启用字典数据
|
# 启用字典数据
|
||||||
@admin_dict.route('/dictData/enable', methods=['PUT'])
|
@admin_dict.route('/dictData/enable', methods=['PUT'])
|
||||||
@authorize_and_log("admin:dict:edit")
|
@authorize("admin:dict:edit", log=True)
|
||||||
def dictData_enable():
|
def dictData_enable():
|
||||||
id = request.json.get('dataId')
|
id = request.json.get('dataId')
|
||||||
if id:
|
if id:
|
||||||
@@ -159,7 +156,7 @@ def dictData_enable():
|
|||||||
|
|
||||||
# 禁用字典数据
|
# 禁用字典数据
|
||||||
@admin_dict.route('/dictData/disable', methods=['PUT'])
|
@admin_dict.route('/dictData/disable', methods=['PUT'])
|
||||||
@authorize_and_log("admin:dict:edit")
|
@authorize("admin:dict:edit", log=True)
|
||||||
def dictData_disenable():
|
def dictData_disenable():
|
||||||
id = request.json.get('dataId')
|
id = request.json.get('dataId')
|
||||||
if id:
|
if id:
|
||||||
@@ -172,7 +169,7 @@ def dictData_disenable():
|
|||||||
|
|
||||||
# 删除字典类型
|
# 删除字典类型
|
||||||
@admin_dict.route('dictData/remove/<int:id>', methods=['DELETE'])
|
@admin_dict.route('dictData/remove/<int:id>', methods=['DELETE'])
|
||||||
@authorize_and_log("admin:dict:remove")
|
@authorize("admin:dict:remove", log=True)
|
||||||
def dictData_delete(id):
|
def dictData_delete(id):
|
||||||
res = delete_data_by_id(id)
|
res = delete_data_by_id(id)
|
||||||
if not res:
|
if not res:
|
||||||
|
|||||||
@@ -2,38 +2,37 @@ import os
|
|||||||
from flask import Blueprint, request, render_template, jsonify, current_app
|
from flask import Blueprint, request, render_template, jsonify, current_app
|
||||||
from applications.models import db
|
from applications.models import db
|
||||||
from applications.models.admin_photo import Photo
|
from applications.models.admin_photo import Photo
|
||||||
from applications.service.admin.file import get_photo, upload_one, delete_photo_by_id
|
from applications.service.admin import file_curd
|
||||||
from applications.service.common.response import table_api, success_api, fail_api
|
from applications.service.common.response import table_api, success_api, fail_api
|
||||||
from applications.service.route_auth import authorize_and_log
|
from applications.service.route_auth import authorize
|
||||||
|
|
||||||
admin_file = Blueprint('adminFile', __name__, url_prefix='/admin/file')
|
admin_file = Blueprint('adminFile', __name__, url_prefix='/admin/file')
|
||||||
|
|
||||||
|
|
||||||
# 图片管理
|
# 图片管理
|
||||||
@admin_file.route('/')
|
@admin_file.route('/')
|
||||||
@authorize_and_log("admin:file:main")
|
@authorize("admin:file:main", log=True)
|
||||||
def index():
|
def index():
|
||||||
return render_template('admin/photo/photo.html')
|
return render_template('admin/photo/photo.html')
|
||||||
|
|
||||||
|
|
||||||
# 图片数据
|
# 图片数据
|
||||||
@admin_file.route('/table')
|
@admin_file.route('/table')
|
||||||
@authorize_and_log("admin:file:main")
|
@authorize("admin:file:main", log=True)
|
||||||
def table():
|
def table():
|
||||||
page = request.args.get('page', type=int)
|
page = request.args.get('page', type=int)
|
||||||
limit = request.args.get('limit', type=int)
|
limit = request.args.get('limit', type=int)
|
||||||
data, count = get_photo(page=page, limit=limit)
|
data, count = file_curd.get_photo(page=page, limit=limit)
|
||||||
return table_api(data=data, count=count)
|
return table_api(data=data, count=count)
|
||||||
|
|
||||||
|
|
||||||
# 上传接口
|
# 上传接口
|
||||||
@admin_file.route('/upload', methods=['GET', 'POST'])
|
@admin_file.route('/upload', methods=['GET', 'POST'])
|
||||||
@authorize_and_log("admin:file:add")
|
@authorize("admin:file:add", log=True)
|
||||||
def upload():
|
def upload():
|
||||||
if request.method == 'POST' and 'file' in request.files:
|
if request.method == 'POST' and 'file' in request.files:
|
||||||
photo = request.files['file']
|
photo = request.files['file']
|
||||||
mime = request.files['file'].content_type
|
mime = request.files['file'].content_type
|
||||||
file_url = upload_one(photo=photo, mime=mime)
|
file_url = file_curd.upload_one(photo=photo, mime=mime)
|
||||||
res = {
|
res = {
|
||||||
"msg": "上传成功",
|
"msg": "上传成功",
|
||||||
"code": 0,
|
"code": 0,
|
||||||
@@ -48,10 +47,10 @@ def upload():
|
|||||||
|
|
||||||
# 图片删除
|
# 图片删除
|
||||||
@admin_file.route('/delete', methods=['GET', 'POST'])
|
@admin_file.route('/delete', methods=['GET', 'POST'])
|
||||||
@authorize_and_log("admin:file:delete")
|
@authorize("admin:file:delete", log=True)
|
||||||
def delete():
|
def delete():
|
||||||
id = request.form.get('id')
|
id = request.form.get('id')
|
||||||
res = delete_photo_by_id(id)
|
res = file_curd.delete_photo_by_id(id)
|
||||||
if res:
|
if res:
|
||||||
return success_api(msg="删除成功")
|
return success_api(msg="删除成功")
|
||||||
else:
|
else:
|
||||||
@@ -60,7 +59,7 @@ def delete():
|
|||||||
|
|
||||||
# 图片批量删除
|
# 图片批量删除
|
||||||
@admin_file.route('/batchRemove', methods=['GET', 'POST'])
|
@admin_file.route('/batchRemove', methods=['GET', 'POST'])
|
||||||
@authorize_and_log("admin:file:delete")
|
@authorize("admin:file:delete", log=True)
|
||||||
def batchRemove():
|
def batchRemove():
|
||||||
ids = request.form.getlist('ids[]')
|
ids = request.form.getlist('ids[]')
|
||||||
photo_name = Photo.query.filter(Photo.id.in_(ids)).all()
|
photo_name = Photo.query.filter(Photo.id.in_(ids)).all()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from flask import Blueprint, render_template, jsonify, request, session, redirect, url_for
|
from flask import Blueprint, render_template, jsonify, request, session, redirect, url_for
|
||||||
from flask_login import login_user, login_required, logout_user, current_user
|
from flask_login import login_user, login_required, logout_user, current_user
|
||||||
from applications.service.admin.index import add_auth_session, make_menu_tree, get_captcha
|
from applications.service.admin import index_curd
|
||||||
from applications.service.admin_log import login_log
|
from applications.service.admin_log import login_log
|
||||||
from applications.models.admin_user import User
|
from applications.models.admin_user import User
|
||||||
from applications.service.common.response import fail_api, success_api
|
from applications.service.common.response import fail_api, success_api
|
||||||
@@ -19,7 +19,7 @@ def index():
|
|||||||
# 获取验证码
|
# 获取验证码
|
||||||
@admin_index.route('/getCaptcha', methods=["GET"])
|
@admin_index.route('/getCaptcha', methods=["GET"])
|
||||||
def getCaptcha():
|
def getCaptcha():
|
||||||
resp,code=get_captcha()
|
resp, code = index_curd.get_captcha()
|
||||||
session["code"] = code
|
session["code"] = code
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ def login():
|
|||||||
# 记录登录日志
|
# 记录登录日志
|
||||||
login_log(request, uid=user.id, is_access=True)
|
login_log(request, uid=user.id, is_access=True)
|
||||||
# 存入权限
|
# 存入权限
|
||||||
add_auth_session()
|
index_curd.add_auth_session()
|
||||||
return success_api(msg="登录成功")
|
return success_api(msg="登录成功")
|
||||||
login_log(request, uid=user.id, is_access=False)
|
login_log(request, uid=user.id, is_access=False)
|
||||||
return fail_api(msg="用户名或密码错误")
|
return fail_api(msg="用户名或密码错误")
|
||||||
@@ -78,7 +78,7 @@ def logout():
|
|||||||
@admin_index.route('/menu')
|
@admin_index.route('/menu')
|
||||||
@login_required
|
@login_required
|
||||||
def menu():
|
def menu():
|
||||||
menu_tree = make_menu_tree()
|
menu_tree = index_curd.make_menu_tree()
|
||||||
return jsonify(menu_tree)
|
return jsonify(menu_tree)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import psutil
|
|||||||
from flask import Blueprint, render_template, jsonify
|
from flask import Blueprint, render_template, jsonify
|
||||||
from flask_marshmallow import Marshmallow
|
from flask_marshmallow import Marshmallow
|
||||||
|
|
||||||
from applications.service.route_auth import authorize_and_log, authorize
|
from applications.service.route_auth import authorize
|
||||||
|
|
||||||
ma = Marshmallow()
|
ma = Marshmallow()
|
||||||
admin_Monitor = Blueprint('adminMonitor', __name__, url_prefix='/admin/monitor')
|
admin_Monitor = Blueprint('adminMonitor', __name__, url_prefix='/admin/monitor')
|
||||||
@@ -15,7 +15,7 @@ admin_Monitor = Blueprint('adminMonitor', __name__, url_prefix='/admin/monitor')
|
|||||||
|
|
||||||
# 系统监控
|
# 系统监控
|
||||||
@admin_Monitor.route('/')
|
@admin_Monitor.route('/')
|
||||||
@authorize_and_log("admin:monitor:main")
|
@authorize("admin:monitor:main", log=True)
|
||||||
def main():
|
def main():
|
||||||
# 主机名称
|
# 主机名称
|
||||||
hostname = platform.node()
|
hostname = platform.node()
|
||||||
|
|||||||
@@ -1,22 +1,21 @@
|
|||||||
from flask import Blueprint, render_template, request, jsonify
|
from flask import Blueprint, render_template, request, jsonify
|
||||||
from applications.service.admin.power import get_power_dict, select_parent, save_power, remove_power, get_power_by_id, \
|
from applications.service.admin import power_curd
|
||||||
update_power, enable_status, disable_status, batch_remove
|
|
||||||
from applications.service.common.response import success_api, fail_api
|
from applications.service.common.response import success_api, fail_api
|
||||||
from applications.service.route_auth import authorize_and_log
|
from applications.service.route_auth import authorize
|
||||||
|
|
||||||
admin_power = Blueprint('adminPower', __name__, url_prefix='/admin/power')
|
admin_power = Blueprint('adminPower', __name__, url_prefix='/admin/power')
|
||||||
|
|
||||||
|
|
||||||
@admin_power.route('/')
|
@admin_power.route('/')
|
||||||
@authorize_and_log("admin:power:main")
|
@authorize("admin:power:main", log=True)
|
||||||
def index():
|
def index():
|
||||||
return render_template('admin/power/main.html')
|
return render_template('admin/power/main.html')
|
||||||
|
|
||||||
|
|
||||||
@admin_power.route('/data')
|
@admin_power.route('/data')
|
||||||
@authorize_and_log("admin:power:main")
|
@authorize("admin:power:main", log=True)
|
||||||
def data():
|
def data():
|
||||||
power_data = get_power_dict()
|
power_data = power_curd.get_power_dict()
|
||||||
res = {
|
res = {
|
||||||
"data": power_data
|
"data": power_data
|
||||||
}
|
}
|
||||||
@@ -24,15 +23,15 @@ def data():
|
|||||||
|
|
||||||
|
|
||||||
@admin_power.route('/add')
|
@admin_power.route('/add')
|
||||||
@authorize_and_log("admin:power:add")
|
@authorize("admin:power:add", log=True)
|
||||||
def add():
|
def add():
|
||||||
return render_template('admin/power/add.html')
|
return render_template('admin/power/add.html')
|
||||||
|
|
||||||
|
|
||||||
@admin_power.route('/selectParent')
|
@admin_power.route('/selectParent')
|
||||||
@authorize_and_log("admin:power:main")
|
@authorize("admin:power:main", log=True)
|
||||||
def selectParent():
|
def selectParent():
|
||||||
power_data = select_parent()
|
power_data = power_curd.select_parent()
|
||||||
res = {
|
res = {
|
||||||
"status": {"code": 200, "message": "默认"},
|
"status": {"code": 200, "message": "默认"},
|
||||||
"data": power_data
|
"data": power_data
|
||||||
@@ -43,18 +42,18 @@ def selectParent():
|
|||||||
|
|
||||||
# 增加
|
# 增加
|
||||||
@admin_power.route('/save', methods=['POST'])
|
@admin_power.route('/save', methods=['POST'])
|
||||||
@authorize_and_log("admin:power:add")
|
@authorize("admin:power:add", log=True)
|
||||||
def save():
|
def save():
|
||||||
req = request.json
|
req = request.json
|
||||||
save_power(req)
|
power_curd.save_power(req)
|
||||||
return success_api(msg="成功")
|
return success_api(msg="成功")
|
||||||
|
|
||||||
|
|
||||||
# 权限编辑
|
# 权限编辑
|
||||||
@admin_power.route('/edit/<int:id>', methods=['GET', 'POST'])
|
@admin_power.route('/edit/<int:id>', methods=['GET', 'POST'])
|
||||||
@authorize_and_log("admin:power:edit")
|
@authorize("admin:power:edit", log=True)
|
||||||
def edit(id):
|
def edit(id):
|
||||||
power = get_power_by_id(id)
|
power = power_curd.get_power_by_id(id)
|
||||||
icon = str(power.icon).split()
|
icon = str(power.icon).split()
|
||||||
if len(icon) == 2:
|
if len(icon) == 2:
|
||||||
icon = icon[1]
|
icon = icon[1]
|
||||||
@@ -65,9 +64,9 @@ def edit(id):
|
|||||||
|
|
||||||
# 权限更新
|
# 权限更新
|
||||||
@admin_power.route('/update', methods=['PUT'])
|
@admin_power.route('/update', methods=['PUT'])
|
||||||
@authorize_and_log("admin:power:edit")
|
@authorize("admin:power:edit", log=True)
|
||||||
def update():
|
def update():
|
||||||
res = update_power(request.json)
|
res = power_curd.update_power(request.json)
|
||||||
if not res:
|
if not res:
|
||||||
return fail_api(msg="更新权限失败")
|
return fail_api(msg="更新权限失败")
|
||||||
return success_api(msg="更新权限成功")
|
return success_api(msg="更新权限成功")
|
||||||
@@ -75,12 +74,11 @@ def update():
|
|||||||
|
|
||||||
# 启用权限
|
# 启用权限
|
||||||
@admin_power.route('/enable', methods=['PUT'])
|
@admin_power.route('/enable', methods=['PUT'])
|
||||||
@authorize_and_log("admin:power:edit")
|
@authorize("admin:power:edit", log=True)
|
||||||
def enable():
|
def enable():
|
||||||
id = request.json.get('powerId')
|
id = request.json.get('powerId')
|
||||||
print(id)
|
|
||||||
if id:
|
if id:
|
||||||
res = enable_status(id)
|
res = power_curd.enable_status(id)
|
||||||
if not res:
|
if not res:
|
||||||
return fail_api(msg="出错啦")
|
return fail_api(msg="出错啦")
|
||||||
return success_api(msg="启用成功")
|
return success_api(msg="启用成功")
|
||||||
@@ -89,12 +87,11 @@ def enable():
|
|||||||
|
|
||||||
# 禁用权限
|
# 禁用权限
|
||||||
@admin_power.route('/disable', methods=['PUT'])
|
@admin_power.route('/disable', methods=['PUT'])
|
||||||
@authorize_and_log("admin:power:edit")
|
@authorize("admin:power:edit", log=True)
|
||||||
def disenable():
|
def disenable():
|
||||||
id = request.json.get('powerId')
|
id = request.json.get('powerId')
|
||||||
print(id)
|
|
||||||
if id:
|
if id:
|
||||||
res = disable_status(id)
|
res = power_curd.disable_status(id)
|
||||||
if not res:
|
if not res:
|
||||||
return fail_api(msg="出错啦")
|
return fail_api(msg="出错啦")
|
||||||
return success_api(msg="禁用成功")
|
return success_api(msg="禁用成功")
|
||||||
@@ -103,9 +100,9 @@ def disenable():
|
|||||||
|
|
||||||
# 权限删除
|
# 权限删除
|
||||||
@admin_power.route('/remove/<int:id>', methods=['DELETE'])
|
@admin_power.route('/remove/<int:id>', methods=['DELETE'])
|
||||||
@authorize_and_log("admin:power:remove")
|
@authorize("admin:power:remove", log=True)
|
||||||
def remove(id):
|
def remove(id):
|
||||||
r = remove_power(id)
|
r = power_curd.remove_power(id)
|
||||||
if r:
|
if r:
|
||||||
return success_api(msg="删除成功")
|
return success_api(msg="删除成功")
|
||||||
else:
|
else:
|
||||||
@@ -114,8 +111,8 @@ def remove(id):
|
|||||||
|
|
||||||
# 批量删除
|
# 批量删除
|
||||||
@admin_power.route('/batchRemove', methods=['DELETE'])
|
@admin_power.route('/batchRemove', methods=['DELETE'])
|
||||||
@authorize_and_log("admin:power:remove")
|
@authorize("admin:power:remove", log=True)
|
||||||
def batchRemove():
|
def batchRemove():
|
||||||
ids = request.form.getlist('ids[]')
|
ids = request.form.getlist('ids[]')
|
||||||
batch_remove(ids)
|
power_curd.batch_remove(ids)
|
||||||
return success_api(msg="批量删除成功")
|
return success_api(msg="批量删除成功")
|
||||||
|
|||||||
@@ -1,24 +1,22 @@
|
|||||||
from flask import Blueprint, render_template, request, jsonify
|
from flask import Blueprint, render_template, request, jsonify
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
|
from applications.service.admin import role_curd
|
||||||
from applications.service.admin.role import get_role_data_dict, add_role, get_role_power, update_role_power, \
|
|
||||||
get_role_by_id, update_role, remove_role, batch_remove, enable_status, disable_status
|
|
||||||
from applications.service.common.response import table_api, success_api, fail_api
|
from applications.service.common.response import table_api, success_api, fail_api
|
||||||
from applications.service.route_auth import authorize_and_log
|
from applications.service.route_auth import authorize
|
||||||
|
|
||||||
admin_role = Blueprint('adminRole', __name__, url_prefix='/admin/role')
|
admin_role = Blueprint('adminRole', __name__, url_prefix='/admin/role')
|
||||||
|
|
||||||
|
|
||||||
# 用户管理
|
# 用户管理
|
||||||
@admin_role.route('/')
|
@admin_role.route('/')
|
||||||
@authorize_and_log("admin:role:main")
|
@authorize("admin:role:main", log=True)
|
||||||
def main():
|
def main():
|
||||||
return render_template('admin/role/main.html')
|
return render_template('admin/role/main.html')
|
||||||
|
|
||||||
|
|
||||||
# 表格数据
|
# 表格数据
|
||||||
@admin_role.route('/data')
|
@admin_role.route('/data')
|
||||||
@authorize_and_log("admin:role:main")
|
@authorize("admin:role:main", log=True)
|
||||||
def table():
|
def table():
|
||||||
page = request.args.get('page', type=int)
|
page = request.args.get('page', type=int)
|
||||||
limit = request.args.get('limit', type=int)
|
limit = request.args.get('limit', type=int)
|
||||||
@@ -29,13 +27,13 @@ def table():
|
|||||||
filters["name"] = ('%' + roleName + '%')
|
filters["name"] = ('%' + roleName + '%')
|
||||||
if roleCode:
|
if roleCode:
|
||||||
filters["code"] = ('%' + roleCode + '%')
|
filters["code"] = ('%' + roleCode + '%')
|
||||||
data, count = get_role_data_dict(page=page, limit=limit, filters=filters)
|
data, count = role_curd.get_role_data_dict(page=page, limit=limit, filters=filters)
|
||||||
return table_api(data=data, count=count)
|
return table_api(data=data, count=count)
|
||||||
|
|
||||||
|
|
||||||
# 角色增加
|
# 角色增加
|
||||||
@admin_role.route('/add')
|
@admin_role.route('/add')
|
||||||
@authorize_and_log("admin:role:add")
|
@authorize("admin:role:add", log=True)
|
||||||
@login_required
|
@login_required
|
||||||
def add():
|
def add():
|
||||||
return render_template('admin/role/add.html')
|
return render_template('admin/role/add.html')
|
||||||
@@ -43,25 +41,25 @@ def add():
|
|||||||
|
|
||||||
# 角色增加
|
# 角色增加
|
||||||
@admin_role.route('/save', methods=['POST'])
|
@admin_role.route('/save', methods=['POST'])
|
||||||
@authorize_and_log("admin:role:add")
|
@authorize("admin:role:add", log=True)
|
||||||
def save():
|
def save():
|
||||||
req = request.json
|
req = request.json
|
||||||
add_role(req=req)
|
role_curd.add_role(req=req)
|
||||||
return success_api(msg="成功")
|
return success_api(msg="成功")
|
||||||
|
|
||||||
|
|
||||||
# 角色授权
|
# 角色授权
|
||||||
@admin_role.route('/power/<int:id>')
|
@admin_role.route('/power/<int:id>')
|
||||||
@authorize_and_log("admin:role:power")
|
@authorize("admin:role:power", log=True)
|
||||||
def power(id):
|
def power(id):
|
||||||
return render_template('admin/role/power.html', id=id)
|
return render_template('admin/role/power.html', id=id)
|
||||||
|
|
||||||
|
|
||||||
# 获取角色权限
|
# 获取角色权限
|
||||||
@admin_role.route('/getRolePower/<int:id>')
|
@admin_role.route('/getRolePower/<int:id>')
|
||||||
@authorize_and_log("admin:role:main")
|
@authorize("admin:role:main", log=True)
|
||||||
def getRolePower(id):
|
def getRolePower(id):
|
||||||
powers = get_role_power(id)
|
powers = role_curd.get_role_power(id)
|
||||||
res = {
|
res = {
|
||||||
"data": powers,
|
"data": powers,
|
||||||
"status": {"code": 200, "message": "默认"}
|
"status": {"code": 200, "message": "默认"}
|
||||||
@@ -71,29 +69,29 @@ def getRolePower(id):
|
|||||||
|
|
||||||
# 保存角色权限
|
# 保存角色权限
|
||||||
@admin_role.route('/saveRolePower', methods=['PUT'])
|
@admin_role.route('/saveRolePower', methods=['PUT'])
|
||||||
@authorize_and_log("admin:role:edit")
|
@authorize("admin:role:edit", log=True)
|
||||||
def saveRolePower():
|
def saveRolePower():
|
||||||
req_form = request.form
|
req_form = request.form
|
||||||
powerIds = req_form.get("powerIds")
|
powerIds = req_form.get("powerIds")
|
||||||
power_list = powerIds.split(',')
|
power_list = powerIds.split(',')
|
||||||
roleId = req_form.get("roleId")
|
roleId = req_form.get("roleId")
|
||||||
update_role_power(id=roleId, power_list=power_list)
|
role_curd.update_role_power(id=roleId, power_list=power_list)
|
||||||
return success_api(msg="授权成功")
|
return success_api(msg="授权成功")
|
||||||
|
|
||||||
|
|
||||||
# 角色编辑
|
# 角色编辑
|
||||||
@admin_role.route('/edit/<int:id>', methods=['GET', 'POST'])
|
@admin_role.route('/edit/<int:id>', methods=['GET', 'POST'])
|
||||||
@authorize_and_log("admin:role:edit")
|
@authorize("admin:role:edit", log=True)
|
||||||
def edit(id):
|
def edit(id):
|
||||||
role = get_role_by_id(id)
|
role = role_curd.get_role_by_id(id)
|
||||||
return render_template('admin/role/edit.html', role=role)
|
return render_template('admin/role/edit.html', role=role)
|
||||||
|
|
||||||
|
|
||||||
# 更新角色
|
# 更新角色
|
||||||
@admin_role.route('/update', methods=['PUT'])
|
@admin_role.route('/update', methods=['PUT'])
|
||||||
@authorize_and_log("admin:role:edit")
|
@authorize("admin:role:edit", log=True)
|
||||||
def update():
|
def update():
|
||||||
res = update_role(request.json)
|
res = role_curd.update_role(request.json)
|
||||||
if not res:
|
if not res:
|
||||||
return fail_api(msg="更新角色失败")
|
return fail_api(msg="更新角色失败")
|
||||||
return success_api(msg="更新角色成功")
|
return success_api(msg="更新角色成功")
|
||||||
@@ -101,12 +99,12 @@ def update():
|
|||||||
|
|
||||||
# 启用用户
|
# 启用用户
|
||||||
@admin_role.route('/enable', methods=['PUT'])
|
@admin_role.route('/enable', methods=['PUT'])
|
||||||
@authorize_and_log("admin:role:edit")
|
@authorize("admin:role:edit", log=True)
|
||||||
def enable():
|
def enable():
|
||||||
id = request.json.get('roleId')
|
id = request.json.get('roleId')
|
||||||
print(id)
|
print(id)
|
||||||
if id:
|
if id:
|
||||||
res = enable_status(id)
|
res = role_curd.enable_status(id)
|
||||||
if not res:
|
if not res:
|
||||||
return fail_api(msg="出错啦")
|
return fail_api(msg="出错啦")
|
||||||
return success_api(msg="启动成功")
|
return success_api(msg="启动成功")
|
||||||
@@ -115,11 +113,11 @@ def enable():
|
|||||||
|
|
||||||
# 禁用用户
|
# 禁用用户
|
||||||
@admin_role.route('/disable', methods=['PUT'])
|
@admin_role.route('/disable', methods=['PUT'])
|
||||||
@authorize_and_log("admin:role:edit")
|
@authorize("admin:role:edit", log=True)
|
||||||
def disenable():
|
def disenable():
|
||||||
id = request.json.get('roleId')
|
id = request.json.get('roleId')
|
||||||
if id:
|
if id:
|
||||||
res = disable_status(id)
|
res = role_curd.disable_status(id)
|
||||||
if not res:
|
if not res:
|
||||||
return fail_api(msg="出错啦")
|
return fail_api(msg="出错啦")
|
||||||
return success_api(msg="禁用成功")
|
return success_api(msg="禁用成功")
|
||||||
@@ -128,9 +126,9 @@ def disenable():
|
|||||||
|
|
||||||
# 角色删除
|
# 角色删除
|
||||||
@admin_role.route('/remove/<int:id>', methods=['DELETE'])
|
@admin_role.route('/remove/<int:id>', methods=['DELETE'])
|
||||||
@authorize_and_log("admin:role:remove")
|
@authorize("admin:role:remove", log=True)
|
||||||
def remove(id):
|
def remove(id):
|
||||||
res = remove_role(id)
|
res = role_curd.remove_role(id)
|
||||||
if not res:
|
if not res:
|
||||||
return fail_api(msg="角色删除失败")
|
return fail_api(msg="角色删除失败")
|
||||||
return success_api(msg="角色删除成功")
|
return success_api(msg="角色删除成功")
|
||||||
@@ -138,9 +136,9 @@ def remove(id):
|
|||||||
|
|
||||||
# 批量删除
|
# 批量删除
|
||||||
@admin_role.route('/batchRemove', methods=['DELETE'])
|
@admin_role.route('/batchRemove', methods=['DELETE'])
|
||||||
@authorize_and_log("admin:role:remove")
|
@authorize("admin:role:remove", log=True)
|
||||||
@login_required
|
@login_required
|
||||||
def batchRemove():
|
def batchRemove():
|
||||||
ids = request.form.getlist('ids[]')
|
ids = request.form.getlist('ids[]')
|
||||||
batch_remove(ids)
|
role_curd.batch_remove(ids)
|
||||||
return success_api(msg="批量删除成功")
|
return success_api(msg="批量删除成功")
|
||||||
|
|||||||
@@ -1,26 +1,24 @@
|
|||||||
from flask import Blueprint, render_template, request, jsonify
|
from flask import Blueprint, render_template, request
|
||||||
from flask_login import login_required, current_user
|
from flask_login import login_required, current_user
|
||||||
from applications.models.admin_user import User
|
from applications.models.admin_user import User
|
||||||
from applications.models.admin_role import Role
|
from applications.models.admin_role import Role
|
||||||
from applications.service.admin.user import get_user_data_dict, add_user, delete_by_id, \
|
from applications.service.admin import user_curd
|
||||||
batch_remove, update_user, update_user_role, is_user_exists, add_user_role, enable_status, disable_status, \
|
|
||||||
edit_password, get_current_user_logs, update_current_user_info, update_avatar
|
|
||||||
from applications.service.common.response import table_api, fail_api, success_api
|
from applications.service.common.response import table_api, fail_api, success_api
|
||||||
from applications.service.route_auth import authorize_and_log
|
from applications.service.route_auth import authorize
|
||||||
|
|
||||||
admin_user = Blueprint('adminUser', __name__, url_prefix='/admin/user')
|
admin_user = Blueprint('adminUser', __name__, url_prefix='/admin/user')
|
||||||
|
|
||||||
|
|
||||||
# 用户管理
|
# 用户管理
|
||||||
@admin_user.route('/')
|
@admin_user.route('/')
|
||||||
@authorize_and_log("admin:user:main")
|
@authorize("admin:user:main", log=True)
|
||||||
def main():
|
def main():
|
||||||
return render_template('admin/user/main.html')
|
return render_template('admin/user/main.html')
|
||||||
|
|
||||||
|
|
||||||
# 用户分页查询
|
# 用户分页查询
|
||||||
@admin_user.route('/data')
|
@admin_user.route('/data')
|
||||||
@authorize_and_log("admin:user:main")
|
@authorize("admin:user:main", log=True)
|
||||||
def data():
|
def data():
|
||||||
page = request.args.get('page', type=int)
|
page = request.args.get('page', type=int)
|
||||||
limit = request.args.get('limit', type=int)
|
limit = request.args.get('limit', type=int)
|
||||||
@@ -32,20 +30,20 @@ def data():
|
|||||||
filters["realname"] = ('%' + realName + '%')
|
filters["realname"] = ('%' + realName + '%')
|
||||||
if username:
|
if username:
|
||||||
filters["username"] = ('%' + username + '%')
|
filters["username"] = ('%' + username + '%')
|
||||||
user_data, count = get_user_data_dict(page=page, limit=limit, filters=filters,deptId=deptId)
|
user_data, count = user_curd.get_user_data_dict(page=page, limit=limit, filters=filters,deptId=deptId)
|
||||||
return table_api(data=user_data, count=count)
|
return table_api(data=user_data, count=count)
|
||||||
|
|
||||||
|
|
||||||
# 用户增加
|
# 用户增加
|
||||||
@admin_user.route('/add')
|
@admin_user.route('/add')
|
||||||
@authorize_and_log("admin:user:add")
|
@authorize("admin:user:add",log=True)
|
||||||
def add():
|
def add():
|
||||||
roles = Role.query.all()
|
roles = Role.query.all()
|
||||||
return render_template('admin/user/add.html', roles=roles)
|
return render_template('admin/user/add.html', roles=roles)
|
||||||
|
|
||||||
|
|
||||||
@admin_user.route('/save', methods=['POST'])
|
@admin_user.route('/save', methods=['POST'])
|
||||||
@authorize_and_log("admin:user:add")
|
@authorize("admin:user:add", log=True)
|
||||||
def save():
|
def save():
|
||||||
req_json = request.json
|
req_json = request.json
|
||||||
a = req_json.get("roleIds")
|
a = req_json.get("roleIds")
|
||||||
@@ -57,20 +55,20 @@ def save():
|
|||||||
if not username or not realName or not password:
|
if not username or not realName or not password:
|
||||||
return fail_api(msg="账号姓名密码不得为空")
|
return fail_api(msg="账号姓名密码不得为空")
|
||||||
|
|
||||||
if is_user_exists(username):
|
if user_curd.is_user_exists(username):
|
||||||
return fail_api(msg="用户已经存在")
|
return fail_api(msg="用户已经存在")
|
||||||
|
|
||||||
id = add_user(username, realName, password)
|
id = user_curd.add_user(username, realName, password)
|
||||||
add_user_role(id, role_ids)
|
user_curd.add_user_role(id, role_ids)
|
||||||
|
|
||||||
return success_api(msg="增加成功")
|
return success_api(msg="增加成功")
|
||||||
|
|
||||||
|
|
||||||
# 删除用户
|
# 删除用户
|
||||||
@admin_user.route('/remove/<int:id>', methods=['DELETE'])
|
@admin_user.route('/remove/<int:id>', methods=['DELETE'])
|
||||||
@authorize_and_log("admin:user:remove")
|
@authorize("admin:user:remove", log=True)
|
||||||
def delete(id):
|
def delete(id):
|
||||||
res = delete_by_id(id)
|
res = user_curd.delete_by_id(id)
|
||||||
if not res:
|
if not res:
|
||||||
return fail_api(msg="删除失败")
|
return fail_api(msg="删除失败")
|
||||||
return success_api(msg="删除成功")
|
return success_api(msg="删除成功")
|
||||||
@@ -78,7 +76,7 @@ def delete(id):
|
|||||||
|
|
||||||
# 编辑用户
|
# 编辑用户
|
||||||
@admin_user.route('/edit/<int:id>', methods=['GET', 'POST'])
|
@admin_user.route('/edit/<int:id>', methods=['GET', 'POST'])
|
||||||
@authorize_and_log("admin:user:edit")
|
@authorize("admin:user:edit", log=True)
|
||||||
def edit(id):
|
def edit(id):
|
||||||
user = User.query.filter_by(id=id).first()
|
user = User.query.filter_by(id=id).first()
|
||||||
roles = Role.query.all()
|
roles = Role.query.all()
|
||||||
@@ -90,7 +88,7 @@ def edit(id):
|
|||||||
|
|
||||||
# 编辑用户
|
# 编辑用户
|
||||||
@admin_user.route('/update', methods=['PUT'])
|
@admin_user.route('/update', methods=['PUT'])
|
||||||
@authorize_and_log("admin:user:edit")
|
@authorize("admin:user:edit", log=True)
|
||||||
def update():
|
def update():
|
||||||
req_json = request.json
|
req_json = request.json
|
||||||
a = req_json.get("roleIds")
|
a = req_json.get("roleIds")
|
||||||
@@ -99,8 +97,8 @@ def update():
|
|||||||
realName = req_json.get('realName')
|
realName = req_json.get('realName')
|
||||||
deptId = req_json.get('deptId')
|
deptId = req_json.get('deptId')
|
||||||
role_ids = a.split(',')
|
role_ids = a.split(',')
|
||||||
update_user(id, username, realName,deptId)
|
user_curd.update_user(id, username, realName,deptId)
|
||||||
update_user_role(id, role_ids)
|
user_curd.update_user_role(id, role_ids)
|
||||||
return success_api(msg="更新成功")
|
return success_api(msg="更新成功")
|
||||||
|
|
||||||
|
|
||||||
@@ -109,7 +107,7 @@ def update():
|
|||||||
@login_required
|
@login_required
|
||||||
def center():
|
def center():
|
||||||
user_info = current_user
|
user_info = current_user
|
||||||
user_logs = get_current_user_logs()
|
user_logs = user_curd.get_current_user_logs()
|
||||||
return render_template('admin/user/center.html', user_info=user_info, user_logs=user_logs)
|
return render_template('admin/user/center.html', user_info=user_info, user_logs=user_logs)
|
||||||
|
|
||||||
|
|
||||||
@@ -125,7 +123,7 @@ def profile():
|
|||||||
@login_required
|
@login_required
|
||||||
def updateAvatar():
|
def updateAvatar():
|
||||||
url = request.json.get("avatar").get("src")
|
url = request.json.get("avatar").get("src")
|
||||||
if not update_avatar(url):
|
if not user_curd.update_avatar(url):
|
||||||
return fail_api(msg="出错啦")
|
return fail_api(msg="出错啦")
|
||||||
return success_api(msg="修改成功")
|
return success_api(msg="修改成功")
|
||||||
|
|
||||||
@@ -135,7 +133,7 @@ def updateAvatar():
|
|||||||
@login_required
|
@login_required
|
||||||
def updateInfo():
|
def updateInfo():
|
||||||
res_json = request.json
|
res_json = request.json
|
||||||
if not update_current_user_info(req_json=res_json):
|
if not user_curd.update_current_user_info(req_json=res_json):
|
||||||
return fail_api(msg="出错啦")
|
return fail_api(msg="出错啦")
|
||||||
return success_api(msg="更新成功")
|
return success_api(msg="更新成功")
|
||||||
|
|
||||||
@@ -152,16 +150,16 @@ def editPassword():
|
|||||||
@login_required
|
@login_required
|
||||||
def edit_password_put():
|
def edit_password_put():
|
||||||
res_json = request.json
|
res_json = request.json
|
||||||
return edit_password(res_json=res_json)
|
return user_curd.edit_password(res_json=res_json)
|
||||||
|
|
||||||
|
|
||||||
# 启用用户
|
# 启用用户
|
||||||
@admin_user.route('/enable', methods=['PUT'])
|
@admin_user.route('/enable', methods=['PUT'])
|
||||||
@authorize_and_log("admin:user:edit")
|
@authorize("admin:user:edit",log=True)
|
||||||
def enable():
|
def enable():
|
||||||
id = request.json.get('userId')
|
id = request.json.get('userId')
|
||||||
if id:
|
if id:
|
||||||
res = enable_status(id)
|
res = user_curd.enable_status(id)
|
||||||
if not res:
|
if not res:
|
||||||
return fail_api(msg="出错啦")
|
return fail_api(msg="出错啦")
|
||||||
return success_api(msg="启动成功")
|
return success_api(msg="启动成功")
|
||||||
@@ -170,11 +168,11 @@ def enable():
|
|||||||
|
|
||||||
# 禁用用户
|
# 禁用用户
|
||||||
@admin_user.route('/disable', methods=['PUT'])
|
@admin_user.route('/disable', methods=['PUT'])
|
||||||
@authorize_and_log("admin:user:edit")
|
@authorize("admin:user:edit",log=True)
|
||||||
def disenable():
|
def disenable():
|
||||||
id = request.json.get('userId')
|
id = request.json.get('userId')
|
||||||
if id:
|
if id:
|
||||||
res = disable_status(id)
|
res = user_curd.disable_status(id)
|
||||||
if not res:
|
if not res:
|
||||||
return fail_api(msg="出错啦")
|
return fail_api(msg="出错啦")
|
||||||
return success_api(msg="禁用成功")
|
return success_api(msg="禁用成功")
|
||||||
@@ -183,8 +181,8 @@ def disenable():
|
|||||||
|
|
||||||
# 批量删除
|
# 批量删除
|
||||||
@admin_user.route('/batchRemove', methods=['DELETE'])
|
@admin_user.route('/batchRemove', methods=['DELETE'])
|
||||||
@authorize_and_log("admin:user:remove")
|
@authorize("admin:user:remove", log=True)
|
||||||
def batchRemove():
|
def batchRemove():
|
||||||
ids = request.form.getlist('ids[]')
|
ids = request.form.getlist('ids[]')
|
||||||
batch_remove(ids)
|
user_curd.batch_remove(ids)
|
||||||
return success_api(msg="批量删除成功")
|
return success_api(msg="批量删除成功")
|
||||||
|
|||||||
Reference in New Issue
Block a user