Skip to content

Commit 44238bc

Browse files
committed
feat: 支持管理后台使用可视化配置*匹配全部字段
1 parent 140a745 commit 44238bc

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

fastapi_user_auth/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.6.1a3"
1+
__version__ = "0.6.1a4"
22
__url__ = "https://github.com/amisadmin/fastapi_user_auth"
33

44
import gettext

fastapi_user_auth/admin/actions.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,21 @@ def get_admin_field_permission_rows(admin: PageSchemaAdmin, action: str) -> List
6262
fields = admin.read_permission_fields
6363
else:
6464
pass
65-
for name, label in fields.items():
66-
rows.append(
67-
{
68-
"label": label,
69-
"rol": f"{admin.unique_id}#page:{action}:{name}#page:{action}",
70-
}
71-
)
65+
if not fields:
66+
return []
67+
rows.append(
68+
{
69+
"label": "全部",
70+
"rol": f"{admin.unique_id}#page:{action}:*#page:{action}",
71+
}
72+
)
73+
rows.extend(
74+
{
75+
"label": label,
76+
"rol": f"{admin.unique_id}#page:{action}:{name}#page:{action}",
77+
}
78+
for name, label in fields.items()
79+
)
7280
elif isinstance(admin, FormAdmin): # todo 表单管理
7381
pass
7482
return rows
@@ -348,9 +356,9 @@ async def get_admin_action_perm_options(
348356
admin, parent = self.site.get_page_schema_child(unique_id)
349357
if not admin:
350358
return out
351-
if action == "page":
359+
if action == "page": # select权限
352360
rows = get_admin_select_permission_rows(admin)
353-
else:
361+
else: # 字段权限
354362
action = action.replace("page:", "")
355363
rows = get_admin_field_permission_rows(admin, action)
356364
out.data["rows"] = rows

fastapi_user_auth/mixins/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class BaseAuthFieldModelAdmin(admin.ModelAdmin):
101101
#todo 初步实现,未优化
102102
"""
103103

104-
perm_fields_exclude: Dict[int, Sequence[str]] = None
104+
perm_fields_exclude: Dict[Union[FieldPermEnum, int], Sequence[str]] = None
105105
"""exclude指定的字段,不进行权限验证."""
106106

107107
def __init__(self, app: "AdminApp"):

0 commit comments

Comments
 (0)