arpakitlib 1.8.36__py3-none-any.whl → 1.8.37__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.
- arpakitlib/_arpakit_project_template_v_5/command/emojize.py +9 -0
- arpakitlib/_arpakit_project_template_v_5/project/api/create_api_app.py +12 -2
- arpakitlib/_arpakit_project_template_v_5/project/api/exception_handler.py +1 -1
- arpakitlib/_arpakit_project_template_v_5/project/api/router/admin/create_operation.py +78 -0
- arpakitlib/_arpakit_project_template_v_5/project/api/router/admin/get_arpakitlib_project_template_info.py +8 -2
- arpakitlib/_arpakit_project_template_v_5/project/api/router/admin/get_auth_data.py +8 -2
- arpakitlib/_arpakit_project_template_v_5/project/api/router/admin/get_operation.py +63 -0
- arpakitlib/_arpakit_project_template_v_5/project/api/router/admin/get_operation_allowed_statuses.py +40 -0
- arpakitlib/_arpakit_project_template_v_5/project/api/router/admin/get_operation_allowed_types.py +40 -0
- arpakitlib/_arpakit_project_template_v_5/project/api/router/admin/get_sqlalchemy_db_table_name_to_amount.py +39 -0
- arpakitlib/_arpakit_project_template_v_5/project/api/router/admin/get_story_log.py +14 -4
- arpakitlib/_arpakit_project_template_v_5/project/api/router/admin/init_sqlalchemy_db.py +8 -2
- arpakitlib/_arpakit_project_template_v_5/project/api/router/admin/main_router.py +27 -1
- arpakitlib/_arpakit_project_template_v_5/project/api/router/admin/raise_fake_error.py +1 -2
- arpakitlib/_arpakit_project_template_v_5/project/api/router/admin/reinit_sqlalchemy_db.py +8 -2
- arpakitlib/_arpakit_project_template_v_5/project/api/router/client/get_current_user.py +11 -3
- arpakitlib/_arpakit_project_template_v_5/project/api/router/client/get_current_user_token.py +10 -3
- arpakitlib/_arpakit_project_template_v_5/project/api/router/client/main_router.py +1 -11
- arpakitlib/_arpakit_project_template_v_5/project/api/router/general/check_authorization.py +46 -0
- arpakitlib/_arpakit_project_template_v_5/project/api/router/{client → general}/get_current_api_key.py +9 -3
- arpakitlib/_arpakit_project_template_v_5/project/api/router/{client → general}/get_errors_info.py +10 -8
- arpakitlib/_arpakit_project_template_v_5/project/api/router/general/healthcheck.py +12 -3
- arpakitlib/_arpakit_project_template_v_5/project/api/router/general/main_router.py +18 -1
- arpakitlib/_arpakit_project_template_v_5/project/api/router/general/now_utc_datetime.py +14 -2
- arpakitlib/_arpakit_project_template_v_5/project/api/schema/common.py +11 -0
- arpakitlib/_arpakit_project_template_v_5/project/api/schema/out/admin/common.py +1 -0
- arpakitlib/_arpakit_project_template_v_5/project/api/schema/out/admin/operation.py +6 -3
- arpakitlib/_arpakit_project_template_v_5/project/api/schema/out/admin/story_log.py +8 -6
- arpakitlib/_arpakit_project_template_v_5/project/api/schema/out/client/common.py +3 -1
- arpakitlib/_arpakit_project_template_v_5/project/api/schema/out/client/user.py +14 -5
- arpakitlib/_arpakit_project_template_v_5/project/api/schema/out/client/user_token.py +5 -3
- arpakitlib/_arpakit_project_template_v_5/project/api/schema/out/{client → general}/api_key.py +5 -3
- arpakitlib/_arpakit_project_template_v_5/project/api/schema/out/general/user.py +31 -0
- arpakitlib/_arpakit_project_template_v_5/project/api/schema/out/general/user_token.py +16 -0
- arpakitlib/_arpakit_project_template_v_5/project/operation_execution/operation_executor_worker.py +2 -2
- arpakitlib/_arpakit_project_template_v_5/project/operation_execution/scheduled_operation_creator_worker.py +2 -1
- arpakitlib/_arpakit_project_template_v_5/project/sandbox/sandbox_1.py +6 -1
- arpakitlib/_arpakit_project_template_v_5/project/sqladmin_/model_view/api_key.py +4 -11
- arpakitlib/_arpakit_project_template_v_5/project/sqladmin_/model_view/common.py +1 -1
- arpakitlib/_arpakit_project_template_v_5/project/sqladmin_/model_view/operation.py +6 -18
- arpakitlib/_arpakit_project_template_v_5/project/sqladmin_/model_view/story_log.py +5 -15
- arpakitlib/_arpakit_project_template_v_5/project/sqladmin_/model_view/user.py +5 -15
- arpakitlib/_arpakit_project_template_v_5/project/sqladmin_/model_view/user_token.py +5 -11
- arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/operation.py +6 -1
- arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/story_log.py +6 -9
- arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/user.py +30 -30
- arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/user_token.py +4 -0
- arpakitlib/_arpakit_project_template_v_5/project/test_data/make_test_api_keys.py +2 -2
- arpakitlib/_arpakit_project_template_v_5/project/tg_bot/blank/{client.py → general.py} +7 -6
- arpakitlib/_arpakit_project_template_v_5/project/tg_bot/const.py +2 -2
- arpakitlib/_arpakit_project_template_v_5/project/tg_bot/kb/inline_/client/hello_world.py +1 -1
- arpakitlib/_arpakit_project_template_v_5/project/tg_bot/kb/static_/client/hello_world.py +1 -1
- arpakitlib/_arpakit_project_template_v_5/project/tg_bot/router/general/about.py +4 -4
- arpakitlib/_arpakit_project_template_v_5/project/tg_bot/router/general/author.py +4 -4
- arpakitlib/_arpakit_project_template_v_5/project/tg_bot/router/general/error_handler.py +2 -2
- arpakitlib/_arpakit_project_template_v_5/project/tg_bot/router/general/healthcheck.py +3 -3
- arpakitlib/_arpakit_project_template_v_5/project/tg_bot/router/general/hello_world.py +3 -3
- arpakitlib/_arpakit_project_template_v_5/project/tg_bot/router/general/raw_callback_query.py +1 -1
- arpakitlib/_arpakit_project_template_v_5/project/tg_bot/router/general/raw_message.py +1 -1
- arpakitlib/_arpakit_project_template_v_5/project/tg_bot/router/general/start.py +4 -4
- arpakitlib/_arpakit_project_template_v_5/project/tg_bot/router/general/support.py +4 -4
- arpakitlib/_arpakit_project_template_v_5/project/tg_bot/util/set_tg_bot_commands.py +14 -14
- arpakitlib/ar_enumeration_util.py +2 -2
- arpakitlib/ar_sqlalchemy_util.py +52 -24
- arpakitlib/ar_str_util.py +6 -0
- arpakitlib/ar_zabbix_api_client_util.py +43 -3
- {arpakitlib-1.8.36.dist-info → arpakitlib-1.8.37.dist-info}/METADATA +1 -1
- {arpakitlib-1.8.36.dist-info → arpakitlib-1.8.37.dist-info}/RECORD +71 -64
- arpakitlib/_arpakit_project_template_v_5/project/api/schema/out/general/errors_info_general.py +0 -6
- arpakitlib/_arpakit_project_template_v_5/project/api/schema/out/general/healthcheck.py +0 -5
- {arpakitlib-1.8.36.dist-info → arpakitlib-1.8.37.dist-info}/LICENSE +0 -0
- {arpakitlib-1.8.36.dist-info → arpakitlib-1.8.37.dist-info}/WHEEL +0 -0
- {arpakitlib-1.8.36.dist-info → arpakitlib-1.8.37.dist-info}/entry_points.txt +0 -0
@@ -1,6 +1,7 @@
|
|
1
1
|
import logging
|
2
2
|
import os
|
3
3
|
|
4
|
+
import starlette.types
|
4
5
|
from fastapi import FastAPI
|
5
6
|
from fastapi.middleware.cors import CORSMiddleware
|
6
7
|
from fastapi.staticfiles import StaticFiles
|
@@ -53,14 +54,23 @@ def create_api_app(*, prefix: str = "/api") -> FastAPI:
|
|
53
54
|
router=main_api_router
|
54
55
|
)
|
55
56
|
|
57
|
+
class _CustomStaticFiles(StaticFiles):
|
58
|
+
async def get_response(self, path: str, scope: starlette.types.Scope):
|
59
|
+
if os.path.isfile(os.path.join(self.directory, path)):
|
60
|
+
headers = {"Content-Disposition": f"attachment; filename={os.path.basename(path)}"}
|
61
|
+
response = await super().get_response(path, scope)
|
62
|
+
response.headers.update(headers)
|
63
|
+
return response
|
64
|
+
return await super().get_response(path, scope)
|
65
|
+
|
56
66
|
if get_cached_settings().media_dirpath is not None:
|
57
67
|
if not os.path.exists(get_cached_settings().media_dirpath):
|
58
68
|
os.makedirs(get_cached_settings().media_dirpath, exist_ok=True)
|
59
|
-
api_app.mount("/media",
|
69
|
+
api_app.mount("/media", _CustomStaticFiles(directory=get_cached_settings().media_dirpath), name="media")
|
60
70
|
|
61
71
|
if not os.path.exists(ProjectPaths.static_dirpath):
|
62
72
|
os.makedirs(ProjectPaths.static_dirpath, exist_ok=True)
|
63
|
-
api_app.mount("/static",
|
73
|
+
api_app.mount("/static", _CustomStaticFiles(directory=ProjectPaths.static_dirpath), name="static")
|
64
74
|
|
65
75
|
if get_cached_settings().api_enable_sqladmin:
|
66
76
|
from project.sqladmin_.add_admin_in_app import add_sqladmin_in_app
|
@@ -214,7 +214,7 @@ def create_story_log_func_before_in_api_exception_handler(
|
|
214
214
|
level=StoryLogDBM.Levels.error,
|
215
215
|
type=StoryLogDBM.Types.error_in_api,
|
216
216
|
title=f"{status_code}, {type(exception)}",
|
217
|
-
|
217
|
+
extra_data={
|
218
218
|
"exception": str(exception),
|
219
219
|
"error_common_so": error_common_so.model_dump(),
|
220
220
|
"exception_traceback": exception_to_traceback_str(exception=exception)
|
@@ -0,0 +1,78 @@
|
|
1
|
+
from typing import Any
|
2
|
+
|
3
|
+
import fastapi
|
4
|
+
from fastapi import APIRouter
|
5
|
+
|
6
|
+
from arpakitlib.ar_type_util import NotSet, is_set
|
7
|
+
from project.api.authorize import require_api_key_dbm_api_authorize_middleware, \
|
8
|
+
require_user_token_dbm_api_authorize_middleware, APIAuthorizeData, api_authorize
|
9
|
+
from project.api.schema.common import BaseRouteSO, BaseSI
|
10
|
+
from project.api.schema.out.admin.operation import OperationAdmin1SO
|
11
|
+
from project.api.schema.out.common.error import ErrorCommonSO
|
12
|
+
from project.sqlalchemy_db_.sqlalchemy_db import get_cached_sqlalchemy_db
|
13
|
+
from project.sqlalchemy_db_.sqlalchemy_model import UserDBM, OperationDBM
|
14
|
+
|
15
|
+
|
16
|
+
class CreateOperationAdminSI(BaseSI):
|
17
|
+
slug: str | None = NotSet
|
18
|
+
type: str
|
19
|
+
title: str | None = NotSet
|
20
|
+
input_data: dict[str, Any] = NotSet
|
21
|
+
|
22
|
+
|
23
|
+
class CreateOperationRouteSO(BaseRouteSO, OperationAdmin1SO):
|
24
|
+
pass
|
25
|
+
|
26
|
+
|
27
|
+
api_router = APIRouter()
|
28
|
+
|
29
|
+
|
30
|
+
@api_router.post(
|
31
|
+
"",
|
32
|
+
name="Create operation",
|
33
|
+
status_code=fastapi.status.HTTP_200_OK,
|
34
|
+
response_model=CreateOperationRouteSO | None | ErrorCommonSO,
|
35
|
+
)
|
36
|
+
async def _(
|
37
|
+
*,
|
38
|
+
request: fastapi.requests.Request,
|
39
|
+
response: fastapi.responses.Response,
|
40
|
+
api_auth_data: APIAuthorizeData = fastapi.Depends(api_authorize(middlewares=[
|
41
|
+
require_api_key_dbm_api_authorize_middleware(
|
42
|
+
require_active=True
|
43
|
+
),
|
44
|
+
require_user_token_dbm_api_authorize_middleware(
|
45
|
+
require_active_user_token=True,
|
46
|
+
require_user_roles=[UserDBM.Roles.admin]
|
47
|
+
)
|
48
|
+
])),
|
49
|
+
create_operation_admin_si: CreateOperationAdminSI = fastapi.Body()
|
50
|
+
):
|
51
|
+
operation_dbm = OperationDBM(
|
52
|
+
status=OperationDBM.Statuses.waiting_for_execution
|
53
|
+
)
|
54
|
+
|
55
|
+
if is_set(create_operation_admin_si.slug):
|
56
|
+
operation_dbm.slug = create_operation_admin_si.slug
|
57
|
+
else:
|
58
|
+
operation_dbm.slug = None
|
59
|
+
|
60
|
+
if is_set(create_operation_admin_si.type):
|
61
|
+
operation_dbm.type = create_operation_admin_si.type
|
62
|
+
|
63
|
+
if is_set(create_operation_admin_si.title):
|
64
|
+
operation_dbm.title = create_operation_admin_si.title
|
65
|
+
else:
|
66
|
+
operation_dbm.title = None
|
67
|
+
|
68
|
+
if is_set(create_operation_admin_si.input_data):
|
69
|
+
operation_dbm.input_data = create_operation_admin_si.input_data
|
70
|
+
else:
|
71
|
+
operation_dbm.input_data = {}
|
72
|
+
|
73
|
+
async with get_cached_sqlalchemy_db().new_async_session() as async_session:
|
74
|
+
async_session.add(operation_dbm)
|
75
|
+
await async_session.commit()
|
76
|
+
await async_session.refresh(operation_dbm)
|
77
|
+
|
78
|
+
return CreateOperationRouteSO.from_dbm(simple_dbm=operation_dbm)
|
@@ -3,11 +3,17 @@ from fastapi import APIRouter
|
|
3
3
|
|
4
4
|
from project.api.authorize import require_user_token_dbm_api_authorize_middleware, APIAuthorizeData, \
|
5
5
|
api_authorize, require_api_key_dbm_api_authorize_middleware
|
6
|
+
from project.api.schema.common import BaseRouteSO
|
6
7
|
from project.api.schema.out.common.error import ErrorCommonSO
|
7
8
|
from project.api.schema.out.common.raw_data import RawDataCommonSO
|
8
9
|
from project.sqlalchemy_db_.sqlalchemy_model import UserDBM
|
9
10
|
from project.util.arpakitlib_project_template import get_arpakitlib_project_template_info
|
10
11
|
|
12
|
+
|
13
|
+
class GetArpakitlibProjectTemplateInfoRouteSO(BaseRouteSO, RawDataCommonSO):
|
14
|
+
pass
|
15
|
+
|
16
|
+
|
11
17
|
api_router = APIRouter()
|
12
18
|
|
13
19
|
|
@@ -15,7 +21,7 @@ api_router = APIRouter()
|
|
15
21
|
"",
|
16
22
|
name="Get arpakitlib project template info",
|
17
23
|
status_code=fastapi.status.HTTP_200_OK,
|
18
|
-
response_model=
|
24
|
+
response_model=GetArpakitlibProjectTemplateInfoRouteSO | ErrorCommonSO
|
19
25
|
)
|
20
26
|
async def _(
|
21
27
|
*,
|
@@ -31,4 +37,4 @@ async def _(
|
|
31
37
|
]))
|
32
38
|
):
|
33
39
|
arpakitlib_project_template_data = get_arpakitlib_project_template_info()
|
34
|
-
return
|
40
|
+
return GetArpakitlibProjectTemplateInfoRouteSO(data=arpakitlib_project_template_data)
|
@@ -4,10 +4,16 @@ from fastapi import APIRouter
|
|
4
4
|
from arpakitlib.ar_json_util import transfer_data_to_json_str_to_data
|
5
5
|
from project.api.authorize import APIAuthorizeData, api_authorize, require_user_token_dbm_api_authorize_middleware, \
|
6
6
|
require_api_key_dbm_api_authorize_middleware
|
7
|
+
from project.api.schema.common import BaseRouteSO
|
7
8
|
from project.api.schema.out.common.error import ErrorCommonSO
|
8
9
|
from project.api.schema.out.common.raw_data import RawDataCommonSO
|
9
10
|
from project.sqlalchemy_db_.sqlalchemy_model import UserDBM
|
10
11
|
|
12
|
+
|
13
|
+
class GetAuthDataRouteSO(BaseRouteSO, RawDataCommonSO):
|
14
|
+
pass
|
15
|
+
|
16
|
+
|
11
17
|
api_router = APIRouter()
|
12
18
|
|
13
19
|
|
@@ -15,7 +21,7 @@ api_router = APIRouter()
|
|
15
21
|
path="",
|
16
22
|
name="Get auth data",
|
17
23
|
status_code=fastapi.status.HTTP_200_OK,
|
18
|
-
response_model=
|
24
|
+
response_model=GetAuthDataRouteSO | ErrorCommonSO,
|
19
25
|
)
|
20
26
|
async def _(
|
21
27
|
*,
|
@@ -31,4 +37,4 @@ async def _(
|
|
31
37
|
)
|
32
38
|
]))
|
33
39
|
):
|
34
|
-
return
|
40
|
+
return GetAuthDataRouteSO(data=transfer_data_to_json_str_to_data(api_auth_data.model_dump()))
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import fastapi.requests
|
2
|
+
import sqlalchemy
|
3
|
+
from fastapi import APIRouter
|
4
|
+
|
5
|
+
from arpakitlib.ar_str_util import strip_if_not_none, make_none_if_blank
|
6
|
+
from project.api.authorize import APIAuthorizeData, api_authorize, require_user_token_dbm_api_authorize_middleware, \
|
7
|
+
require_api_key_dbm_api_authorize_middleware
|
8
|
+
from project.api.schema.common import BaseRouteSO
|
9
|
+
from project.api.schema.out.admin.operation import OperationAdmin1SO
|
10
|
+
from project.api.schema.out.common.error import ErrorCommonSO
|
11
|
+
from project.sqlalchemy_db_.sqlalchemy_db import get_cached_sqlalchemy_db
|
12
|
+
from project.sqlalchemy_db_.sqlalchemy_model import UserDBM, OperationDBM
|
13
|
+
|
14
|
+
|
15
|
+
class GetOperationRouteSO(BaseRouteSO, OperationAdmin1SO):
|
16
|
+
pass
|
17
|
+
|
18
|
+
|
19
|
+
api_router = APIRouter()
|
20
|
+
|
21
|
+
|
22
|
+
@api_router.get(
|
23
|
+
"",
|
24
|
+
name="Get story log",
|
25
|
+
status_code=fastapi.status.HTTP_200_OK,
|
26
|
+
response_model=GetOperationRouteSO | None | ErrorCommonSO,
|
27
|
+
)
|
28
|
+
async def _(
|
29
|
+
*,
|
30
|
+
request: fastapi.requests.Request,
|
31
|
+
response: fastapi.responses.Response,
|
32
|
+
api_auth_data: APIAuthorizeData = fastapi.Depends(api_authorize(middlewares=[
|
33
|
+
require_api_key_dbm_api_authorize_middleware(
|
34
|
+
require_active=True
|
35
|
+
),
|
36
|
+
require_user_token_dbm_api_authorize_middleware(
|
37
|
+
require_active_user_token=True,
|
38
|
+
require_user_roles=[UserDBM.Roles.admin]
|
39
|
+
)
|
40
|
+
])),
|
41
|
+
filter_id: int | None = fastapi.Query(default=None),
|
42
|
+
filter_long_id: str | None = fastapi.Query(default=None),
|
43
|
+
filter_slug: str | None = fastapi.Query(default=None),
|
44
|
+
):
|
45
|
+
filter_long_id = make_none_if_blank(strip_if_not_none(filter_long_id))
|
46
|
+
filter_slug = make_none_if_blank(strip_if_not_none(filter_slug))
|
47
|
+
|
48
|
+
if filter_id is None and filter_long_id is None and filter_slug is None:
|
49
|
+
return None
|
50
|
+
|
51
|
+
query = sqlalchemy.select(OperationDBM)
|
52
|
+
if filter_id is not None:
|
53
|
+
query = query.filter(OperationDBM.id == filter_id)
|
54
|
+
if filter_long_id is not None:
|
55
|
+
query = query.filter(OperationDBM.long_id == filter_long_id)
|
56
|
+
if filter_slug is not None:
|
57
|
+
query = query.filter(OperationDBM.slug == filter_slug)
|
58
|
+
|
59
|
+
async with get_cached_sqlalchemy_db().new_async_session() as async_session:
|
60
|
+
result = await async_session.scalar(query)
|
61
|
+
if result is None:
|
62
|
+
return None
|
63
|
+
return GetOperationRouteSO.from_dbm(simple_dbm=result)
|
arpakitlib/_arpakit_project_template_v_5/project/api/router/admin/get_operation_allowed_statuses.py
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
import fastapi.requests
|
2
|
+
from fastapi import APIRouter
|
3
|
+
|
4
|
+
from project.api.authorize import APIAuthorizeData, api_authorize, require_api_key_dbm_api_authorize_middleware, \
|
5
|
+
require_user_token_dbm_api_authorize_middleware
|
6
|
+
from project.api.schema.common import BaseRouteSO
|
7
|
+
from project.api.schema.out.common.error import ErrorCommonSO
|
8
|
+
from project.sqlalchemy_db_.sqlalchemy_model import OperationDBM, UserDBM
|
9
|
+
|
10
|
+
|
11
|
+
class GetOperationAllowedStatusesRouteSO(BaseRouteSO):
|
12
|
+
allowed_statuses: list[str]
|
13
|
+
|
14
|
+
|
15
|
+
api_router = APIRouter()
|
16
|
+
|
17
|
+
|
18
|
+
@api_router.get(
|
19
|
+
"",
|
20
|
+
name="Get operation allowed statuses",
|
21
|
+
status_code=fastapi.status.HTTP_200_OK,
|
22
|
+
response_model=GetOperationAllowedStatusesRouteSO | ErrorCommonSO,
|
23
|
+
)
|
24
|
+
async def _(
|
25
|
+
*,
|
26
|
+
request: fastapi.requests.Request,
|
27
|
+
response: fastapi.responses.Response,
|
28
|
+
api_auth_data: APIAuthorizeData = fastapi.Depends(api_authorize(middlewares=[
|
29
|
+
require_api_key_dbm_api_authorize_middleware(
|
30
|
+
require_active=True
|
31
|
+
),
|
32
|
+
require_user_token_dbm_api_authorize_middleware(
|
33
|
+
require_active_user_token=True,
|
34
|
+
require_user_roles=[UserDBM.Roles.admin]
|
35
|
+
)
|
36
|
+
]))
|
37
|
+
):
|
38
|
+
return GetOperationAllowedStatusesRouteSO(
|
39
|
+
allowed_statuses=OperationDBM.Statuses.values_list()
|
40
|
+
)
|
arpakitlib/_arpakit_project_template_v_5/project/api/router/admin/get_operation_allowed_types.py
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
import fastapi.requests
|
2
|
+
from fastapi import APIRouter
|
3
|
+
|
4
|
+
from project.api.authorize import APIAuthorizeData, api_authorize, require_api_key_dbm_api_authorize_middleware, \
|
5
|
+
require_user_token_dbm_api_authorize_middleware
|
6
|
+
from project.api.schema.common import BaseRouteSO
|
7
|
+
from project.api.schema.out.common.error import ErrorCommonSO
|
8
|
+
from project.sqlalchemy_db_.sqlalchemy_model import OperationDBM, UserDBM
|
9
|
+
|
10
|
+
|
11
|
+
class GetOperationAllowedTypesRouteSO(BaseRouteSO):
|
12
|
+
allowed_types: list[str]
|
13
|
+
|
14
|
+
|
15
|
+
api_router = APIRouter()
|
16
|
+
|
17
|
+
|
18
|
+
@api_router.get(
|
19
|
+
"",
|
20
|
+
name="Get operation allowed types",
|
21
|
+
status_code=fastapi.status.HTTP_200_OK,
|
22
|
+
response_model=GetOperationAllowedTypesRouteSO | ErrorCommonSO,
|
23
|
+
)
|
24
|
+
async def _(
|
25
|
+
*,
|
26
|
+
request: fastapi.requests.Request,
|
27
|
+
response: fastapi.responses.Response,
|
28
|
+
api_auth_data: APIAuthorizeData = fastapi.Depends(api_authorize(middlewares=[
|
29
|
+
require_api_key_dbm_api_authorize_middleware(
|
30
|
+
require_active=True
|
31
|
+
),
|
32
|
+
require_user_token_dbm_api_authorize_middleware(
|
33
|
+
require_active_user_token=True,
|
34
|
+
require_user_roles=[UserDBM.Roles.admin]
|
35
|
+
)
|
36
|
+
]))
|
37
|
+
):
|
38
|
+
return GetOperationAllowedTypesRouteSO(
|
39
|
+
allowed_types=OperationDBM.Types.values_list()
|
40
|
+
)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import fastapi
|
2
|
+
from fastapi import APIRouter
|
3
|
+
|
4
|
+
from project.api.authorize import require_user_token_dbm_api_authorize_middleware, APIAuthorizeData, \
|
5
|
+
api_authorize, require_api_key_dbm_api_authorize_middleware
|
6
|
+
from project.api.schema.common import BaseRouteSO
|
7
|
+
from project.api.schema.out.common.error import ErrorCommonSO
|
8
|
+
from project.api.schema.out.common.raw_data import RawDataCommonSO
|
9
|
+
from project.sqlalchemy_db_.sqlalchemy_db import get_cached_sqlalchemy_db
|
10
|
+
from project.sqlalchemy_db_.sqlalchemy_model import UserDBM
|
11
|
+
|
12
|
+
|
13
|
+
class GetAuthDataRouteSO(BaseRouteSO, RawDataCommonSO):
|
14
|
+
pass
|
15
|
+
|
16
|
+
|
17
|
+
api_router = APIRouter()
|
18
|
+
|
19
|
+
|
20
|
+
@api_router.get(
|
21
|
+
"",
|
22
|
+
name="Get sqlalchemy db table name to amount",
|
23
|
+
status_code=fastapi.status.HTTP_200_OK,
|
24
|
+
response_model=GetAuthDataRouteSO | ErrorCommonSO
|
25
|
+
)
|
26
|
+
async def _(
|
27
|
+
*,
|
28
|
+
request: fastapi.requests.Request,
|
29
|
+
response: fastapi.responses.Response,
|
30
|
+
api_auth_data: APIAuthorizeData = fastapi.Depends(api_authorize(middlewares=[
|
31
|
+
require_api_key_dbm_api_authorize_middleware(
|
32
|
+
require_active=True
|
33
|
+
), require_user_token_dbm_api_authorize_middleware(
|
34
|
+
require_active_user_token=True,
|
35
|
+
require_user_roles=[UserDBM.Roles.admin]
|
36
|
+
)
|
37
|
+
]))
|
38
|
+
):
|
39
|
+
return GetAuthDataRouteSO(data=await get_cached_sqlalchemy_db().async_get_table_name_to_amount())
|
@@ -2,13 +2,20 @@ import fastapi.requests
|
|
2
2
|
import sqlalchemy
|
3
3
|
from fastapi import APIRouter
|
4
4
|
|
5
|
+
from arpakitlib.ar_str_util import make_none_if_blank, strip_if_not_none
|
5
6
|
from project.api.authorize import APIAuthorizeData, api_authorize, require_user_token_dbm_api_authorize_middleware, \
|
6
7
|
require_api_key_dbm_api_authorize_middleware
|
7
|
-
from project.api.schema.
|
8
|
+
from project.api.schema.common import BaseRouteSO
|
9
|
+
from project.api.schema.out.admin.story_log import StoryLogAdmin1SO
|
8
10
|
from project.api.schema.out.common.error import ErrorCommonSO
|
9
11
|
from project.sqlalchemy_db_.sqlalchemy_db import get_cached_sqlalchemy_db
|
10
12
|
from project.sqlalchemy_db_.sqlalchemy_model import UserDBM, StoryLogDBM
|
11
13
|
|
14
|
+
|
15
|
+
class GetStoryLogRouteSO(BaseRouteSO, StoryLogAdmin1SO):
|
16
|
+
pass
|
17
|
+
|
18
|
+
|
12
19
|
api_router = APIRouter()
|
13
20
|
|
14
21
|
|
@@ -16,7 +23,7 @@ api_router = APIRouter()
|
|
16
23
|
"",
|
17
24
|
name="Get story log",
|
18
25
|
status_code=fastapi.status.HTTP_200_OK,
|
19
|
-
response_model=
|
26
|
+
response_model=GetStoryLogRouteSO | None | ErrorCommonSO,
|
20
27
|
)
|
21
28
|
async def _(
|
22
29
|
*,
|
@@ -35,7 +42,10 @@ async def _(
|
|
35
42
|
filter_long_id: str | None = fastapi.Query(default=None),
|
36
43
|
filter_slug: str | None = fastapi.Query(default=None),
|
37
44
|
):
|
38
|
-
|
45
|
+
filter_long_id = make_none_if_blank(strip_if_not_none(filter_long_id))
|
46
|
+
filter_slug = make_none_if_blank(strip_if_not_none(filter_slug))
|
47
|
+
|
48
|
+
if filter_id is None and filter_long_id is None and filter_slug is None:
|
39
49
|
return None
|
40
50
|
|
41
51
|
query = sqlalchemy.select(StoryLogDBM)
|
@@ -50,4 +60,4 @@ async def _(
|
|
50
60
|
result = await async_session.scalar(query)
|
51
61
|
if result is None:
|
52
62
|
return None
|
53
|
-
return
|
63
|
+
return GetStoryLogRouteSO.from_dbm(simple_dbm=result)
|
@@ -3,11 +3,17 @@ from fastapi import APIRouter
|
|
3
3
|
|
4
4
|
from project.api.authorize import APIAuthorizeData, api_authorize, require_user_token_dbm_api_authorize_middleware, \
|
5
5
|
require_api_key_dbm_api_authorize_middleware, require_not_prod_mode_api_authorize_middleware
|
6
|
+
from project.api.schema.common import BaseRouteSO
|
6
7
|
from project.api.schema.out.common.error import ErrorCommonSO
|
7
8
|
from project.api.schema.out.common.raw_data import RawDataCommonSO
|
8
9
|
from project.sqlalchemy_db_.sqlalchemy_db import get_cached_sqlalchemy_db
|
9
10
|
from project.sqlalchemy_db_.sqlalchemy_model import UserDBM
|
10
11
|
|
12
|
+
|
13
|
+
class InitSqlalchemyDbRouteSO(BaseRouteSO, RawDataCommonSO):
|
14
|
+
pass
|
15
|
+
|
16
|
+
|
11
17
|
api_router = APIRouter()
|
12
18
|
|
13
19
|
|
@@ -15,7 +21,7 @@ api_router = APIRouter()
|
|
15
21
|
path="",
|
16
22
|
name="Init sqlalchemy db",
|
17
23
|
status_code=fastapi.status.HTTP_200_OK,
|
18
|
-
response_model=
|
24
|
+
response_model=InitSqlalchemyDbRouteSO | ErrorCommonSO,
|
19
25
|
)
|
20
26
|
async def _(
|
21
27
|
*,
|
@@ -33,4 +39,4 @@ async def _(
|
|
33
39
|
]))
|
34
40
|
):
|
35
41
|
get_cached_sqlalchemy_db().init()
|
36
|
-
return
|
42
|
+
return InitSqlalchemyDbRouteSO()
|
@@ -1,7 +1,8 @@
|
|
1
1
|
from fastapi import APIRouter
|
2
2
|
|
3
3
|
from project.api.router.admin import get_auth_data, get_arpakitlib_project_template_info, raise_fake_error, \
|
4
|
-
reinit_sqlalchemy_db, get_story_log, init_sqlalchemy_db
|
4
|
+
reinit_sqlalchemy_db, get_story_log, init_sqlalchemy_db, get_sqlalchemy_db_table_name_to_amount, \
|
5
|
+
get_operation_allowed_statuses, get_operation, create_operation, get_operation_allowed_types
|
5
6
|
|
6
7
|
main_admin_api_router = APIRouter()
|
7
8
|
|
@@ -34,3 +35,28 @@ main_admin_api_router.include_router(
|
|
34
35
|
router=init_sqlalchemy_db.api_router,
|
35
36
|
prefix="/init_sqlalchemy_db"
|
36
37
|
)
|
38
|
+
|
39
|
+
main_admin_api_router.include_router(
|
40
|
+
router=get_sqlalchemy_db_table_name_to_amount.api_router,
|
41
|
+
prefix="/get_sqlalchemy_db_table_name_to_amount"
|
42
|
+
)
|
43
|
+
|
44
|
+
main_admin_api_router.include_router(
|
45
|
+
router=get_operation_allowed_statuses.api_router,
|
46
|
+
prefix="/get_operation_allowed_statuses"
|
47
|
+
)
|
48
|
+
|
49
|
+
main_admin_api_router.include_router(
|
50
|
+
router=get_operation_allowed_types.api_router,
|
51
|
+
prefix="/get_operation_allowed_types"
|
52
|
+
)
|
53
|
+
|
54
|
+
main_admin_api_router.include_router(
|
55
|
+
router=get_operation.api_router,
|
56
|
+
prefix="/get_operation"
|
57
|
+
)
|
58
|
+
|
59
|
+
main_admin_api_router.include_router(
|
60
|
+
router=create_operation.api_router,
|
61
|
+
prefix="/create_operation"
|
62
|
+
)
|
@@ -4,7 +4,6 @@ from fastapi import APIRouter
|
|
4
4
|
from project.api.authorize import APIAuthorizeData, api_authorize, require_user_token_dbm_api_authorize_middleware, \
|
5
5
|
require_api_key_dbm_api_authorize_middleware
|
6
6
|
from project.api.schema.out.common.error import ErrorCommonSO
|
7
|
-
from project.api.schema.out.common.raw_data import RawDataCommonSO
|
8
7
|
from project.sqlalchemy_db_.sqlalchemy_model import UserDBM
|
9
8
|
|
10
9
|
api_router = APIRouter()
|
@@ -14,7 +13,7 @@ api_router = APIRouter()
|
|
14
13
|
path="",
|
15
14
|
name="Raise fake error",
|
16
15
|
status_code=fastapi.status.HTTP_200_OK,
|
17
|
-
response_model=
|
16
|
+
response_model=ErrorCommonSO,
|
18
17
|
)
|
19
18
|
async def _(
|
20
19
|
*,
|
@@ -4,11 +4,17 @@ from fastapi import APIRouter
|
|
4
4
|
from project.api.authorize import APIAuthorizeData, api_authorize, require_user_token_dbm_api_authorize_middleware, \
|
5
5
|
require_not_prod_mode_api_authorize_middleware, \
|
6
6
|
require_api_key_dbm_api_authorize_middleware
|
7
|
+
from project.api.schema.common import BaseRouteSO
|
7
8
|
from project.api.schema.out.common.error import ErrorCommonSO
|
8
9
|
from project.api.schema.out.common.raw_data import RawDataCommonSO
|
9
10
|
from project.sqlalchemy_db_.sqlalchemy_db import get_cached_sqlalchemy_db
|
10
11
|
from project.sqlalchemy_db_.sqlalchemy_model import UserDBM
|
11
12
|
|
13
|
+
|
14
|
+
class ReinitSqlalchemyDbRouteSO(BaseRouteSO, RawDataCommonSO):
|
15
|
+
pass
|
16
|
+
|
17
|
+
|
12
18
|
api_router = APIRouter()
|
13
19
|
|
14
20
|
|
@@ -16,7 +22,7 @@ api_router = APIRouter()
|
|
16
22
|
path="",
|
17
23
|
name="Reinit sqlalchemy db",
|
18
24
|
status_code=fastapi.status.HTTP_200_OK,
|
19
|
-
response_model=
|
25
|
+
response_model=ReinitSqlalchemyDbRouteSO | ErrorCommonSO,
|
20
26
|
)
|
21
27
|
async def _(
|
22
28
|
*,
|
@@ -34,4 +40,4 @@ async def _(
|
|
34
40
|
]))
|
35
41
|
):
|
36
42
|
get_cached_sqlalchemy_db().reinit()
|
37
|
-
return
|
43
|
+
return ReinitSqlalchemyDbRouteSO()
|
@@ -1,12 +1,20 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
1
3
|
import fastapi.requests
|
2
4
|
from fastapi import APIRouter
|
3
5
|
|
4
6
|
from project.api.authorize import APIAuthorizeData, api_authorize, require_user_token_dbm_api_authorize_middleware, \
|
5
7
|
require_api_key_dbm_api_authorize_middleware
|
6
|
-
from project.api.schema.
|
8
|
+
from project.api.schema.common import BaseRouteSO
|
9
|
+
from project.api.schema.out.client.user import UserClient1SO
|
7
10
|
from project.api.schema.out.common.error import ErrorCommonSO
|
8
11
|
from project.sqlalchemy_db_.sqlalchemy_model import UserDBM
|
9
12
|
|
13
|
+
|
14
|
+
class GetCurrentUserRouteSO(BaseRouteSO, UserClient1SO):
|
15
|
+
pass
|
16
|
+
|
17
|
+
|
10
18
|
api_router = APIRouter()
|
11
19
|
|
12
20
|
|
@@ -14,7 +22,7 @@ api_router = APIRouter()
|
|
14
22
|
"",
|
15
23
|
name="Get current user",
|
16
24
|
status_code=fastapi.status.HTTP_200_OK,
|
17
|
-
response_model=
|
25
|
+
response_model=GetCurrentUserRouteSO | ErrorCommonSO,
|
18
26
|
)
|
19
27
|
async def _(
|
20
28
|
*,
|
@@ -30,6 +38,6 @@ async def _(
|
|
30
38
|
)
|
31
39
|
]))
|
32
40
|
):
|
33
|
-
return
|
41
|
+
return GetCurrentUserRouteSO.from_dbm(
|
34
42
|
simple_dbm=api_auth_data.user_token_dbm.user
|
35
43
|
)
|
arpakitlib/_arpakit_project_template_v_5/project/api/router/client/get_current_user_token.py
CHANGED
@@ -3,10 +3,17 @@ from fastapi import APIRouter
|
|
3
3
|
|
4
4
|
from project.api.authorize import APIAuthorizeData, api_authorize, require_user_token_dbm_api_authorize_middleware, \
|
5
5
|
require_api_key_dbm_api_authorize_middleware
|
6
|
-
from project.api.schema.
|
6
|
+
from project.api.schema.common import BaseRouteSO
|
7
|
+
from project.api.schema.out.client.user import UserClient1SO
|
8
|
+
from project.api.schema.out.client.user_token import UserTokenClient1SO
|
7
9
|
from project.api.schema.out.common.error import ErrorCommonSO
|
8
10
|
from project.sqlalchemy_db_.sqlalchemy_model import UserDBM
|
9
11
|
|
12
|
+
|
13
|
+
class GetCurrentUserTokenRouteSO(BaseRouteSO, UserTokenClient1SO):
|
14
|
+
user: UserClient1SO
|
15
|
+
|
16
|
+
|
10
17
|
api_router = APIRouter()
|
11
18
|
|
12
19
|
|
@@ -14,7 +21,7 @@ api_router = APIRouter()
|
|
14
21
|
"",
|
15
22
|
name="Get current user token",
|
16
23
|
status_code=fastapi.status.HTTP_200_OK,
|
17
|
-
response_model=
|
24
|
+
response_model=GetCurrentUserTokenRouteSO | ErrorCommonSO,
|
18
25
|
)
|
19
26
|
async def _(
|
20
27
|
*,
|
@@ -30,6 +37,6 @@ async def _(
|
|
30
37
|
)
|
31
38
|
]))
|
32
39
|
):
|
33
|
-
return
|
40
|
+
return GetCurrentUserTokenRouteSO.from_dbm(
|
34
41
|
simple_dbm=api_auth_data.user_token_dbm
|
35
42
|
)
|
@@ -1,14 +1,9 @@
|
|
1
1
|
from fastapi import APIRouter
|
2
2
|
|
3
|
-
from project.api.router.client import
|
3
|
+
from project.api.router.client import get_current_user, get_current_user_token
|
4
4
|
|
5
5
|
main_client_api_router = APIRouter()
|
6
6
|
|
7
|
-
main_client_api_router.include_router(
|
8
|
-
router=get_errors_info.api_router,
|
9
|
-
prefix="/get_errors_info"
|
10
|
-
)
|
11
|
-
|
12
7
|
main_client_api_router.include_router(
|
13
8
|
router=get_current_user.api_router,
|
14
9
|
prefix="/get_current_user"
|
@@ -18,8 +13,3 @@ main_client_api_router.include_router(
|
|
18
13
|
router=get_current_user_token.api_router,
|
19
14
|
prefix="/get_current_user_token"
|
20
15
|
)
|
21
|
-
|
22
|
-
main_client_api_router.include_router(
|
23
|
-
router=get_current_api_key.api_router,
|
24
|
-
prefix="/get_current_api_key"
|
25
|
-
)
|