diff --git a/applications/common/admin/dept_curd.py b/applications/common/admin/dept_curd.py index 0e0a978..f402888 100644 --- a/applications/common/admin/dept_curd.py +++ b/applications/common/admin/dept_curd.py @@ -2,7 +2,6 @@ from applications.extensions import db from applications.models import Dept, DeptSchema from applications.models import User from applications.common.curd import model_to_dicts -from flask import escape def get_dept_dict(): @@ -12,14 +11,14 @@ def get_dept_dict(): def save_dept(req): - address = escape(req.get("address")) - deptName = escape(req.get("deptName")) - email = escape(req.get("email")) - leader = escape(req.get("leader")) - parentId = escape(req.get("parentId")) - phone = escape(req.get("phone")) - sort = escape(req.get("sort")) - status = escape(req.get("status")) + address = req.get("address") + deptName = req.get("deptName") + email = req.get("email") + leader = req.get("leader") + parentId = req.get("parentId") + phone = req.get("phone") + sort = req.get("sort") + status = req.get("status") dept = Dept( parent_id=parentId, dept_name=deptName, @@ -65,13 +64,13 @@ def update_dept(json): """ 更新部门信息 """ _id = json.get("deptId"), data = { - "dept_name": escape(json.get("deptName")), - "sort": escape(json.get("sort")), - "leader": escape(json.get("leader")), - "phone": escape(json.get("phone")), - "email": escape(json.get("email")), - "status": escape(json.get("status")), - "address": escape(json.get("address")) + "dept_name": json.get("deptName"), + "sort": json.get("sort"), + "leader": json.get("leader"), + "phone": json.get("phone"), + "email": json.get("email"), + "status": json.get("status"), + "address": json.get("address") } d = Dept.query.filter_by(id=_id).update(data) if not d: diff --git a/applications/common/utils/gen_captcha.py b/applications/common/utils/gen_captcha.py index 622a6e1..e69de29 100644 --- a/applications/common/utils/gen_captcha.py +++ b/applications/common/utils/gen_captcha.py @@ -1,14 +0,0 @@ -from captcha.image import ImageCaptcha - -from PIL import Image -from random import choices - - -def gen_captcha(content='0123456789'): - """ 生成验证码 """ - image = ImageCaptcha() - # 获取字符串 - captcha_text = "".join(choices(content, k=4)) - # 生成图像 - captcha_image = Image.open(image.generate(captcha_text)) - return captcha_text, captcha_image diff --git a/applications/extensions/init_databases/__init__.py b/applications/extensions/init_databases/__init__.py index 8e4a07e..97ab387 100644 --- a/applications/extensions/init_databases/__init__.py +++ b/applications/extensions/init_databases/__init__.py @@ -302,7 +302,7 @@ course_data = [ phase_data = [ {'name': '基础课'}, - {'name': '进阶'}, + {'name': '高级开发'}, {'name': '爬虫'}, {'name': '数据分析'}, {'name': '全栈课程'} diff --git a/applications/templates/admin/admin_log/main.html b/applications/templates/admin/admin_log/main.html index cf5a1a8..ea6eca9 100644 --- a/applications/templates/admin/admin_log/main.html +++ b/applications/templates/admin/admin_log/main.html @@ -12,14 +12,14 @@
-
+
@@ -44,7 +44,7 @@ let table = layui.table let form = layui.form - let MODULE_PATH = '/admin/log/' + let MODULE_PATH = '/logs/' let cols = [ [ @@ -61,8 +61,8 @@ ] table.render({ - elem: '#log-operate-table', - url: MODULE_PATH + 'operateLog', + elem: '#log-access-table', + url: MODULE_PATH + 'access_log', page: true, cols: cols, skin: 'line', @@ -71,7 +71,7 @@ table.render({ elem: '#log-login-table', - url: MODULE_PATH + 'loginLog', + url: MODULE_PATH + 'login_log', page: true, cols: cols, skin: 'line', diff --git a/applications/templates/admin/dept/edit.html b/applications/templates/admin/dept/edit.html index eabbe84..de35fb6 100644 --- a/applications/templates/admin/dept/edit.html +++ b/applications/templates/admin/dept/edit.html @@ -97,6 +97,7 @@ let form = layui.form let $ = layui.jquery + // 当点击更新之后,获取数据 form.on('submit(dept-update)', function (data) { $.ajax({ url: '/dept/update', @@ -107,7 +108,7 @@ success: function (result) { if (result.success) { layer.msg(result.msg, { icon: 1, time: 1000 }, function () { - parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页 + parent.layer.close(parent.layer.getFrameIndex(window.name)) //关闭当前页 parent.render() }) } else { diff --git a/applications/templates/admin/dept/main.html b/applications/templates/admin/dept/main.html index 13d7503..bcfb56c 100644 --- a/applications/templates/admin/dept/main.html +++ b/applications/templates/admin/dept/main.html @@ -163,13 +163,16 @@ /*表格的工具栏*/ table.on('toolbar(dept-table)', function (obj) { + console.log(obj) if (obj.event === 'add') { window.add() } else if (obj.event === 'refresh') { window.refresh() } else if (obj.event === 'batchRemove') { {#window.batchRemove(obj)#} - console.log(table.checkStatus(obj.config.id).data) + layer.msg('禁止批量删除') + return false + {#console.log(table.checkStatus(obj.config.id).data)#} } }) diff --git a/applications/templates/admin/dict/add.html b/applications/templates/admin/dict/add.html index 4722d80..e2a3a21 100644 --- a/applications/templates/admin/dict/add.html +++ b/applications/templates/admin/dict/add.html @@ -69,7 +69,7 @@ success: function (result) { if (result.success) { layer.msg(result.msg, { icon: 1, time: 1000 }, function () { - parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页 + parent.layer.close(parent.layer.getFrameIndex(window.name)) //关闭当前页 parent.layui.table.reload('dict-type-table') }) } else { diff --git a/applications/templates/admin/dict/main.html b/applications/templates/admin/dict/main.html index bfe2f32..7294521 100644 --- a/applications/templates/admin/dict/main.html +++ b/applications/templates/admin/dict/main.html @@ -92,7 +92,9 @@ @@ -108,9 +110,11 @@ diff --git a/applications/templates/admin/photo/photo.html b/applications/templates/admin/file/photo.html similarity index 99% rename from applications/templates/admin/photo/photo.html rename to applications/templates/admin/file/photo.html index 7ae39ad..a4f77a1 100644 --- a/applications/templates/admin/photo/photo.html +++ b/applications/templates/admin/file/photo.html @@ -210,7 +210,7 @@ layer.close(index) let loading = layer.load() $.ajax({ - url: "{{ url_for('adminFile.batch_remove') }}", + url: "{{ url_for('file.batch_remove') }}", data: { ids: ids }, dataType: 'json', type: 'POST', diff --git a/applications/templates/admin/photo/photo_add.html b/applications/templates/admin/file/photo_add.html similarity index 97% rename from applications/templates/admin/photo/photo_add.html rename to applications/templates/admin/file/photo_add.html index 77469ae..20d343b 100644 --- a/applications/templates/admin/photo/photo_add.html +++ b/applications/templates/admin/file/photo_add.html @@ -43,7 +43,7 @@ //选完文件后不自动上传 upload.render({ elem: '#logo-img' - , url: "{{ url_for('adminFile.upload') }}" + , url: "{{ url_for('file.upload') }}" , auto: false , exts: 'jpg|png|gif|bmp|jpeg' , size: 1000 diff --git a/applications/templates/admin/index.html b/applications/templates/admin/index.html index 578e7a9..37957e4 100644 --- a/applications/templates/admin/index.html +++ b/applications/templates/admin/index.html @@ -17,9 +17,12 @@
@@ -66,7 +69,9 @@
-
+
+ +
diff --git a/applications/templates/admin/login.html b/applications/templates/admin/login.html index 3cdaf9b..35c51c9 100644 --- a/applications/templates/admin/login.html +++ b/applications/templates/admin/login.html @@ -39,51 +39,56 @@ {% include 'admin/common/footer.html' %} \ No newline at end of file diff --git a/applications/templates/admin/power/edit.html b/applications/templates/admin/power/edit.html index 0060a5f..aa71e43 100644 --- a/applications/templates/admin/power/edit.html +++ b/applications/templates/admin/power/edit.html @@ -137,8 +137,9 @@ form.on('submit(power-save)', function (data) { data.field.icon = 'layui-icon ' + data.field.icon + console.log(data.field) $.ajax({ - url: '{{ url_for('rights.update') }}', + url: '/rights/power/' + data.field.powerId , data: JSON.stringify(data.field), dataType: 'json', contentType: 'application/json', diff --git a/applications/templates/admin/power/main.html b/applications/templates/admin/power/main.html index 0a5dabb..e658c52 100644 --- a/applications/templates/admin/power/main.html +++ b/applications/templates/admin/power/main.html @@ -106,7 +106,7 @@ toolbar: '#power-toolbar', elem: '#power-table', url: '{{ url_for('rights.data') }}', - page: false, + page: false, cols: [ [ {% if authorize("admin:role:remove") %} @@ -212,7 +212,7 @@ title: '修改', shade: 0.1, area: ['450px', '500px'], - content: MODULE_PATH + 'edit/' + obj.data['powerId'] + content: MODULE_PATH + 'power/' + obj.data['powerId'] }) } window.remove = function (obj) { @@ -220,7 +220,7 @@ layer.close(index) let loading = layer.load() $.ajax({ - url: MODULE_PATH + 'remove/' + obj.data['powerId'], + url: MODULE_PATH + 'power/' + obj.data['powerId'], dataType: 'json', type: 'delete', success: function (result) { diff --git a/applications/view/admin/__init__.py b/applications/view/admin/__init__.py index 428f5a6..62372fc 100644 --- a/applications/view/admin/__init__.py +++ b/applications/view/admin/__init__.py @@ -1,10 +1,10 @@ from flask import Flask -from applications.view.admin.admin_log import admin_log +from applications.view.admin.logs import admin_log from applications.view.admin.dict import admin_dict from applications.view.admin.index import admin_bp -from applications.view.admin.file import admin_file -from applications.view.rights.role import admin_role +from applications.view.admin.file import file_bp +from applications.view.rights.role import role_bp from applications.view.company.users import users_bp from applications.view.admin.monitor import admin_monitor_bp @@ -12,8 +12,8 @@ from applications.view.admin.monitor import admin_monitor_bp def register_admin_views(app: Flask): app.register_blueprint(admin_bp) app.register_blueprint(users_bp) - app.register_blueprint(admin_file) + app.register_blueprint(file_bp) app.register_blueprint(admin_monitor_bp) app.register_blueprint(admin_log) - app.register_blueprint(admin_role) + app.register_blueprint(role_bp) app.register_blueprint(admin_dict) diff --git a/applications/view/admin/admin_log.py b/applications/view/admin/admin_log.py deleted file mode 100644 index b30271b..0000000 --- a/applications/view/admin/admin_log.py +++ /dev/null @@ -1,58 +0,0 @@ -from flask import Blueprint, request, render_template -from sqlalchemy import desc - -from applications.common.utils.http import table_api -from applications.common.utils.rights import authorize -from applications.models import AdminLog, LogSchema -from applications.common.curd import model_to_dicts - -admin_log = Blueprint('adminLog', __name__, url_prefix='/admin/log') - - -# ---------------------------------------------------------- -# ------------------------- 日志管理 -------------------------- -# ---------------------------------------------------------- - - -@admin_log.get('/') -@authorize("admin:log:main") -def index(): - return render_template('admin/admin_log/main.html') - - -# ========================================================== -# 登录日志 -# ========================================================== - - -@admin_log.get('/loginLog') -@authorize("admin:log:main") -def login_log(): - page = request.args.get('page', type=int) - limit = request.args.get('limit', type=int) - log = AdminLog.query.filter_by(url='/admin/login').order_by(desc(AdminLog.create_time)).paginate(page=page, - per_page=limit, - error_out=False) - count = AdminLog.query.filter_by(url='/admin/login').count() - data = model_to_dicts(Schema=LogSchema, model=log.items) - - return table_api(data=data, count=count) - - -# ========================================================== -# 操作日志 -# ========================================================== - - -@admin_log.get('/operateLog') -@authorize("admin:log:main") -def operate_log(): - page = request.args.get('page', type=int) - limit = request.args.get('limit', type=int) - log = AdminLog.query.filter( - AdminLog.url != '/admin/login').order_by( - desc(AdminLog.create_time)).paginate( - page=page, per_page=limit, error_out=False) - count = AdminLog.query.filter(AdminLog.url != '/admin/login').count() - data = model_to_dicts(Schema=LogSchema, model=log.items) - return table_api(data=data, count=count) diff --git a/applications/view/admin/dict.py b/applications/view/admin/dict.py index 55fc57a..53825a2 100644 --- a/applications/view/admin/dict.py +++ b/applications/view/admin/dict.py @@ -22,7 +22,7 @@ def dict_type_data(): limit = request.args.get('limit', type=int) type_name = request.args.get('typeName', type=str) 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.get('/dictType/add') diff --git a/applications/view/admin/file.py b/applications/view/admin/file.py index 8eb6a7f..1f74e0c 100644 --- a/applications/view/admin/file.py +++ b/applications/view/admin/file.py @@ -7,18 +7,18 @@ from applications.extensions import db from applications.models import Photo from applications.common.admin import file_curd -admin_file = Blueprint('adminFile', __name__, url_prefix='/admin/file') +file_bp = Blueprint('file', __name__, url_prefix='/file') # 图片管理 -@admin_file.get('/') +@file_bp.get('/') @authorize("admin:file:main", log=True) def index(): - return render_template('admin/photo/photo.html') + return render_template('admin/file/photo.html') # 图片数据 -@admin_file.get('/table') +@file_bp.get('/table') @authorize("admin:file:main", log=True) def table(): page = request.args.get('page', type=int) @@ -28,14 +28,14 @@ def table(): # 上传 -@admin_file.get('/upload') +@file_bp.get('/upload') @authorize("admin:file:add", log=True) def upload(): - return render_template('admin/photo/photo_add.html') + return render_template('admin/file/photo_add.html') # 上传接口 -@admin_file.post('/upload') +@file_bp.post('/upload') @authorize("admin:file:add", log=True) def upload_api(): if 'file' in request.files: @@ -54,7 +54,7 @@ def upload_api(): # 图片删除 -@admin_file.route('/delete', methods=['GET', 'POST']) +@file_bp.route('/delete', methods=['GET', 'POST']) @authorize("admin:file:delete", log=True) def delete(): _id = request.form.get('id') @@ -66,7 +66,7 @@ def delete(): # 图片批量删除 -@admin_file.route('/batchRemove', methods=['GET', 'POST']) +@file_bp.route('/batchRemove', methods=['GET', 'POST']) @authorize("admin:file:delete", log=True) def batch_remove(): ids = request.form.getlist('ids[]') diff --git a/applications/view/admin/logs.py b/applications/view/admin/logs.py new file mode 100644 index 0000000..d73d458 --- /dev/null +++ b/applications/view/admin/logs.py @@ -0,0 +1,43 @@ +from flask import Blueprint, request, render_template +from sqlalchemy import desc + +from applications.common.utils.http import table_api +from applications.common.utils.rights import authorize +from applications.models import AdminLog, LogSchema +from applications.common.curd import model_to_dicts + +admin_log = Blueprint('logs', __name__, url_prefix='/logs') + + +@admin_log.get('/') +@authorize("admin:log:main") +def index(): + return render_template('admin/admin_log/main.html') + + +@admin_log.get('/login_log') +@authorize("admin:log:main") +def login_log(): + page = request.args.get('page', type=int) + limit = request.args.get('limit', type=int) + log_paginate = AdminLog.query.filter_by( + url='/passport/login').order_by( + desc(AdminLog.create_time)).paginate( + page=page, per_page=limit, error_out=False) + data = model_to_dicts(Schema=LogSchema, model=log_paginate.items) + + return table_api(data=data, count=log_paginate.total) + + +@admin_log.get('/access_log') +@authorize("admin:log:main") +def operate_log(): + page = request.args.get('page', type=int) + limit = request.args.get('limit', type=int) + log = AdminLog.query.filter( + AdminLog.url != '/passport/login').order_by( + desc(AdminLog.create_time)).paginate( + page=page, per_page=limit, error_out=False) + count = AdminLog.query.filter(AdminLog.url != '/admin/login').count() + data = model_to_dicts(Schema=LogSchema, model=log.items) + return table_api(data=data, count=count) diff --git a/applications/view/passport/__init__.py b/applications/view/passport/__init__.py index 735073e..e856c02 100644 --- a/applications/view/passport/__init__.py +++ b/applications/view/passport/__init__.py @@ -1,10 +1,10 @@ from flask import Blueprint, session, redirect, url_for, render_template, request, make_response from flask_login import current_user, login_user, login_required, logout_user from flask_restful import Resource, Api, reqparse -from applications.common.admin import index_curd from applications.common.admin_log import login_log from applications.common.utils.http import fail_api, success_api from applications.models import User +from ._utils import get_captcha_image, add_auth_session passport_bp = Blueprint('passport', __name__, url_prefix='/passport') passport_api = Api(passport_bp) @@ -17,7 +17,7 @@ def register_passport_views(app): # 获取验证码 @passport_bp.get('/getCaptcha') def get_captcha(): - resp, code = index_curd.get_captcha() + resp, code = get_captcha_image() session["code"] = code return resp @@ -57,7 +57,7 @@ class Login(Resource): # 记录登录日志 login_log(request, uid=user.id, is_access=True) # 存入权限 - index_curd.add_auth_session() + add_auth_session() return success_api(msg="登录成功") login_log(request, uid=user.id, is_access=False) return fail_api(msg="用户名或密码错误") diff --git a/applications/view/passport/_utils.py b/applications/view/passport/_utils.py new file mode 100644 index 0000000..7583601 --- /dev/null +++ b/applications/view/passport/_utils.py @@ -0,0 +1,43 @@ +from captcha.image import ImageCaptcha +from io import BytesIO +from PIL import Image +from random import choices + +from flask import session, make_response +from flask_login import current_user + + +def gen_captcha(content='0123456789'): + """ 生成验证码 """ + image = ImageCaptcha() + # 获取字符串 + captcha_text = "".join(choices(content, k=4)) + # 生成图像 + captcha_image = Image.open(image.generate(captcha_text)) + return captcha_text, captcha_image + + +# 生成验证码 +def get_captcha_image(): + code, image = gen_captcha() + out = BytesIO() + session["code"] = code + image.save(out, 'png') + out.seek(0) + resp = make_response(out.read()) + resp.content_type = 'image/png' + return resp, code + + +# 授权路由存入session +def add_auth_session(): + role = current_user.role + user_power = [] + for i in role: + if i.enable == 0: + continue + for p in i.power: + if p.enable == 0: + continue + user_power.append(p.code) + session['permissions'] = user_power diff --git a/applications/view/rights/__init__.py b/applications/view/rights/__init__.py index a6bf133..5497d52 100644 --- a/applications/view/rights/__init__.py +++ b/applications/view/rights/__init__.py @@ -1,6 +1,8 @@ from flask import Blueprint, Flask +from flask_restful import Api rights_bp = Blueprint('rights', __name__, url_prefix='/rights') +rights_api = Api(rights_bp) from . import routes from . import view diff --git a/applications/common/admin/index_curd.py b/applications/view/rights/_utils.py similarity index 81% rename from applications/common/admin/index_curd.py rename to applications/view/rights/_utils.py index 5c9de03..813d203 100644 --- a/applications/common/admin/index_curd.py +++ b/applications/view/rights/_utils.py @@ -1,75 +1,10 @@ -from collections import OrderedDict import copy +from collections import OrderedDict -from io import BytesIO -from flask import session, make_response, current_app +from flask import current_app from flask_login import current_user -from applications.common.utils.gen_captcha import gen_captcha -from applications.models.rights.power import PowerSchema - - -# 授权路由存入session -def add_auth_session(): - role = current_user.role - user_power = [] - for i in role: - if i.enable == 0: - continue - for p in i.power: - if p.enable == 0: - continue - user_power.append(p.code) - session['permissions'] = user_power - - -# 生成菜单树 -def make_menu_tree(): - role = current_user.role - powers = [] - for i in role: - # 如果角色没有被启用就直接跳过 - if i.enable == 0: - continue - # 变量角色用户的权限 - for p in i.power: - # 如果权限关闭了就直接跳过 - if p.enable == 0: - continue - # 一二级菜单 - if p.type == 0 or p.type == 1: - powers.append(p) - - power_schema = PowerSchema(many=True) # 用已继承 ma.ModelSchema 类的自定制类生成序列化类 - power_dict = power_schema.dump(powers) # 生成可序列化对象 - power_dict.sort(key=lambda x: x['id'], reverse=True) - - menu_dict = OrderedDict() - for _dict in power_dict: - if _dict['id'] in menu_dict: - # 当前节点添加子节点 - _dict['children'] = copy.deepcopy(menu_dict[_dict['id']]) - # 删除子节点 - del menu_dict[_dict['id']] - - if _dict['parent_id'] not in menu_dict: - menu_dict[_dict['parent_id']] = [_dict] - else: - menu_dict[_dict['parent_id']].append(_dict) - - return menu_dict.get(0) - - -# 生成验证码 -def get_captcha(): - code, image = gen_captcha() - out = BytesIO() - session["code"] = code - image.save(out, 'png') - out.seek(0) - resp = make_response(out.read()) - resp.content_type = 'image/png' - return resp, code +from applications.models import PowerSchema def get_render_config(): @@ -142,3 +77,41 @@ def get_render_config(): "autoHead": False }, header=False) return config + + +# 生成菜单树 +def make_menu_tree(): + role = current_user.role + powers = [] + for i in role: + # 如果角色没有被启用就直接跳过 + if i.enable == 0: + continue + # 变量角色用户的权限 + for p in i.power: + # 如果权限关闭了就直接跳过 + if p.enable == 0: + continue + # 一二级菜单 + if p.type == 0 or p.type == 1: + powers.append(p) + + power_schema = PowerSchema(many=True) # 用已继承 ma.ModelSchema 类的自定制类生成序列化类 + power_dict = power_schema.dump(powers) # 生成可序列化对象 + power_dict.sort(key=lambda x: x['id'], reverse=True) + + menu_dict = OrderedDict() + for _dict in power_dict: + if _dict['id'] in menu_dict: + # 当前节点添加子节点 + _dict['children'] = copy.deepcopy(menu_dict[_dict['id']]) + # 删除子节点 + del menu_dict[_dict['id']] + + if _dict['parent_id'] not in menu_dict: + menu_dict[_dict['parent_id']] = [_dict] + else: + menu_dict[_dict['parent_id']].append(_dict) + + return menu_dict.get(0) + diff --git a/applications/view/rights/role.py b/applications/view/rights/role.py index 659487d..499b013 100644 --- a/applications/view/rights/role.py +++ b/applications/view/rights/role.py @@ -5,18 +5,18 @@ from applications.common.utils.http import table_api, success_api, fail_api from applications.common.utils.rights import authorize -admin_role = Blueprint('role', __name__, url_prefix='/admin/role') +role_bp = Blueprint('role', __name__, url_prefix='/admin/role') # 用户管理 -@admin_role.get('/') +@role_bp.get('/') @authorize("admin:role:main", log=True) def main(): return render_template('admin/role/main.html') # 表格数据 -@admin_role.get('/data') +@role_bp.get('/data') @authorize("admin:role:main", log=True) def table(): page = request.args.get('page', type=int) @@ -33,7 +33,7 @@ def table(): # 角色增加 -@admin_role.get('/add') +@role_bp.get('/add') @authorize("admin:role:add", log=True) @login_required def add(): @@ -41,7 +41,7 @@ def add(): # 角色增加 -@admin_role.post('/save') +@role_bp.post('/save') @authorize("admin:role:add", log=True) def save(): req = request.json @@ -50,14 +50,14 @@ def save(): # 角色授权 -@admin_role.get('/power/') +@role_bp.get('/power/') @authorize("admin:role:power", log=True) def power(_id): return render_template('admin/role/power.html', id=_id) # 获取角色权限 -@admin_role.get('/getRolePower/') +@role_bp.get('/getRolePower/') @authorize("admin:role:main", log=True) def get_role_power(_id): powers = role_curd.get_role_power(_id) @@ -69,7 +69,7 @@ def get_role_power(_id): # 保存角色权限 -@admin_role.put('/saveRolePower') +@role_bp.put('/saveRolePower') @authorize("admin:role:edit", log=True) def save_role_power(): req_form = request.form @@ -81,7 +81,7 @@ def save_role_power(): # 角色编辑 -@admin_role.get('/edit/') +@role_bp.get('/edit/') @authorize("admin:role:edit", log=True) def edit(_id): role = role_curd.get_role_by_id(_id) @@ -89,7 +89,7 @@ def edit(_id): # 更新角色 -@admin_role.put('/update') +@role_bp.put('/update') @authorize("admin:role:edit", log=True) def update(): res = role_curd.update_role(request.json) @@ -99,7 +99,7 @@ def update(): # 启用用户 -@admin_role.put('/enable') +@role_bp.put('/enable') @authorize("admin:role:edit", log=True) def enable(): id = request.json.get('roleId') @@ -113,7 +113,7 @@ def enable(): # 禁用用户 -@admin_role.put('/disable') +@role_bp.put('/disable') @authorize("admin:role:edit", log=True) def dis_enable(): _id = request.json.get('roleId') @@ -126,7 +126,7 @@ def dis_enable(): # 角色删除 -@admin_role.delete('/remove/') +@role_bp.delete('/remove/') @authorize("admin:role:remove", log=True) def remove(_id): res = role_curd.remove_role(_id) @@ -136,7 +136,7 @@ def remove(_id): # 批量删除 -@admin_role.delete('/batchRemove') +@role_bp.delete('/batchRemove') @authorize("admin:role:remove", log=True) @login_required def batch_remove(): diff --git a/applications/view/rights/routes.py b/applications/view/rights/routes.py index be6f42e..0fa21a4 100644 --- a/applications/view/rights/routes.py +++ b/applications/view/rights/routes.py @@ -3,18 +3,19 @@ from flask import jsonify from flask_login import login_required from . import rights_bp -from ...common.admin import index_curd + +from ._utils import get_render_config, make_menu_tree @rights_bp.get('/configs') @login_required def configs(): - return index_curd.get_render_config() + return get_render_config() # 菜单 @rights_bp.get('/menu') @login_required def menu(): - menu_tree = index_curd.make_menu_tree() + menu_tree = make_menu_tree() return jsonify(menu_tree) diff --git a/applications/view/rights/view.py b/applications/view/rights/view.py index c7a06c1..5188c91 100644 --- a/applications/view/rights/view.py +++ b/applications/view/rights/view.py @@ -1,6 +1,7 @@ -from flask import render_template, request, jsonify +from flask import render_template, request, jsonify, make_response +from flask_restful import Resource, reqparse -from . import rights_bp +from . import rights_bp, rights_api from ...common.admin import rights_curd from ...common.utils.http import success_api, fail_api from ...common.utils.rights import authorize @@ -25,12 +26,14 @@ def data(): @rights_bp.get('/add') @authorize("admin:power:add", log=True) def add(): + """获取增加视图""" return render_template('admin/power/add.html') @rights_bp.get('/selectParent') @authorize("admin:power:main", log=True) def select_parent(): + """获取选择父节点""" power_data = rights_curd.select_parent() res = { "status": {"code": 200, "message": "默认"}, @@ -49,36 +52,41 @@ def save(): return success_api(msg="成功") -# 权限编辑 -@rights_bp.get('/edit/') -@authorize("admin:power:edit", log=True) -def edit(_id): - power = rights_curd.get_power_by_id(_id) - icon = str(power.icon).split() - if len(icon) == 2: - icon = icon[1] - else: - icon = None - return render_template('admin/power/edit.html', power=power, icon=icon) +@rights_api.resource('/power/') +class RightsURD(Resource): + @authorize("admin:power:edit", log=True) + def get(self, power_id): + power = rights_curd.get_power_by_id(power_id) + icon = str(power.icon).split() + if len(icon) == 2: + icon = icon[1] + else: + icon = None + return make_response(render_template('admin/power/edit.html', power=power, icon=icon)) + @authorize("admin:power:remove", log=True) + def delete(self, power_id): + r = rights_curd.remove_power(power_id) + if r: + return success_api(msg="删除成功") + else: + return fail_api(msg="删除失败") -# 权限更新 -@rights_bp.put('/update') -@authorize("admin:power:edit", log=True) -def update(): - res = rights_curd.update_power(request.json) - if not res: - return fail_api(msg="更新权限失败") - return success_api(msg="更新权限成功") + @authorize("admin:power:edit", log=True) + def put(self, power_id): + res = rights_curd.update_power(request.json) + if not res: + return fail_api(msg="更新权限失败") + return success_api(msg="更新权限成功") # 启用权限 @rights_bp.put('/enable') @authorize("admin:power:edit", log=True) def enable(): - _id = request.json.get('powerId') + power_id = request.json.get('powerId') if id: - res = rights_curd.enable_status(_id) + res = rights_curd.enable_status(power_id) if not res: return fail_api(msg="出错啦") return success_api(msg="启用成功") @@ -98,17 +106,6 @@ def dis_enable(): return fail_api(msg="数据错误") -# 权限删除 -@rights_bp.delete('/remove/') -@authorize("admin:power:remove", log=True) -def remove(_id): - r = rights_curd.remove_power(_id) - if r: - return success_api(msg="删除成功") - else: - return fail_api(msg="删除失败") - - # 批量删除 @rights_bp.delete('/batchRemove') @authorize("admin:power:remove", log=True)