From 32ab0dc33dedd9fc354da35edf80805fa70892ee Mon Sep 17 00:00:00 2001 From: long2ice Date: Sat, 8 May 2021 21:22:04 +0800 Subject: [PATCH] update docs --- docs/en/docs/custom/provider.md | 1 + docs/en/docs/custom/providers/admin_log.md | 1 - docs/en/docs/custom/providers/login.md | 1 - docs/en/docs/custom/providers/permission.md | 1 - docs/en/docs/custom/providers/search.md | 1 - docs/en/docs/getting_started/quick_start.md | 9 ++- docs/en/docs/pro/exclusive.md | 13 ++++- docs/en/docs/pro/sponsor.md | 2 +- docs/en/docs/pro/support.md | 3 +- docs/en/docs/pro/upgrade.md | 6 +- docs/en/docs/reference/admin_log.md | 35 +++++++++++ docs/en/docs/reference/global_search.md | 19 ++++++ docs/en/docs/reference/middleware.md | 14 ++++- docs/en/docs/reference/permission.md | 64 +++++++++++++++++++++ docs/en/mkdocs.yml | 6 +- 15 files changed, 157 insertions(+), 19 deletions(-) create mode 100644 docs/en/docs/custom/provider.md delete mode 100644 docs/en/docs/custom/providers/admin_log.md delete mode 100644 docs/en/docs/custom/providers/login.md delete mode 100644 docs/en/docs/custom/providers/permission.md delete mode 100644 docs/en/docs/custom/providers/search.md diff --git a/docs/en/docs/custom/provider.md b/docs/en/docs/custom/provider.md new file mode 100644 index 0000000..d296174 --- /dev/null +++ b/docs/en/docs/custom/provider.md @@ -0,0 +1 @@ +# Provider diff --git a/docs/en/docs/custom/providers/admin_log.md b/docs/en/docs/custom/providers/admin_log.md deleted file mode 100644 index f025050..0000000 --- a/docs/en/docs/custom/providers/admin_log.md +++ /dev/null @@ -1 +0,0 @@ -# Admin Log Provider diff --git a/docs/en/docs/custom/providers/login.md b/docs/en/docs/custom/providers/login.md deleted file mode 100644 index a85a769..0000000 --- a/docs/en/docs/custom/providers/login.md +++ /dev/null @@ -1 +0,0 @@ -# Login Provider diff --git a/docs/en/docs/custom/providers/permission.md b/docs/en/docs/custom/providers/permission.md deleted file mode 100644 index a2c1e9f..0000000 --- a/docs/en/docs/custom/providers/permission.md +++ /dev/null @@ -1 +0,0 @@ -# Permission Provider diff --git a/docs/en/docs/custom/providers/search.md b/docs/en/docs/custom/providers/search.md deleted file mode 100644 index 613564c..0000000 --- a/docs/en/docs/custom/providers/search.md +++ /dev/null @@ -1 +0,0 @@ -# Search Provider diff --git a/docs/en/docs/getting_started/quick_start.md b/docs/en/docs/getting_started/quick_start.md index b48006f..7be3983 100644 --- a/docs/en/docs/getting_started/quick_start.md +++ b/docs/en/docs/getting_started/quick_start.md @@ -26,7 +26,11 @@ from examples.models import Admin import aioredis from fastapi import FastAPI -login_provider = UsernamePasswordProvider(admin_model=Admin, enable_captcha=True) +login_provider = UsernamePasswordProvider( + admin_model=Admin, + enable_captcha=True, + login_logo_url="https://preview.tabler.io/static/logo.svg" +) app = FastAPI() @@ -36,7 +40,6 @@ async def startup(): redis = await aioredis.create_redis_pool("redis://localhost", encoding="utf8") admin_app.configure( logo_url="https://preview.tabler.io/static/logo-white.svg", - login_logo_url="https://preview.tabler.io/static/logo.svg", template_folders=[os.path.join(BASE_DIR, "templates")], providers=[login_provider], redis=redis, @@ -165,3 +168,5 @@ class Content(Dropdown): ### What's next? That's all, you can run your app now. For more reference you can see [Reference](/reference). + +Or you can see full [examples](https://github.com/fastapi-admin/fastapi-admin/tree/dev/examples). diff --git a/docs/en/docs/pro/exclusive.md b/docs/en/docs/pro/exclusive.md index 2178f3f..1f5e82c 100644 --- a/docs/en/docs/pro/exclusive.md +++ b/docs/en/docs/pro/exclusive.md @@ -18,18 +18,25 @@ admin_app.add_middleware(BaseHTTPMiddleware, dispatch=LoginPasswordMaxTryMiddlew ## Permission Control +`PermissionProvider` allow you to configure the access control for resources of admin users with permissions `read` +/`create`/`update`/`delete`. + ## Additional File Upload ### ALiYunOSS +File upload for ALiYunOSS. + ### AwsS3 +File upload for AWS S3. + ## Maintenance If your site is in maintenance, you can set `true` to `admin_app.configure(...)`. ```python -admin_app.configure(maintenance=True) +await admin_app.configure(maintenance=True) ``` ## Admin Log @@ -37,7 +44,7 @@ admin_app.configure(maintenance=True) If you want to log all `create/update/delete` actions, you can add `AdminLogProvider` to `admin_app.configure(...)`. ```python -admin_app.configure(providers=[AdminLogProvider(Log)]) +await admin_app.configure(providers=[AdminLogProvider(Log)]) ``` ## Site Search @@ -45,5 +52,5 @@ admin_app.configure(providers=[AdminLogProvider(Log)]) You can enable site search by add `SearchProvider` to `admin_app.configure(...)`. ```python -admin_app.configure(providers=[SearchProvider()]) +await admin_app.configure(providers=[SearchProvider()]) ``` diff --git a/docs/en/docs/pro/sponsor.md b/docs/en/docs/pro/sponsor.md index 780e8f2..9b13311 100644 --- a/docs/en/docs/pro/sponsor.md +++ b/docs/en/docs/pro/sponsor.md @@ -26,7 +26,7 @@ You will be invited and keep collaborator role for half a year. You will be invited and keep collaborator role for a year. -## Warning +## Licence After you have be invited, you can read and clone and develop yourself, but please **don't distribute the source code** of pro version. Thanks! diff --git a/docs/en/docs/pro/support.md b/docs/en/docs/pro/support.md index 246faba..0daeffd 100644 --- a/docs/en/docs/pro/support.md +++ b/docs/en/docs/pro/support.md @@ -1,4 +1,5 @@ # Support -Whenever you have any questions, you can send email to or open `issue` in `fastapi-admin-pro` +Whenever you have any questions, you can send email to or +open [issues](https://github.com/fastapi-admin/fastapi-admin-pro/issues/new) in `fastapi-admin-pro` repository for help, I will answer your questions as soon as possible. diff --git a/docs/en/docs/pro/upgrade.md b/docs/en/docs/pro/upgrade.md index 6485699..a242a8d 100644 --- a/docs/en/docs/pro/upgrade.md +++ b/docs/en/docs/pro/upgrade.md @@ -1,6 +1,7 @@ # Upgrade from the open source version -It's so easy to upgrade `fastapi-admin` open source version to pro version, because pro version contains all of open source and has same project structure. +It's so easy to upgrade `fastapi-admin` open source version to pro version, because pro version contains all of open +source and has same project structure. 1. Uninstall open source version. @@ -15,3 +16,6 @@ It's so easy to upgrade `fastapi-admin` open source version to pro version, beca ``` That's all, then you can add pro version exclusive content yourself without any code change. + +And you can also see the pro version [examples](https://github.com/fastapi-admin/fastapi-admin-pro/tree/dev/examples) +for reference. diff --git a/docs/en/docs/reference/admin_log.md b/docs/en/docs/reference/admin_log.md index a7dedf9..a7ea340 100644 --- a/docs/en/docs/reference/admin_log.md +++ b/docs/en/docs/reference/admin_log.md @@ -1 +1,36 @@ # Admin Log (💗 Pro only) + +You can enable log all actions by using the `AdminLogProvider`. + +You should just add the `AdminLogProvider` to providers. + +```python +from fastapi import FastAPI +from fastapi_admin.app import app as admin_app +from fastapi_admin.providers.admin_log import AdminLogProvider +from examples.models import Log + +app = FastAPI() + + +@app.on_event("startup") +async def startup(): + await admin_app.configure( + providers=[AdminLogProvider(Log)] + ) +``` + +The `Log` model is subclass of `fastapi_admin.models.AbstractLog`. + +```python +class AbstractLog(Model): + admin = fields.ForeignKeyField("models.Admin") + content = fields.JSONField() + resource = fields.CharField(max_length=50) + action = fields.CharEnumField(enums.Action, default=enums.Action.create) + created_at = fields.DatetimeField(auto_now_add=True) + + class Meta: + abstract = True + ordering = ["-id"] +``` diff --git a/docs/en/docs/reference/global_search.md b/docs/en/docs/reference/global_search.md index 2da60f5..4d7e469 100644 --- a/docs/en/docs/reference/global_search.md +++ b/docs/en/docs/reference/global_search.md @@ -1 +1,20 @@ # Global Search (💗 Pro only) + +You can enable site search by add `SearchProvider` to `admin_app.configure(...)`. + +```python +from fastapi import FastAPI +from fastapi_admin.app import app as admin_app +from fastapi_admin.providers.search import SearchProvider + +app = FastAPI() + + +@app.on_event("startup") +async def startup(): + await admin_app.configure( + providers=[SearchProvider()] + ) +``` + +The builtin search provider can search for the all available resources by resource name. diff --git a/docs/en/docs/reference/middleware.md b/docs/en/docs/reference/middleware.md index d651a88..7c15273 100644 --- a/docs/en/docs/reference/middleware.md +++ b/docs/en/docs/reference/middleware.md @@ -2,9 +2,14 @@ ## language_processor -By default `fastapi-admin` support both `Chinese` and `English` and will display a language switch in page. To enable that, you should add `language_processor` middleware. +By default `fastapi-admin` support both `Chinese` and `English` and will display a language switch in page. To enable +that, you should add `language_processor` middleware. ```python +from starlette.middleware.base import BaseHTTPMiddleware +from fastapi_admin import middlewares +from fastapi_admin.app import app as admin_app + admin_app.add_middleware(BaseHTTPMiddleware, dispatch=middlewares.language_processor) ``` @@ -13,7 +18,12 @@ admin_app.add_middleware(BaseHTTPMiddleware, dispatch=middlewares.language_proce If you want limit login failed ip with error password, you can use `LoginPasswordMaxTryMiddleware`. ```python -admin_app.add_middleware(BaseHTTPMiddleware, dispatch=LoginPasswordMaxTryMiddleware(max_times=3, after_seconds=3600)) +from starlette.middleware.base import BaseHTTPMiddleware +from fastapi_admin import middlewares +from fastapi_admin.app import app as admin_app + +admin_app.add_middleware(BaseHTTPMiddleware, + dispatch=middlewares.LoginPasswordMaxTryMiddleware(max_times=3, after_seconds=3600)) ``` After that, user can try max `3` times password, if all failed, the ip will be limited `3600` seconds. diff --git a/docs/en/docs/reference/permission.md b/docs/en/docs/reference/permission.md index 9ba5712..640b215 100644 --- a/docs/en/docs/reference/permission.md +++ b/docs/en/docs/reference/permission.md @@ -1 +1,65 @@ # Permission Control (💗 Pro only) + +There are for kinds of permissions builtin. The `Link` has only `read`, and `Model` resource has all kinds of +permissions. + +```python +class Permission(Enum): + create = "create" + delete = "delete" + update = "update" + read = "read" +``` + +If an admin user has no `read` for a resource, it won't show the menu in dashboard. The `update`/`delete`/`create` +permissions is also related with the `actions` display. + +## Usage + +First, inherit and add the necessary models to your `models.py`. + +```python +from fastapi_admin.models import ( + AbstractPermission, + AbstractResource, + AbstractRole, +) + + +class Resource(AbstractResource): + pass + + +class Permission(AbstractPermission): + pass + + +class Role(AbstractRole): + pass +``` + +Then also add `PermissionProvider` to providers. + +```python +from fastapi import FastAPI +from fastapi_admin.app import app as admin_app +from fastapi_admin.providers.permission import PermissionProvider + +app = FastAPI() + + +@app.on_event("startup") +async def startup(): + await admin_app.configure( + providers=[ + PermissionProvider( + Admin, + Resource, + Permission, + ), + ] + ) +``` + +That's the all code, after that, all resources and permissions will autofill in database, what you need do is just add +role and relate admins in dashboard and configure permissions yourself. diff --git a/docs/en/mkdocs.yml b/docs/en/mkdocs.yml index 0989e21..c73b38b 100644 --- a/docs/en/mkdocs.yml +++ b/docs/en/mkdocs.yml @@ -57,11 +57,7 @@ nav: - custom/overwrite.md - custom/widget.md - custom/file_upload.md - - Providers: - - custom/providers/login.md - - custom/providers/search.md - - custom/providers/admin_log.md - - custom/providers/permission.md + - custom/provider.md - Pro Version For Sponsor: - pro/sponsor.md - pro/exclusive.md