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