amsdal 0.1.26__cp311-cp311-win_amd64.whl → 0.2.0__cp311-cp311-win_amd64.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.
Potentially problematic release.
This version of amsdal might be problematic. Click here for more details.
- amsdal/__about__.py +1 -1
- amsdal/cloud/__init__.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/client.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/client.pyi +46 -2
- amsdal/cloud/constants.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/enums.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/enums.pyi +46 -0
- amsdal/cloud/models/__init__.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/models/base.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/models/base.pyi +156 -0
- amsdal/cloud/services/__init__.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/__init__.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/add_allowlist_ip.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/add_allowlist_ip.pyi +16 -1
- amsdal/cloud/services/actions/add_basic_auth.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/add_basic_auth.pyi +17 -1
- amsdal/cloud/services/actions/add_dependency.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/add_dependency.pyi +16 -1
- amsdal/cloud/services/actions/add_secret.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/add_secret.pyi +17 -1
- amsdal/cloud/services/actions/base.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/base.pyi +71 -3
- amsdal/cloud/services/actions/create_deploy.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/create_deploy.pyi +33 -3
- amsdal/cloud/services/actions/create_env.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/create_env.pyi +15 -1
- amsdal/cloud/services/actions/create_session.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/create_session.pyi +13 -1
- amsdal/cloud/services/actions/delete_allowlist_ip.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/delete_allowlist_ip.pyi +16 -1
- amsdal/cloud/services/actions/delete_basic_auth.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/delete_basic_auth.pyi +17 -1
- amsdal/cloud/services/actions/delete_dependency.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/delete_dependency.pyi +18 -1
- amsdal/cloud/services/actions/delete_env.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/delete_env.pyi +17 -1
- amsdal/cloud/services/actions/delete_secret.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/delete_secret.pyi +18 -1
- amsdal/cloud/services/actions/destroy_deploy.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/destroy_deploy.pyi +15 -1
- amsdal/cloud/services/actions/expose_db.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/expose_db.pyi +18 -1
- amsdal/cloud/services/actions/get_basic_auth_credentials.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/get_basic_auth_credentials.pyi +17 -1
- amsdal/cloud/services/actions/get_monitoring_info.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/get_monitoring_info.pyi +17 -1
- amsdal/cloud/services/actions/list_dependencies.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/list_dependencies.pyi +17 -1
- amsdal/cloud/services/actions/list_deploys.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/list_deploys.pyi +15 -1
- amsdal/cloud/services/actions/list_envs.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/list_envs.pyi +16 -1
- amsdal/cloud/services/actions/list_secrets.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/list_secrets.pyi +18 -1
- amsdal/cloud/services/actions/manager.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/manager.pyi +254 -20
- amsdal/cloud/services/actions/signup_action.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/signup_action.pyi +16 -1
- amsdal/cloud/services/actions/update_deploy.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/actions/update_deploy.pyi +15 -1
- amsdal/cloud/services/auth/__init__.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/auth/base.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/auth/credentials.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/auth/credentials.pyi +12 -1
- amsdal/cloud/services/auth/manager.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/auth/manager.pyi +15 -1
- amsdal/cloud/services/auth/signup_service.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/auth/signup_service.pyi +16 -1
- amsdal/cloud/services/auth/token.cp311-win_amd64.pyd +0 -0
- amsdal/cloud/services/auth/token.pyi +15 -1
- amsdal/configs/constants.py +10 -0
- amsdal/configs/constants.pyi +11 -1
- amsdal/configs/main.py +132 -19
- amsdal/configs/main.pyi +140 -10
- amsdal/context/manager.py +39 -0
- amsdal/context/manager.pyi +41 -3
- amsdal/contrib/__init__.cp311-win_amd64.pyd +0 -0
- amsdal/contrib/auth/app.py +12 -0
- amsdal/contrib/auth/app.pyi +12 -1
- amsdal/contrib/auth/lifecycle/consumer.py +53 -0
- amsdal/contrib/auth/lifecycle/consumer.pyi +53 -3
- amsdal/contrib/auth/models/login_session/hooks/pre_init.py +13 -0
- amsdal/contrib/auth/models/login_session/modifiers/display_name.py +8 -0
- amsdal/contrib/auth/models/permission/modifiers/display_name.py +8 -0
- amsdal/contrib/auth/models/user/hooks/post_init.py +13 -0
- amsdal/contrib/auth/models/user/hooks/pre_create.py +6 -0
- amsdal/contrib/auth/models/user/modifiers/display_name.py +8 -0
- amsdal/contrib/auth/settings.py +15 -0
- amsdal/contrib/auth/settings.pyi +14 -0
- amsdal/contrib/frontend_configs/app.py +14 -0
- amsdal/contrib/frontend_configs/app.pyi +14 -1
- amsdal/contrib/frontend_configs/conversion/convert.py +14 -0
- amsdal/contrib/frontend_configs/conversion/convert.pyi +15 -1
- amsdal/contrib/frontend_configs/lifecycle/consumer.py +75 -3
- amsdal/contrib/frontend_configs/lifecycle/consumer.pyi +77 -6
- amsdal/contrib/frontend_configs/models/frontent_config_control_action/properties/action_validate.py +16 -0
- amsdal/contrib/frontend_configs/utils.py +12 -1
- amsdal/contrib/frontend_configs/utils.pyi +12 -1
- amsdal/fixtures/__init__.cp311-win_amd64.pyd +0 -0
- amsdal/fixtures/manager.cp311-win_amd64.pyd +0 -0
- amsdal/fixtures/manager.pyi +90 -8
- amsdal/manager.cp311-win_amd64.pyd +0 -0
- amsdal/manager.pyi +113 -25
- amsdal/migration/__init__.cp311-win_amd64.pyd +0 -0
- amsdal/migration/base_migration_schemas.cp311-win_amd64.pyd +0 -0
- amsdal/migration/base_migration_schemas.pyi +84 -8
- amsdal/migration/data_classes.cp311-win_amd64.pyd +0 -0
- amsdal/migration/data_classes.pyi +104 -4
- amsdal/migration/executors/__init__.cp311-win_amd64.pyd +0 -0
- amsdal/migration/executors/base.cp311-win_amd64.pyd +0 -0
- amsdal/migration/executors/base.pyi +75 -5
- amsdal/migration/executors/default_executor.cp311-win_amd64.pyd +0 -0
- amsdal/migration/executors/default_executor.pyi +82 -10
- amsdal/migration/executors/state_executor.cp311-win_amd64.pyd +0 -0
- amsdal/migration/executors/state_executor.pyi +69 -5
- amsdal/migration/file_migration_executor.cp311-win_amd64.pyd +0 -0
- amsdal/migration/file_migration_executor.pyi +34 -2
- amsdal/migration/file_migration_generator.cp311-win_amd64.pyd +0 -0
- amsdal/migration/file_migration_generator.pyi +102 -10
- amsdal/migration/file_migration_store.cp311-win_amd64.pyd +0 -0
- amsdal/migration/file_migration_store.pyi +36 -8
- amsdal/migration/file_migration_writer.cp311-win_amd64.pyd +0 -0
- amsdal/migration/file_migration_writer.pyi +60 -5
- amsdal/migration/migrations.cp311-win_amd64.pyd +0 -0
- amsdal/migration/migrations.pyi +111 -6
- amsdal/migration/migrations_loader.cp311-win_amd64.pyd +0 -0
- amsdal/migration/migrations_loader.pyi +17 -2
- amsdal/migration/schemas_loaders.cp311-win_amd64.pyd +0 -0
- amsdal/migration/schemas_loaders.pyi +15 -2
- amsdal/migration/utils.cp311-win_amd64.pyd +0 -0
- amsdal/migration/utils.pyi +46 -6
- amsdal/mixins/__init__.cp311-win_amd64.pyd +0 -0
- amsdal/mixins/build_mixin.cp311-win_amd64.pyd +0 -0
- amsdal/mixins/build_mixin.pyi +60 -8
- amsdal/mixins/class_versions_mixin.cp311-win_amd64.pyd +0 -0
- amsdal/mixins/class_versions_mixin.pyi +3 -7
- amsdal/schemas/core/class_object/properties/display_name.py +6 -0
- amsdal/schemas/core/file/hooks/pre_create.py +9 -0
- amsdal/schemas/core/file/hooks/pre_update.py +9 -0
- amsdal/schemas/core/file/properties/from_file.py +12 -0
- amsdal/schemas/core/file/properties/mimetype.py +8 -0
- amsdal/schemas/core/file/properties/to_file.py +12 -0
- amsdal/schemas/core/file/properties/validate_data.py +13 -0
- amsdal/schemas/manager.cp311-win_amd64.pyd +0 -0
- amsdal/schemas/manager.py +53 -2
- amsdal/schemas/manager.pyi +55 -5
- amsdal/services/__init__.cp311-win_amd64.pyd +0 -0
- amsdal/services/transaction_execution.cp311-win_amd64.pyd +0 -0
- amsdal/services/transaction_execution.pyi +52 -3
- amsdal/utils/contrib_paths.py +10 -0
- amsdal/utils/contrib_paths.pyi +11 -1
- amsdal/utils/tests/helpers.py +5 -7
- {amsdal-0.1.26.dist-info → amsdal-0.2.0.dist-info}/METADATA +4 -6
- amsdal-0.2.0.dist-info/RECORD +254 -0
- amsdal/operations/__init__.cp311-win_amd64.pyd +0 -0
- amsdal/operations/__init__.pyi +0 -0
- amsdal/operations/manager.cp311-win_amd64.pyd +0 -0
- amsdal/operations/manager.pyi +0 -24
- amsdal-0.1.26.dist-info/RECORD +0 -258
- {amsdal-0.1.26.dist-info → amsdal-0.2.0.dist-info}/LICENSE.txt +0 -0
- {amsdal-0.1.26.dist-info → amsdal-0.2.0.dist-info}/WHEEL +0 -0
- {amsdal-0.1.26.dist-info → amsdal-0.2.0.dist-info}/license_check.py +0 -0
- {amsdal-0.1.26.dist-info → amsdal-0.2.0.dist-info}/top_level.txt +0 -0
amsdal/context/manager.pyi
CHANGED
|
@@ -4,9 +4,47 @@ from typing import Any
|
|
|
4
4
|
_CONTEXT: ContextVar[dict[str, Any] | None]
|
|
5
5
|
|
|
6
6
|
class AmsdalContextManager:
|
|
7
|
+
"""
|
|
8
|
+
Manages a context for storing and retrieving data.
|
|
9
|
+
|
|
10
|
+
This class provides methods to get, set, and add to a context stored in a
|
|
11
|
+
`ContextVar`. The context is a dictionary that can hold any key-value pairs.
|
|
12
|
+
"""
|
|
7
13
|
@classmethod
|
|
8
|
-
def get_context(cls) -> dict[str, Any]:
|
|
14
|
+
def get_context(cls) -> dict[str, Any]:
|
|
15
|
+
"""
|
|
16
|
+
Retrieves the current context or creates a new one if none exists.
|
|
17
|
+
|
|
18
|
+
This method gets the current context from the `_CONTEXT` variable. If no
|
|
19
|
+
context exists, it creates a new empty context and sets it.
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
dict[str, Any]: The current context.
|
|
23
|
+
"""
|
|
9
24
|
@classmethod
|
|
10
|
-
def set_context(cls, context: dict[str, Any]) -> None:
|
|
25
|
+
def set_context(cls, context: dict[str, Any]) -> None:
|
|
26
|
+
"""
|
|
27
|
+
Sets the context to the provided dictionary.
|
|
28
|
+
|
|
29
|
+
This method sets the `_CONTEXT` variable to the provided context.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
context (dict[str, Any]): The context to set.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
None
|
|
36
|
+
"""
|
|
11
37
|
@classmethod
|
|
12
|
-
def add_to_context(cls, key: str, value: Any) -> None:
|
|
38
|
+
def add_to_context(cls, key: str, value: Any) -> None:
|
|
39
|
+
"""
|
|
40
|
+
Adds a key-value pair to the current context.
|
|
41
|
+
|
|
42
|
+
This method adds the provided key-value pair to the current context.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
key (str): The key to add to the context.
|
|
46
|
+
value (Any): The value to associate with the key.
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
None
|
|
50
|
+
"""
|
|
Binary file
|
amsdal/contrib/auth/app.py
CHANGED
|
@@ -5,7 +5,19 @@ from amsdal.contrib.app_config import AppConfig
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class AuthAppConfig(AppConfig):
|
|
8
|
+
"""
|
|
9
|
+
Configuration class for the authentication application.
|
|
10
|
+
|
|
11
|
+
This class sets up the necessary listeners for various lifecycle events
|
|
12
|
+
related to authentication and permission checks.
|
|
13
|
+
"""
|
|
14
|
+
|
|
8
15
|
def on_ready(self) -> None:
|
|
16
|
+
"""
|
|
17
|
+
Sets up listeners for various lifecycle events.
|
|
18
|
+
|
|
19
|
+
This method adds listeners for server startup, user authentication, and permission checks.
|
|
20
|
+
"""
|
|
9
21
|
from amsdal.contrib.auth.lifecycle.consumer import AuthenticateUserConsumer
|
|
10
22
|
from amsdal.contrib.auth.lifecycle.consumer import CheckAndCreateSuperUserConsumer
|
|
11
23
|
from amsdal.contrib.auth.lifecycle.consumer import CheckPermissionConsumer
|
amsdal/contrib/auth/app.pyi
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
from amsdal.contrib.app_config import AppConfig as AppConfig
|
|
2
2
|
|
|
3
3
|
class AuthAppConfig(AppConfig):
|
|
4
|
-
|
|
4
|
+
"""
|
|
5
|
+
Configuration class for the authentication application.
|
|
6
|
+
|
|
7
|
+
This class sets up the necessary listeners for various lifecycle events
|
|
8
|
+
related to authentication and permission checks.
|
|
9
|
+
"""
|
|
10
|
+
def on_ready(self) -> None:
|
|
11
|
+
"""
|
|
12
|
+
Sets up listeners for various lifecycle events.
|
|
13
|
+
|
|
14
|
+
This method adds listeners for server startup, user authentication, and permission checks.
|
|
15
|
+
"""
|
|
@@ -15,8 +15,22 @@ logger = logging.getLogger(__name__)
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
class CheckAndCreateSuperUserConsumer(LifecycleConsumer):
|
|
18
|
+
"""
|
|
19
|
+
Ensures the existence of a super user in the system.
|
|
20
|
+
|
|
21
|
+
This consumer checks if a super user exists based on the provided email and password
|
|
22
|
+
in the authentication settings. If the super user does not exist, it creates one.
|
|
23
|
+
"""
|
|
24
|
+
|
|
18
25
|
@transaction
|
|
19
26
|
def on_event(self) -> None:
|
|
27
|
+
"""
|
|
28
|
+
Checks for the existence of a super user and creates one if necessary.
|
|
29
|
+
|
|
30
|
+
This method ensures that a super user exists by checking the email and password
|
|
31
|
+
in the authentication settings. If the super user does not exist, it creates one
|
|
32
|
+
with the necessary permissions.
|
|
33
|
+
"""
|
|
20
34
|
from amsdal.contrib.auth.settings import auth_settings
|
|
21
35
|
from models.contrib.permission import Permission # type: ignore[import-not-found]
|
|
22
36
|
from models.contrib.user import User # type: ignore[import-not-found]
|
|
@@ -58,7 +72,26 @@ class CheckAndCreateSuperUserConsumer(LifecycleConsumer):
|
|
|
58
72
|
|
|
59
73
|
|
|
60
74
|
class AuthenticateUserConsumer(LifecycleConsumer):
|
|
75
|
+
"""
|
|
76
|
+
Authenticates a user based on a provided JWT token.
|
|
77
|
+
|
|
78
|
+
This consumer decodes the JWT token from the authorization header and retrieves
|
|
79
|
+
the corresponding user from the database. If the token is invalid or expired,
|
|
80
|
+
it raises an `AuthenticationError`.
|
|
81
|
+
"""
|
|
82
|
+
|
|
61
83
|
def on_event(self, auth_header: str, authentication_info: Any) -> None:
|
|
84
|
+
"""
|
|
85
|
+
Authenticates the user using the provided JWT token.
|
|
86
|
+
|
|
87
|
+
This method decodes the JWT token from the authorization header and retrieves
|
|
88
|
+
the corresponding user from the database. If the token is invalid or expired,
|
|
89
|
+
it raises an `AuthenticationError`.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
auth_header (str): The JWT token from the authorization header.
|
|
93
|
+
authentication_info (Any): The authentication information object to update with the user.
|
|
94
|
+
"""
|
|
62
95
|
from amsdal.contrib.auth.settings import auth_settings
|
|
63
96
|
from models.contrib.user import User # type: ignore[import-not-found]
|
|
64
97
|
|
|
@@ -89,6 +122,13 @@ class AuthenticateUserConsumer(LifecycleConsumer):
|
|
|
89
122
|
|
|
90
123
|
|
|
91
124
|
class CheckPermissionConsumer(LifecycleConsumer):
|
|
125
|
+
"""
|
|
126
|
+
Checks and manages permissions for a given user and object.
|
|
127
|
+
|
|
128
|
+
This consumer prepopulates default permissions, checks class-level permissions,
|
|
129
|
+
and object-level permissions for a given user and object.
|
|
130
|
+
"""
|
|
131
|
+
|
|
92
132
|
def _prepopulate_default_permissions(self, object_class: type[Model], permissions_info: Any) -> None:
|
|
93
133
|
from amsdal.contrib.auth.settings import auth_settings
|
|
94
134
|
from models.contrib.permission import Permission # type: ignore[import-not-found]
|
|
@@ -160,6 +200,19 @@ class CheckPermissionConsumer(LifecycleConsumer):
|
|
|
160
200
|
permissions_info: Any,
|
|
161
201
|
obj: Model | None = None,
|
|
162
202
|
) -> None:
|
|
203
|
+
"""
|
|
204
|
+
Main method to check permissions for a given user and object.
|
|
205
|
+
|
|
206
|
+
This method prepopulates default permissions, checks class-level permissions,
|
|
207
|
+
and object-level permissions for the given user and object.
|
|
208
|
+
|
|
209
|
+
Args:
|
|
210
|
+
object_class (type[Model]): The class of the object to check permissions for.
|
|
211
|
+
user (Any): The user to check permissions for.
|
|
212
|
+
access_types (list[Any]): The list of access types to check.
|
|
213
|
+
permissions_info (Any): The permissions information object to update.
|
|
214
|
+
obj (Model | None): The object to check permissions for, if any.
|
|
215
|
+
"""
|
|
163
216
|
self._prepopulate_default_permissions(object_class, permissions_info)
|
|
164
217
|
self._check_class_permissions(object_class, user, permissions_info)
|
|
165
218
|
|
|
@@ -7,13 +7,63 @@ from typing import Any
|
|
|
7
7
|
logger: Incomplete
|
|
8
8
|
|
|
9
9
|
class CheckAndCreateSuperUserConsumer(LifecycleConsumer):
|
|
10
|
-
|
|
10
|
+
"""
|
|
11
|
+
Ensures the existence of a super user in the system.
|
|
12
|
+
|
|
13
|
+
This consumer checks if a super user exists based on the provided email and password
|
|
14
|
+
in the authentication settings. If the super user does not exist, it creates one.
|
|
15
|
+
"""
|
|
16
|
+
def on_event(self) -> None:
|
|
17
|
+
"""
|
|
18
|
+
Checks for the existence of a super user and creates one if necessary.
|
|
19
|
+
|
|
20
|
+
This method ensures that a super user exists by checking the email and password
|
|
21
|
+
in the authentication settings. If the super user does not exist, it creates one
|
|
22
|
+
with the necessary permissions.
|
|
23
|
+
"""
|
|
11
24
|
|
|
12
25
|
class AuthenticateUserConsumer(LifecycleConsumer):
|
|
13
|
-
|
|
26
|
+
"""
|
|
27
|
+
Authenticates a user based on a provided JWT token.
|
|
28
|
+
|
|
29
|
+
This consumer decodes the JWT token from the authorization header and retrieves
|
|
30
|
+
the corresponding user from the database. If the token is invalid or expired,
|
|
31
|
+
it raises an `AuthenticationError`.
|
|
32
|
+
"""
|
|
33
|
+
def on_event(self, auth_header: str, authentication_info: Any) -> None:
|
|
34
|
+
"""
|
|
35
|
+
Authenticates the user using the provided JWT token.
|
|
36
|
+
|
|
37
|
+
This method decodes the JWT token from the authorization header and retrieves
|
|
38
|
+
the corresponding user from the database. If the token is invalid or expired,
|
|
39
|
+
it raises an `AuthenticationError`.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
auth_header (str): The JWT token from the authorization header.
|
|
43
|
+
authentication_info (Any): The authentication information object to update with the user.
|
|
44
|
+
"""
|
|
14
45
|
|
|
15
46
|
class CheckPermissionConsumer(LifecycleConsumer):
|
|
47
|
+
"""
|
|
48
|
+
Checks and manages permissions for a given user and object.
|
|
49
|
+
|
|
50
|
+
This consumer prepopulates default permissions, checks class-level permissions,
|
|
51
|
+
and object-level permissions for a given user and object.
|
|
52
|
+
"""
|
|
16
53
|
def _prepopulate_default_permissions(self, object_class: type[Model], permissions_info: Any) -> None: ...
|
|
17
54
|
def _check_class_permissions(self, object_class: type[Model], user: Any, permissions_info: Any) -> None: ...
|
|
18
55
|
def _check_object_permissions(self, obj: Model, user: Any, permissions_info: Any) -> None: ...
|
|
19
|
-
def on_event(self, object_class: type[Model], user: Any, access_types: list[Any], permissions_info: Any, obj: Model | None = None) -> None:
|
|
56
|
+
def on_event(self, object_class: type[Model], user: Any, access_types: list[Any], permissions_info: Any, obj: Model | None = None) -> None:
|
|
57
|
+
"""
|
|
58
|
+
Main method to check permissions for a given user and object.
|
|
59
|
+
|
|
60
|
+
This method prepopulates default permissions, checks class-level permissions,
|
|
61
|
+
and object-level permissions for the given user and object.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
object_class (type[Model]): The class of the object to check permissions for.
|
|
65
|
+
user (Any): The user to check permissions for.
|
|
66
|
+
access_types (list[Any]): The list of access types to check.
|
|
67
|
+
permissions_info (Any): The permissions information object to update.
|
|
68
|
+
obj (Model | None): The object to check permissions for, if any.
|
|
69
|
+
"""
|
|
@@ -9,6 +9,19 @@ from amsdal_utils.models.enums import Versions
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
def pre_init(self, *, is_new_object: bool, kwargs: dict[str, Any]) -> None: # type: ignore[no-untyped-def] # noqa: ARG001
|
|
12
|
+
"""
|
|
13
|
+
Pre-initializes a user object by validating email and password, and generating a JWT token.
|
|
14
|
+
|
|
15
|
+
This method checks if the object is new and validates the provided email and password.
|
|
16
|
+
If the email and password are valid, it generates a JWT token and adds it to the kwargs.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
is_new_object (bool): Indicates if the object is new.
|
|
20
|
+
kwargs (dict[str, Any]): The keyword arguments containing user details.
|
|
21
|
+
|
|
22
|
+
Raises:
|
|
23
|
+
AuthenticationError: If the email or password is invalid.
|
|
24
|
+
"""
|
|
12
25
|
if not is_new_object or '_metadata' in kwargs:
|
|
13
26
|
return
|
|
14
27
|
|
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
@property # type: ignore[misc]
|
|
2
2
|
def display_name(self) -> str: # type: ignore[no-untyped-def]
|
|
3
|
+
"""
|
|
4
|
+
Returns the display name of the user.
|
|
5
|
+
|
|
6
|
+
This method returns the email of the user as their display name.
|
|
7
|
+
|
|
8
|
+
Returns:
|
|
9
|
+
str: The email of the user.
|
|
10
|
+
"""
|
|
3
11
|
return self.email
|
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
@property # type: ignore[misc]
|
|
2
2
|
def display_name(self) -> str: # type: ignore[no-untyped-def]
|
|
3
|
+
"""
|
|
4
|
+
Returns the display name of the user.
|
|
5
|
+
|
|
6
|
+
This method returns a formatted string combining the model and action of the user.
|
|
7
|
+
|
|
8
|
+
Returns:
|
|
9
|
+
str: The formatted display name in the format 'model:action'.
|
|
10
|
+
"""
|
|
3
11
|
return f'{self.model}:{self.action}'
|
|
@@ -2,6 +2,19 @@ from typing import Any
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
def post_init(self, *, is_new_object: bool, kwargs: dict[str, Any]) -> None: # type: ignore[no-untyped-def]
|
|
5
|
+
"""
|
|
6
|
+
Post-initializes a user object by validating email and password, and hashing the password.
|
|
7
|
+
|
|
8
|
+
This method checks if the email and password are provided and valid. If the object is new,
|
|
9
|
+
it hashes the password and sets the object ID to the lowercased email.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
is_new_object (bool): Indicates if the object is new.
|
|
13
|
+
kwargs (dict[str, Any]): The keyword arguments containing user details.
|
|
14
|
+
|
|
15
|
+
Raises:
|
|
16
|
+
UserCreationError: If the email or password is invalid.
|
|
17
|
+
"""
|
|
5
18
|
import bcrypt
|
|
6
19
|
|
|
7
20
|
from amsdal.contrib.auth.errors import UserCreationError
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
@property # type: ignore[misc]
|
|
2
2
|
def display_name(self) -> str: # type: ignore[no-untyped-def]
|
|
3
|
+
"""
|
|
4
|
+
Returns the display name of the user.
|
|
5
|
+
|
|
6
|
+
This method returns the email of the user as their display name.
|
|
7
|
+
|
|
8
|
+
Returns:
|
|
9
|
+
str: The email of the user.
|
|
10
|
+
"""
|
|
3
11
|
return self.email
|
|
4
12
|
|
|
5
13
|
|
amsdal/contrib/auth/settings.py
CHANGED
|
@@ -3,6 +3,21 @@ from pydantic_settings import SettingsConfigDict
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
class Settings(BaseSettings):
|
|
6
|
+
"""
|
|
7
|
+
Settings configuration for the application.
|
|
8
|
+
|
|
9
|
+
This class uses Pydantic's BaseSettings to manage application settings
|
|
10
|
+
from environment variables and a .env file.
|
|
11
|
+
|
|
12
|
+
Attributes:
|
|
13
|
+
model_config (SettingsConfigDict): Configuration for Pydantic settings.
|
|
14
|
+
ADMIN_USER_EMAIL (str | None): The email of the admin user.
|
|
15
|
+
ADMIN_USER_PASSWORD (str | None): The password of the admin user.
|
|
16
|
+
AUTH_JWT_KEY (str | None): The key used for JWT authentication.
|
|
17
|
+
AUTH_TOKEN_EXPIRATION (int): The expiration time for authentication tokens in seconds.
|
|
18
|
+
REQUIRE_DEFAULT_AUTHORIZATION (bool): Flag to require default authorization.
|
|
19
|
+
"""
|
|
20
|
+
|
|
6
21
|
model_config = SettingsConfigDict(
|
|
7
22
|
case_sensitive=True,
|
|
8
23
|
env_prefix='AMSDAL_',
|
amsdal/contrib/auth/settings.pyi
CHANGED
|
@@ -2,6 +2,20 @@ from _typeshed import Incomplete
|
|
|
2
2
|
from pydantic_settings import BaseSettings
|
|
3
3
|
|
|
4
4
|
class Settings(BaseSettings):
|
|
5
|
+
"""
|
|
6
|
+
Settings configuration for the application.
|
|
7
|
+
|
|
8
|
+
This class uses Pydantic's BaseSettings to manage application settings
|
|
9
|
+
from environment variables and a .env file.
|
|
10
|
+
|
|
11
|
+
Attributes:
|
|
12
|
+
model_config (SettingsConfigDict): Configuration for Pydantic settings.
|
|
13
|
+
ADMIN_USER_EMAIL (str | None): The email of the admin user.
|
|
14
|
+
ADMIN_USER_PASSWORD (str | None): The password of the admin user.
|
|
15
|
+
AUTH_JWT_KEY (str | None): The key used for JWT authentication.
|
|
16
|
+
AUTH_TOKEN_EXPIRATION (int): The expiration time for authentication tokens in seconds.
|
|
17
|
+
REQUIRE_DEFAULT_AUTHORIZATION (bool): Flag to require default authorization.
|
|
18
|
+
"""
|
|
5
19
|
model_config: Incomplete
|
|
6
20
|
ADMIN_USER_EMAIL: str | None
|
|
7
21
|
ADMIN_USER_PASSWORD: str | None
|
|
@@ -6,5 +6,19 @@ from amsdal.contrib.frontend_configs.lifecycle.consumer import ProcessResponseCo
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class FrontendConfigAppConfig(AppConfig):
|
|
9
|
+
"""
|
|
10
|
+
Application configuration class for frontend configurations.
|
|
11
|
+
|
|
12
|
+
This class extends the AppConfig and sets up listeners for lifecycle events
|
|
13
|
+
to process frontend configurations.
|
|
14
|
+
"""
|
|
15
|
+
|
|
9
16
|
def on_ready(self) -> None:
|
|
17
|
+
"""
|
|
18
|
+
Registers a listener for the ON_RESPONSE_EVENT to process responses
|
|
19
|
+
using the ProcessResponseConsumer.
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
None
|
|
23
|
+
"""
|
|
10
24
|
LifecycleProducer.add_listener(ON_RESPONSE_EVENT, ProcessResponseConsumer) # type: ignore[arg-type]
|
|
@@ -3,4 +3,17 @@ from amsdal.contrib.frontend_configs.constants import ON_RESPONSE_EVENT as ON_RE
|
|
|
3
3
|
from amsdal.contrib.frontend_configs.lifecycle.consumer import ProcessResponseConsumer as ProcessResponseConsumer
|
|
4
4
|
|
|
5
5
|
class FrontendConfigAppConfig(AppConfig):
|
|
6
|
-
|
|
6
|
+
"""
|
|
7
|
+
Application configuration class for frontend configurations.
|
|
8
|
+
|
|
9
|
+
This class extends the AppConfig and sets up listeners for lifecycle events
|
|
10
|
+
to process frontend configurations.
|
|
11
|
+
"""
|
|
12
|
+
def on_ready(self) -> None:
|
|
13
|
+
"""
|
|
14
|
+
Registers a listener for the ON_RESPONSE_EVENT to process responses
|
|
15
|
+
using the ProcessResponseConsumer.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
None
|
|
19
|
+
"""
|
|
@@ -45,6 +45,20 @@ def _process_union(value: UnionType, *, is_transaction: bool = False) -> dict[st
|
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
def convert_to_frontend_config(value: Any, *, is_transaction: bool = False) -> dict[str, Any]:
|
|
48
|
+
"""
|
|
49
|
+
Converts a given value to a frontend configuration dictionary.
|
|
50
|
+
|
|
51
|
+
This function takes a value and converts it into a dictionary that represents
|
|
52
|
+
the configuration for a frontend form control. It handles various types such as
|
|
53
|
+
Union, list, dict, BaseModel, and custom types.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
value (Any): The value to be converted to frontend configuration.
|
|
57
|
+
is_transaction (bool, optional): Indicates if the conversion is for a transaction. Defaults to False.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
dict[str, Any]: A dictionary representing the frontend configuration for the given value.
|
|
61
|
+
"""
|
|
48
62
|
if hasattr(value, '__origin__'):
|
|
49
63
|
origin_class = value.__origin__
|
|
50
64
|
|
|
@@ -6,4 +6,18 @@ from typing import Any
|
|
|
6
6
|
default_types_map: Incomplete
|
|
7
7
|
|
|
8
8
|
def _process_union(value: UnionType, *, is_transaction: bool = False) -> dict[str, Any]: ...
|
|
9
|
-
def convert_to_frontend_config(value: Any, *, is_transaction: bool = False) -> dict[str, Any]:
|
|
9
|
+
def convert_to_frontend_config(value: Any, *, is_transaction: bool = False) -> dict[str, Any]:
|
|
10
|
+
"""
|
|
11
|
+
Converts a given value to a frontend configuration dictionary.
|
|
12
|
+
|
|
13
|
+
This function takes a value and converts it into a dictionary that represents
|
|
14
|
+
the configuration for a frontend form control. It handles various types such as
|
|
15
|
+
Union, list, dict, BaseModel, and custom types.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
value (Any): The value to be converted to frontend configuration.
|
|
19
|
+
is_transaction (bool, optional): Indicates if the conversion is for a transaction. Defaults to False.
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
dict[str, Any]: A dictionary representing the frontend configuration for the given value.
|
|
23
|
+
"""
|
|
@@ -3,11 +3,11 @@ import logging
|
|
|
3
3
|
from typing import Any
|
|
4
4
|
|
|
5
5
|
from amsdal_models.classes.errors import AmsdalClassNotFoundError
|
|
6
|
-
from amsdal_models.schemas.data_models.core import LegacyDictSchema
|
|
7
|
-
from amsdal_models.schemas.data_models.schema import PropertyData
|
|
8
|
-
from amsdal_models.schemas.enums import CoreTypes
|
|
9
6
|
from amsdal_utils.lifecycle.consumer import LifecycleConsumer
|
|
10
7
|
from amsdal_utils.models.data_models.address import Address
|
|
8
|
+
from amsdal_utils.models.data_models.core import LegacyDictSchema
|
|
9
|
+
from amsdal_utils.models.data_models.enums import CoreTypes
|
|
10
|
+
from amsdal_utils.models.data_models.schema import PropertyData
|
|
11
11
|
from amsdal_utils.models.enums import SchemaTypes
|
|
12
12
|
from amsdal_utils.models.enums import Versions
|
|
13
13
|
|
|
@@ -25,6 +25,20 @@ core_to_frontend_types = {
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
def process_property(field_name: str, property_data: PropertyData) -> dict[str, Any]:
|
|
28
|
+
"""
|
|
29
|
+
Processes a property and converts it to a frontend configuration dictionary.
|
|
30
|
+
|
|
31
|
+
This function takes a field name and property data, and converts them into a dictionary
|
|
32
|
+
that represents the configuration for a frontend form control. It handles various types
|
|
33
|
+
such as core types, arrays, dictionaries, and files.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
field_name (str): The name of the field to be processed.
|
|
37
|
+
property_data (PropertyData): The property data to be processed.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
dict[str, Any]: A dictionary representing the frontend configuration for the given property.
|
|
41
|
+
"""
|
|
28
42
|
type_definition: dict[str, Any]
|
|
29
43
|
if property_data.type in core_to_frontend_types:
|
|
30
44
|
type_definition = {
|
|
@@ -92,6 +106,20 @@ def process_property(field_name: str, property_data: PropertyData) -> dict[str,
|
|
|
92
106
|
|
|
93
107
|
|
|
94
108
|
def populate_frontend_config_with_values(config: dict[str, Any], values: dict[str, Any]) -> dict[str, Any]:
|
|
109
|
+
"""
|
|
110
|
+
Populates a frontend configuration dictionary with values.
|
|
111
|
+
|
|
112
|
+
This function takes a frontend configuration dictionary and a dictionary of values,
|
|
113
|
+
and populates the configuration with the corresponding values. It recursively processes
|
|
114
|
+
nested controls to ensure all values are populated.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
config (dict[str, Any]): The frontend configuration dictionary to be populated.
|
|
118
|
+
values (dict[str, Any]): The dictionary of values to populate the configuration with.
|
|
119
|
+
|
|
120
|
+
Returns:
|
|
121
|
+
dict[str, Any]: The populated frontend configuration dictionary.
|
|
122
|
+
"""
|
|
95
123
|
if config.get('controls') and isinstance(config['controls'], list):
|
|
96
124
|
for control in config['controls']:
|
|
97
125
|
populate_frontend_config_with_values(control, values)
|
|
@@ -102,6 +130,19 @@ def populate_frontend_config_with_values(config: dict[str, Any], values: dict[st
|
|
|
102
130
|
|
|
103
131
|
|
|
104
132
|
def get_values_from_response(response: dict[str, Any] | list[dict[str, Any]]) -> dict[str, Any]:
|
|
133
|
+
"""
|
|
134
|
+
Extracts values from a response dictionary or list of dictionaries.
|
|
135
|
+
|
|
136
|
+
This function processes a response to extract the relevant values. It checks if the response
|
|
137
|
+
is a dictionary containing a 'rows' key and processes the rows to find the appropriate values.
|
|
138
|
+
If the response is not in the expected format, it returns an empty dictionary.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
response (dict[str, Any] | list[dict[str, Any]]): The response to extract values from.
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
dict[str, Any]: A dictionary containing the extracted values.
|
|
145
|
+
"""
|
|
105
146
|
if not isinstance(response, dict) or 'rows' not in response or not response['rows']:
|
|
106
147
|
return {}
|
|
107
148
|
|
|
@@ -113,6 +154,19 @@ def get_values_from_response(response: dict[str, Any] | list[dict[str, Any]]) ->
|
|
|
113
154
|
|
|
114
155
|
|
|
115
156
|
def get_default_control(class_name: str) -> dict[str, Any]:
|
|
157
|
+
"""
|
|
158
|
+
Retrieves the default frontend control configuration for a given class name.
|
|
159
|
+
|
|
160
|
+
This function attempts to import a class by its name from various schema types.
|
|
161
|
+
If the class is found, it converts it to a frontend configuration dictionary
|
|
162
|
+
and returns it. If the class is not found, it returns an empty dictionary.
|
|
163
|
+
|
|
164
|
+
Args:
|
|
165
|
+
class_name (str): The name of the class to retrieve the default control for.
|
|
166
|
+
|
|
167
|
+
Returns:
|
|
168
|
+
dict[str, Any]: A dictionary representing the frontend control configuration for the given class.
|
|
169
|
+
"""
|
|
116
170
|
from amsdal_models.classes.manager import ClassManager
|
|
117
171
|
|
|
118
172
|
from amsdal.contrib.frontend_configs.conversion import convert_to_frontend_config
|
|
@@ -135,11 +189,29 @@ def get_default_control(class_name: str) -> dict[str, Any]:
|
|
|
135
189
|
|
|
136
190
|
|
|
137
191
|
class ProcessResponseConsumer(LifecycleConsumer):
|
|
192
|
+
"""
|
|
193
|
+
Consumer class for processing responses and populating frontend configurations.
|
|
194
|
+
|
|
195
|
+
This class extends the LifecycleConsumer and processes responses to populate
|
|
196
|
+
frontend configurations based on the class name and values extracted from the response.
|
|
197
|
+
"""
|
|
198
|
+
|
|
138
199
|
def on_event(
|
|
139
200
|
self,
|
|
140
201
|
request: Any,
|
|
141
202
|
response: dict[str, Any],
|
|
142
203
|
) -> None:
|
|
204
|
+
"""
|
|
205
|
+
Handles the event by extracting the class name and values from the request and response,
|
|
206
|
+
and populates the frontend configuration accordingly.
|
|
207
|
+
|
|
208
|
+
Args:
|
|
209
|
+
request (Any): The request object containing query and path parameters.
|
|
210
|
+
response (dict[str, Any]): The response dictionary to be processed.
|
|
211
|
+
|
|
212
|
+
Returns:
|
|
213
|
+
None
|
|
214
|
+
"""
|
|
143
215
|
from models.contrib.frontend_model_config import FrontendModelConfig # type: ignore[import-not-found]
|
|
144
216
|
|
|
145
217
|
class_name = None
|