Skip to content

Commit aa98fb3

Browse files
committed
rest shcmeas
1 parent 9710ab4 commit aa98fb3

File tree

2 files changed

+79
-45
lines changed

2 files changed

+79
-45
lines changed

packages/models-library/src/models_library/api_schemas_webserver/users.py

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
from datetime import date
33
from enum import Enum
4-
from typing import Annotated, Any, Literal
4+
from typing import Annotated, Any, Literal, Self
55
from uuid import UUID
66

77
from common_library.basic_types import DEFAULT_FACTORY
@@ -11,53 +11,17 @@
1111
from ..basic_types import IDStr
1212
from ..emails import LowerCaseEmailStr
1313
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
1622
from .groups import MyGroupsGet
1723
from .users_preferences import AggregatedPreferences
1824

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-
6125
#
6226
# MY PROFILE
6327
#
@@ -237,3 +201,38 @@ def _consistency_check(cls, v, info: ValidationInfo):
237201
msg = f"{registered=} and {status=} is not allowed"
238202
raise ValueError(msg)
239203
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)

packages/models-library/src/models_library/users.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Annotated, TypeAlias
2+
from uuid import UUID
23

34
from models_library.basic_types import IDStr
45
from pydantic import BaseModel, ConfigDict, Field, PositiveInt, StringConstraints
@@ -29,3 +30,37 @@ class UserBillingDetails(BaseModel):
2930
phone: str | None
3031

3132
model_config = ConfigDict(from_attributes=True)
33+
34+
35+
#
36+
# THIRD-PARTY TOKENS
37+
#
38+
39+
40+
class UserThirdPartyToken(BaseModel):
41+
"""
42+
Tokens used to access third-party services connected to osparc (e.g. pennsieve, scicrunch, etc)
43+
"""
44+
45+
service: str
46+
token_key: UUID
47+
token_secret: UUID | None = None
48+
49+
model_config = ConfigDict(
50+
json_schema_extra={
51+
"example": {
52+
"service": "github-api-v1",
53+
"token_key": "5f21abf5-c596-47b7-bfd1-c0e436ef1107",
54+
}
55+
}
56+
)
57+
58+
59+
#
60+
# PERMISSIONS
61+
#
62+
63+
64+
class UserPermission(BaseModel):
65+
name: str
66+
allowed: bool

0 commit comments

Comments
 (0)