diff --git a/README.md b/README.md index 93b956d..a1e85d9 100644 --- a/README.md +++ b/README.md @@ -76,11 +76,15 @@ site.mount_app(app) @app.on_event("startup") async def startup(): await site.db.async_run_sync(SQLModel.metadata.create_all, is_session=False) - # 创建默认管理员,用户名: root,密码: root, 请及时修改密码!!! - await auth.create_role_user('root') - await auth.create_role_user('admin') + # 创建默认管理员,用户名: admin,密码: admin, 请及时修改密码!!! + await auth.create_role_user("admin") + # 创建默认超级管理员,用户名: root,密码: root, 请及时修改密码!!! + await auth.create_role_user("root") # 运行site的startup方法,加载casbin策略等 await site.router.startup() + # 添加一条默认的casbin规则 + if not auth.enforcer.enforce("u:admin", site.unique_id, "page", "page"): + await auth.enforcer.add_policy("u:admin", site.unique_id, "page", "page", "allow") # 要求: 用户必须登录 @@ -140,8 +144,6 @@ def admin_or_vip_roles(request: Request): ```python from fastapi import Depends -from typing import Tuple -from fastapi_user_auth.auth import Auth from fastapi_user_auth.auth.models import User diff --git a/fastapi_user_auth/__init__.py b/fastapi_user_auth/__init__.py index 27c0a12..cf98626 100644 --- a/fastapi_user_auth/__init__.py +++ b/fastapi_user_auth/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.6.1a7" +__version__ = "0.6.1" __url__ = "https://github.com/amisadmin/fastapi_user_auth" import gettext diff --git a/pyproject.toml b/pyproject.toml index a56301b..eaabf56 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,8 +36,8 @@ classifiers = [ "Programming Language :: Python :: 3.11", ] dependencies = [ - "pydantic>=1.9.0,<2.0.0", - "fastapi-amis-admin>=0.6.5a2,<0.7.0", + "pydantic>=1.10.0,<2.0.0", + "fastapi-amis-admin>=0.6.5,<0.7.0", "email-validator>=1.3.1,<2.0.0", "passlib>=1.7.4", "bcrypt>=4.0.0", diff --git a/tests/test_mixins/admin.py b/tests/test_mixins/admin.py index e74b07f..4eecd62 100644 --- a/tests/test_mixins/admin.py +++ b/tests/test_mixins/admin.py @@ -1,7 +1,7 @@ from typing import List, Optional from fastapi_amis_admin import admin -from fastapi_amis_admin.admin import RecentTimeSelectPerm, SelectPerm, SimpleSelectPerm, UserSelectPerm +from fastapi_amis_admin.admin import FieldPermEnum, RecentTimeSelectPerm, SelectPerm, SimpleSelectPerm, UserSelectPerm from fastapi_amis_admin.amis import PageSchema from fastapi_amis_admin.models import Field from sqlalchemy import Column, Text @@ -24,7 +24,7 @@ class AuthFieldArticleAdmin(AuthFieldModelAdmin, admin.ModelAdmin): page_schema = PageSchema(label="字段控制文章管理") model = Article perm_fields_exclude = { - "create": ["title", "description", "content"], + FieldPermEnum.CREATE: ["title", "description", "content"], }