modify: 修复 static_files.py 错误
This commit is contained in:
+49
@@ -44,3 +44,52 @@ class PermissionConstant:
|
|||||||
CUSTOMER_EXPORT = "customer:export" # 导出客户
|
CUSTOMER_EXPORT = "customer:export" # 导出客户
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_all(cls):
|
||||||
|
"""
|
||||||
|
获取系统中定义的所有权限字符串列表
|
||||||
|
|
||||||
|
该方法通过反射机制自动收集所有内部类中定义的权限常量,
|
||||||
|
用于数据库同步、权限初始化等场景。
|
||||||
|
|
||||||
|
工作流程:
|
||||||
|
1. 遍历 Permission 类的所有属性
|
||||||
|
2. 跳过私有属性和非类属性
|
||||||
|
3. 对每个内部类,遍历其所有字符串类型的权限常量
|
||||||
|
4. 过滤出符合 "resource:action" 格式的权限标识
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list[str]: 所有权限字符串的列表,例如:
|
||||||
|
[
|
||||||
|
'sales_order:create',
|
||||||
|
'sales_order:read',
|
||||||
|
'customer:export',
|
||||||
|
...
|
||||||
|
]
|
||||||
|
|
||||||
|
使用示例:
|
||||||
|
>>> all_perms = Permission.get_all()
|
||||||
|
>>> len(all_perms) # 获取权限总数
|
||||||
|
85
|
||||||
|
>>> 'sales_order:create' in all_perms # 检查权限是否存在
|
||||||
|
True
|
||||||
|
|
||||||
|
Note:
|
||||||
|
- 该方法会自动排除以下划线开头的私有属性
|
||||||
|
- 只收集包含冒号的字符串值,确保是有效的权限标识
|
||||||
|
- 返回的列表顺序取决于 dir() 函数的返回顺序
|
||||||
|
"""
|
||||||
|
perms = []
|
||||||
|
for attr_name in dir(cls):
|
||||||
|
attr = getattr(cls, attr_name)
|
||||||
|
if attr_name.startswith("_") or not hasattr(attr, "__dict__"):
|
||||||
|
continue
|
||||||
|
# 遍历内部类的属性
|
||||||
|
for sub_attr in dir(attr):
|
||||||
|
if sub_attr.startswith("_"):
|
||||||
|
continue
|
||||||
|
val = getattr(attr, sub_attr)
|
||||||
|
if isinstance(val, str) and ":" in val:
|
||||||
|
perms.append(val)
|
||||||
|
return perms
|
||||||
|
|||||||
Reference in New Issue
Block a user