|
1 | 1 | import re |
2 | 2 | from datetime import date |
3 | 3 | from enum import Enum |
4 | | -from typing import Annotated, Any, Literal |
| 4 | +from typing import Annotated, Any, Literal, Self |
5 | 5 | from uuid import UUID |
6 | 6 |
|
7 | 7 | from common_library.basic_types import DEFAULT_FACTORY |
|
11 | 11 | from ..basic_types import IDStr |
12 | 12 | from ..emails import LowerCaseEmailStr |
13 | 13 | from ..products import ProductName |
14 | | -from ..users import FirstNameStr, LastNameStr, UserID |
15 | | -from ._base import InputSchema, OutputSchema |
| 14 | +from ..users import ( |
| 15 | + FirstNameStr, |
| 16 | + LastNameStr, |
| 17 | + UserID, |
| 18 | + UserPermission, |
| 19 | + UserThirdPartyToken, |
| 20 | +) |
| 21 | +from ._base import InputSchema, InputSchemaWithoutCamelCase, OutputSchema |
16 | 22 | from .groups import MyGroupsGet |
17 | 23 | from .users_preferences import AggregatedPreferences |
18 | 24 |
|
19 | | - |
20 | | -# |
21 | | -# THIRD-PARTY TOKENS |
22 | | -# |
23 | | -class UserThirdPartyToken(BaseModel): |
24 | | - """ |
25 | | - Tokens used to access third-party services connected to osparc (e.g. pennsieve, scicrunch, etc) |
26 | | - """ |
27 | | - |
28 | | - service: Annotated[ |
29 | | - str, |
30 | | - Field(description="uniquely identifies the service where this token is used"), |
31 | | - ] |
32 | | - token_key: Annotated[UUID, Field(..., description="basic token key")] |
33 | | - token_secret: UUID | None = None |
34 | | - |
35 | | - model_config = ConfigDict( |
36 | | - json_schema_extra={ |
37 | | - "example": { |
38 | | - "service": "github-api-v1", |
39 | | - "token_key": "5f21abf5-c596-47b7-bfd1-c0e436ef1107", |
40 | | - } |
41 | | - } |
42 | | - ) |
43 | | - |
44 | | - |
45 | | -class MyTokenCreate(UserThirdPartyToken): |
46 | | - ... |
47 | | - |
48 | | - |
49 | | -# |
50 | | -# PERMISSIONS |
51 | | -# |
52 | | -class UserPermission(BaseModel): |
53 | | - name: str |
54 | | - allowed: bool |
55 | | - |
56 | | - |
57 | | -class MyPermissionGet(UserPermission, OutputSchema): |
58 | | - ... |
59 | | - |
60 | | - |
61 | 25 | # |
62 | 26 | # MY PROFILE |
63 | 27 | # |
@@ -237,3 +201,38 @@ def _consistency_check(cls, v, info: ValidationInfo): |
237 | 201 | msg = f"{registered=} and {status=} is not allowed" |
238 | 202 | raise ValueError(msg) |
239 | 203 | return v |
| 204 | + |
| 205 | + |
| 206 | +# |
| 207 | +# THIRD-PARTY TOKENS |
| 208 | +# |
| 209 | + |
| 210 | + |
| 211 | +class MyTokenCreate(InputSchemaWithoutCamelCase): |
| 212 | + service: Annotated[ |
| 213 | + str, |
| 214 | + Field(description="uniquely identifies the service where this token is used"), |
| 215 | + ] |
| 216 | + token_key: Annotated[UUID, Field(..., description="basic token key")] |
| 217 | + token_secret: UUID | None = None |
| 218 | + |
| 219 | + def to_model(self) -> UserThirdPartyToken: |
| 220 | + return UserThirdPartyToken( |
| 221 | + service=self.service, |
| 222 | + token_key=self.token_key, |
| 223 | + token_secret=self.token_secret, |
| 224 | + ) |
| 225 | + |
| 226 | + |
| 227 | +# |
| 228 | +# PERMISSIONS |
| 229 | +# |
| 230 | + |
| 231 | + |
| 232 | +class MyPermissionGet(OutputSchema): |
| 233 | + name: str |
| 234 | + allowed: bool |
| 235 | + |
| 236 | + @classmethod |
| 237 | + def from_model(cls, permission: UserPermission) -> Self: |
| 238 | + return cls(name=permission.name, allowed=permission.allowed) |
0 commit comments