ohmyapi 0.1.10__py3-none-any.whl → 0.1.12__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ohmyapi/builtin/auth/permissions.py +1 -0
- ohmyapi/builtin/auth/routes.py +7 -11
- ohmyapi/cli.py +13 -4
- ohmyapi/core/templates/app/routes.py.j2 +6 -2
- {ohmyapi-0.1.10.dist-info → ohmyapi-0.1.12.dist-info}/METADATA +26 -6
- {ohmyapi-0.1.10.dist-info → ohmyapi-0.1.12.dist-info}/RECORD +8 -8
- {ohmyapi-0.1.10.dist-info → ohmyapi-0.1.12.dist-info}/WHEEL +0 -0
- {ohmyapi-0.1.10.dist-info → ohmyapi-0.1.12.dist-info}/entry_points.txt +0 -0
ohmyapi/builtin/auth/routes.py
CHANGED
@@ -95,7 +95,7 @@ async def require_admin(current_user: User = Depends(get_current_user)) -> User:
|
|
95
95
|
|
96
96
|
async def require_staff(current_user: User = Depends(get_current_user)) -> User:
|
97
97
|
"""Ensure the current user is a staff member."""
|
98
|
-
if not current_user.is_staff:
|
98
|
+
if not current_user.is_admin and not current_user.is_staff:
|
99
99
|
raise HTTPException(403, "Staff privileges required")
|
100
100
|
return current_user
|
101
101
|
|
@@ -152,17 +152,13 @@ async def refresh_token(refresh_token: str):
|
|
152
152
|
return {"access_token": new_access, "token_type": "bearer"}
|
153
153
|
|
154
154
|
|
155
|
+
@router.get("/introspect")
|
156
|
+
async def introspect(token: Dict = Depends(get_token)):
|
157
|
+
return token
|
158
|
+
|
159
|
+
|
155
160
|
@router.get("/me")
|
156
161
|
async def me(user: User = Depends(get_current_user)):
|
157
162
|
"""Return the currently authenticated user."""
|
158
|
-
return
|
159
|
-
"email": user.email,
|
160
|
-
"username": user.username,
|
161
|
-
"is_admin": user.is_admin,
|
162
|
-
"is_staff": user.is_staff,
|
163
|
-
}
|
164
|
-
|
163
|
+
return user
|
165
164
|
|
166
|
-
@router.get("/introspect")
|
167
|
-
async def introspect(token: Dict = Depends(get_token)):
|
168
|
-
return token
|
ohmyapi/cli.py
CHANGED
@@ -16,13 +16,13 @@ Find your loaded project singleton via identifier: `p`
|
|
16
16
|
|
17
17
|
@app.command()
|
18
18
|
def startproject(name: str):
|
19
|
-
"""Create a new OhMyAPI project in the given directory"""
|
19
|
+
"""Create a new OhMyAPI project in the given directory."""
|
20
20
|
scaffolding.startproject(name)
|
21
21
|
|
22
22
|
|
23
23
|
@app.command()
|
24
24
|
def startapp(app_name: str, root: str = "."):
|
25
|
-
"""Create a new app with the given name in your OhMyAPI project"""
|
25
|
+
"""Create a new app with the given name in your OhMyAPI project."""
|
26
26
|
scaffolding.startapp(app_name, root)
|
27
27
|
|
28
28
|
|
@@ -93,6 +93,10 @@ def migrate(app: str = "*", root: str = "."):
|
|
93
93
|
|
94
94
|
@app.command()
|
95
95
|
def createsuperuser(root: str = "."):
|
96
|
+
"""Create a superuser in the DB.
|
97
|
+
|
98
|
+
This requires the presence of `ohmyapi_auth` in your INSTALLED_APPS to work.
|
99
|
+
"""
|
96
100
|
project_path = Path(root).resolve()
|
97
101
|
project = runtime.Project(project_path)
|
98
102
|
if not project.is_app_installed("ohmyapi_auth"):
|
@@ -103,9 +107,14 @@ def createsuperuser(root: str = "."):
|
|
103
107
|
import ohmyapi_auth
|
104
108
|
email = input("E-Mail: ")
|
105
109
|
username = input("Username: ")
|
106
|
-
|
110
|
+
password1, password2 = "foo", "bar"
|
111
|
+
while password1 != password2:
|
112
|
+
password1 = getpass("Password: ")
|
113
|
+
password2 = getpass("Repeat Password: ")
|
114
|
+
if password1 != password2:
|
115
|
+
print("Passwords didn't match!")
|
107
116
|
user = ohmyapi_auth.models.User(email=email, username=username, is_staff=True, is_admin=True)
|
108
|
-
user.set_password(
|
117
|
+
user.set_password(password1)
|
109
118
|
asyncio.run(project.init_orm())
|
110
119
|
asyncio.run(user.save())
|
111
120
|
asyncio.run(project.close_orm())
|
@@ -1,11 +1,15 @@
|
|
1
1
|
from ohmyapi.router import APIRouter
|
2
|
+
|
2
3
|
from . import models
|
3
4
|
|
4
|
-
router = APIRouter
|
5
|
+
# Expose your app's routes via `router = fastapi.APIRouter`.
|
6
|
+
# Use prefixes wisely to avoid cross-app namespace-collisions.
|
7
|
+
# Tags improve the UX of the OpenAPI docs at /docs.
|
8
|
+
router = APIRouter(prefix="/{{ app_name }}", tags=[{{ app_name }}])
|
5
9
|
|
6
10
|
|
7
11
|
@router.get("/")
|
8
|
-
def
|
12
|
+
def hello_world():
|
9
13
|
return {
|
10
14
|
"project": "{{ project_name }}",
|
11
15
|
"app": "{{ app_name }}",
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: ohmyapi
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.12
|
4
4
|
Summary: A Django-like but async web-framework based on FastAPI and TortoiseORM.
|
5
5
|
License-Expression: MIT
|
6
6
|
Keywords: fastapi,tortoise,orm,async,web-framework
|
@@ -158,7 +158,10 @@ from ohmyapi.db.exceptions import DoesNotExist
|
|
158
158
|
|
159
159
|
from .models import Tournament
|
160
160
|
|
161
|
-
router = APIRouter
|
161
|
+
# Expose your app's routes via `router = fastapi.APIRouter`.
|
162
|
+
# Use prefixes wisely to avoid cross-app namespace-collisions.
|
163
|
+
# Tags improve the UX of the OpenAPI docs at /docs.
|
164
|
+
router = APIRouter(prefix="/tournament", tags=['Tournament'])
|
162
165
|
|
163
166
|
|
164
167
|
@router.get("/")
|
@@ -264,8 +267,6 @@ In your `routes.py`:
|
|
264
267
|
|
265
268
|
```python
|
266
269
|
from ohmyapi.router import APIRouter, Depends
|
267
|
-
|
268
|
-
from ohmyapi_auth.models import User
|
269
270
|
from ohmyapi_auth import (
|
270
271
|
models as auth,
|
271
272
|
permissions,
|
@@ -273,7 +274,7 @@ from ohmyapi_auth import (
|
|
273
274
|
|
274
275
|
from .models import Tournament
|
275
276
|
|
276
|
-
router = APIRouter(prefix="/tournament")
|
277
|
+
router = APIRouter(prefix="/tournament", tags=["Tournament"])
|
277
278
|
|
278
279
|
|
279
280
|
@router.get("/")
|
@@ -291,10 +292,11 @@ Use Tortoise's `Manager` to implement model-level permissions.
|
|
291
292
|
|
292
293
|
```python
|
293
294
|
from ohmyapi.db import Manager
|
295
|
+
from ohmyapi_auth.models import User
|
294
296
|
|
295
297
|
|
296
298
|
class TeamManager(Manager):
|
297
|
-
async def for_user(self, user:
|
299
|
+
async def for_user(self, user: User):
|
298
300
|
return await self.filter(members=user).all()
|
299
301
|
|
300
302
|
|
@@ -305,6 +307,24 @@ class Team(Model):
|
|
305
307
|
manager = TeamManager()
|
306
308
|
```
|
307
309
|
|
310
|
+
Use the custom manager in your FastAPI route handler:
|
311
|
+
|
312
|
+
```python
|
313
|
+
from ohmyapi.router import APIRouter
|
314
|
+
from ohmyapi_auth import (
|
315
|
+
models as auth,
|
316
|
+
permissions,
|
317
|
+
)
|
318
|
+
|
319
|
+
router = APIRouter(prefix="/tournament", tags=["Tournament"])
|
320
|
+
|
321
|
+
|
322
|
+
@router.get("/teams")
|
323
|
+
async def teams(user: auth.User = Depends(permissions.require_authenticated)):
|
324
|
+
queryset = Team.for_user(user)
|
325
|
+
return await Tournament.Schema.many.from_queryset(queryset)
|
326
|
+
```
|
327
|
+
|
308
328
|
## Shell
|
309
329
|
|
310
330
|
Similar to Django, you can attach to an interactive shell with your project already loaded inside.
|
@@ -2,15 +2,15 @@ ohmyapi/__init__.py,sha256=UmLNQImTbKvHEgwQB2Wsyl6fq88X92imL9QZYJpQX4I,18
|
|
2
2
|
ohmyapi/__main__.py,sha256=wcCrL4PjG51r5wVKqJhcoJPTLfHW0wNbD31DrUN0MWI,28
|
3
3
|
ohmyapi/builtin/auth/__init__.py,sha256=TY1RKgwWmJ6FKz_v4J3m0Ang69qSmtVDLe4rqjLk4-E,69
|
4
4
|
ohmyapi/builtin/auth/models.py,sha256=Xsxn9m5RTgY2a0PPfW3wTj77ocuuISytdl4ec_TR_kw,1524
|
5
|
-
ohmyapi/builtin/auth/permissions.py,sha256=
|
6
|
-
ohmyapi/builtin/auth/routes.py,sha256=
|
7
|
-
ohmyapi/cli.py,sha256=
|
5
|
+
ohmyapi/builtin/auth/permissions.py,sha256=jf-I2b9rIOw2EF4Kga-_Bz1ZPPHU0vHNaXGrDQSwhSI,145
|
6
|
+
ohmyapi/builtin/auth/routes.py,sha256=iMxmgP6TSpMrtSKf-g7mc60NcOiw8FRkngUroalGCyk,5519
|
7
|
+
ohmyapi/cli.py,sha256=qCGi9GtgybCh_jb_NVwu9dlG9XTbilg6qnXop2IIgC8,3768
|
8
8
|
ohmyapi/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
9
|
ohmyapi/core/runtime.py,sha256=l5zffc4VTwQOo7G9mfiYHsPGapMONRX_jtO_z9QaKHU,8577
|
10
10
|
ohmyapi/core/scaffolding.py,sha256=iMymscokJ-YqzB0ZTC-gcc2T71o73577j9tnb2x8lH8,2572
|
11
11
|
ohmyapi/core/templates/app/__init__.py.j2,sha256=QwVIQVUGZVhdH1d4NrvL7NTsK4-T4cihzYs8UVX2dt4,43
|
12
12
|
ohmyapi/core/templates/app/models.py.j2,sha256=_3w-vFJ5fgsmncsCv34k_wyCMF78jufbSSglns4gbb0,119
|
13
|
-
ohmyapi/core/templates/app/routes.py.j2,sha256=
|
13
|
+
ohmyapi/core/templates/app/routes.py.j2,sha256=o3XEBZDfHRhodx-6rX1ebnKpqqd-QApfw9ggruWl6y8,436
|
14
14
|
ohmyapi/core/templates/project/README.md.j2,sha256=SjR4JIrg-8XRE-UntUDwiw8jDpYitD_UjwoKkYJ7GLw,22
|
15
15
|
ohmyapi/core/templates/project/pyproject.toml.j2,sha256=X0VS6YT9aL3vpHFKPTfLFsdpD8423nY57ySQpSTMxmQ,895
|
16
16
|
ohmyapi/core/templates/project/settings.py.j2,sha256=RBKGB8MZWPM3Bp0a57Y1YrSvSXxh502TUnJqbbu48Ig,138
|
@@ -19,7 +19,7 @@ ohmyapi/db/exceptions.py,sha256=I7AubrdqQF_UvAvzKqz2ve08-BkXHzEWXnwG300StHE,35
|
|
19
19
|
ohmyapi/db/model/__init__.py,sha256=k3StTNuKatpwZo_Z5JBFa-927eJrzibFE8U4SA82asc,32
|
20
20
|
ohmyapi/db/model/model.py,sha256=BajFtLlQ1s0mZ2hj-_JNQhLQmxuVe-Lw2LuW5t2C7Rw,1579
|
21
21
|
ohmyapi/router.py,sha256=hutccsrP9RT8W5O6uBDhOJehwqrkRoPzaUI5zoHPh9A,55
|
22
|
-
ohmyapi-0.1.
|
23
|
-
ohmyapi-0.1.
|
24
|
-
ohmyapi-0.1.
|
25
|
-
ohmyapi-0.1.
|
22
|
+
ohmyapi-0.1.12.dist-info/METADATA,sha256=i8wVhc1RwYUKSXXQmffQCMcuawbKmD07yu48rxK3zOY,8673
|
23
|
+
ohmyapi-0.1.12.dist-info/WHEEL,sha256=M5asmiAlL6HEcOq52Yi5mmk9KmTVjY2RDPtO4p9DMrc,88
|
24
|
+
ohmyapi-0.1.12.dist-info/entry_points.txt,sha256=wb3lw8-meAlpiv1mqcQ3m25ukL7djagU_w89GkrC37k,43
|
25
|
+
ohmyapi-0.1.12.dist-info/RECORD,,
|
File without changes
|
File without changes
|