fix: 修改权限判断bug
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
from django.core.management.base import BaseCommand
|
||||
from system.models import Menu, MenuMeta
|
||||
import re
|
||||
|
||||
from utils.string_utils import camel_to_snake
|
||||
|
||||
"""
|
||||
自动生成 菜单 代码的 Django 管理命令
|
||||
使用方法: python manage.py gen_menu_json <app> <model> <parent>
|
||||
@@ -11,10 +12,6 @@ system 是 app 名称, Config 是 model 名称, System 是上级菜单名称
|
||||
"""
|
||||
|
||||
# gen_menu_json --app system --model Config --parent 系统管理
|
||||
def camel_to_snake(name):
|
||||
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
|
||||
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
|
||||
|
||||
def gen_menu(app_name, model_name, parent_menu_name, creator='admin'):
|
||||
print(parent_menu_name, 'parent')
|
||||
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
"""
|
||||
|
||||
import os
|
||||
import re
|
||||
from string import Template
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.apps import apps
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
|
||||
from utils.string_utils import camel_to_snake
|
||||
|
||||
TPL_DIR = os.path.join(os.path.dirname(__file__), 'tpl')
|
||||
|
||||
@@ -23,9 +23,6 @@ def render_tpl(tpl_name, context):
|
||||
tpl = Template(f.read())
|
||||
return tpl.substitute(context)
|
||||
|
||||
def camel_to_snake(name):
|
||||
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
|
||||
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
|
||||
|
||||
def ensure_view_dirs(app_name, model_name_snake):
|
||||
base_dir = f'../web/apps/web-antd/src/views/{app_name.lower()}'
|
||||
|
||||
@@ -20,7 +20,8 @@ def update_user_login_info(user_id, client_ip, user_agent):
|
||||
user.save(update_fields=['login_ip', 'last_login'])
|
||||
|
||||
# 获取地理位置信息
|
||||
location_info = get_location_from_ip(client_ip)
|
||||
# location_info = get_location_from_ip(client_ip)
|
||||
location_info = None
|
||||
|
||||
# 记录登录日录
|
||||
LoginLog.objects.create(
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from rest_framework import permissions
|
||||
from rest_framework.permissions import BasePermission
|
||||
from system.models import Menu
|
||||
from utils.string_utils import camel_to_snake
|
||||
|
||||
|
||||
class IsSuperUserOrReadOnly(BasePermission):
|
||||
"""超级用户可读写,普通用户只读"""
|
||||
@@ -21,7 +23,7 @@ class HasButtonPermission(BasePermission):
|
||||
if not required_code:
|
||||
# 可自动推断权限编码逻辑
|
||||
app_label = view.queryset.model._meta.app_label
|
||||
model_name = view.queryset.model._meta.model_name
|
||||
model_name = camel_to_snake(view.queryset.model._meta.model_name)
|
||||
action = getattr(view, 'action', None)
|
||||
action_map = {
|
||||
'create': 'create',
|
||||
|
||||
5
backend/utils/string_utils.py
Normal file
5
backend/utils/string_utils.py
Normal file
@@ -0,0 +1,5 @@
|
||||
import re
|
||||
|
||||
def camel_to_snake(name):
|
||||
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
|
||||
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
|
||||
Reference in New Issue
Block a user