update docs

This commit is contained in:
long2ice
2021-05-08 21:22:04 +08:00
parent 529c87ad0b
commit 32ab0dc33d
15 changed files with 157 additions and 19 deletions

View File

@@ -0,0 +1 @@
# Provider

View File

@@ -1 +0,0 @@
# Admin Log Provider

View File

@@ -1 +0,0 @@
# Login Provider

View File

@@ -1 +0,0 @@
# Permission Provider

View File

@@ -1 +0,0 @@
# Search Provider

View File

@@ -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).

View File

@@ -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()])
```

View File

@@ -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!

View File

@@ -1,4 +1,5 @@
# Support
Whenever you have any questions, you can send email to <long2ice@gmai.com> or open `issue` in `fastapi-admin-pro`
Whenever you have any questions, you can send email to <long2ice@gmai.com> 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.

View File

@@ -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.

View File

@@ -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"]
```

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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