forked from ITISFoundation/osparc-simcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ webserver API: generate invitation (ITISFoundation#4796)
- Loading branch information
Showing
31 changed files
with
641 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
43 changes: 43 additions & 0 deletions
43
packages/models-library/src/models_library/api_schemas_invitations/invitations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import Any, ClassVar | ||
|
||
from pydantic import BaseModel, Field, HttpUrl | ||
|
||
from ..invitations import InvitationContent, InvitationInputs | ||
|
||
_INPUTS_EXAMPLE: dict[str, Any] = { | ||
"issuer": "issuerid", | ||
"guest": "[email protected]", | ||
"trial_account_days": 2, | ||
} | ||
|
||
|
||
class ApiInvitationInputs(InvitationInputs): | ||
class Config: | ||
schema_extra: ClassVar[dict[str, Any]] = {"example": _INPUTS_EXAMPLE} | ||
|
||
|
||
class ApiInvitationContent(InvitationContent): | ||
class Config: | ||
schema_extra: ClassVar[dict[str, Any]] = { | ||
"example": { | ||
**_INPUTS_EXAMPLE, | ||
"created": "2023-01-11 13:11:47.293595", | ||
} | ||
} | ||
|
||
|
||
class ApiInvitationContentAndLink(ApiInvitationContent): | ||
invitation_url: HttpUrl = Field(..., description="Invitation link") | ||
|
||
class Config: | ||
schema_extra: ClassVar[dict[str, Any]] = { | ||
"example": { | ||
**_INPUTS_EXAMPLE, | ||
"created": "2023-01-11 12:11:47.293595", | ||
"invitation_url": "https://foo.com/#/registration?invitation=1234", | ||
} | ||
} | ||
|
||
|
||
class ApiEncryptedInvitation(BaseModel): | ||
invitation_url: HttpUrl = Field(..., description="Invitation link") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
from datetime import datetime | ||
from typing import Any, ClassVar | ||
|
||
from pydantic import Field | ||
from models_library.products import ProductName | ||
from pydantic import Field, HttpUrl, PositiveInt | ||
|
||
from ..basic_types import NonNegativeDecimal | ||
from ._base import OutputSchema | ||
from ..emails import LowerCaseEmailStr | ||
from ._base import InputSchema, OutputSchema | ||
|
||
|
||
class CreditPriceGet(OutputSchema): | ||
|
@@ -14,10 +17,38 @@ class CreditPriceGet(OutputSchema): | |
"If None, then this product's price is UNDEFINED", | ||
) | ||
|
||
class Config: | ||
class Config(OutputSchema.Config): | ||
schema_extra: ClassVar[dict[str, Any]] = { | ||
"examples": [ | ||
{"productName": "osparc", "usdPerCredit": None}, | ||
{"productName": "osparc", "usdPerCredit": "10"}, | ||
] | ||
} | ||
|
||
|
||
class GenerateInvitation(InputSchema): | ||
guest: LowerCaseEmailStr | ||
trial_account_days: PositiveInt | None = None | ||
|
||
|
||
class InvitationGenerated(OutputSchema): | ||
product_name: ProductName | ||
issuer: LowerCaseEmailStr | ||
guest: LowerCaseEmailStr | ||
trial_account_days: PositiveInt | None = None | ||
created: datetime | ||
invitation_link: HttpUrl | ||
|
||
class Config(OutputSchema.Config): | ||
schema_extra: ClassVar[dict[str, Any]] = { | ||
"examples": [ | ||
{ | ||
"productName": "osparc", | ||
"issuer": "[email protected]", | ||
"guest": "[email protected]", | ||
"trialAccountDays": 7, | ||
"created": "2023-09-27T15:30:00", | ||
"invitationLink": "https://example.com/invitation#1234", | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from datetime import datetime | ||
|
||
from pydantic import BaseModel, Field, PositiveInt | ||
|
||
from .emails import LowerCaseEmailStr | ||
|
||
|
||
class InvitationInputs(BaseModel): | ||
"""Input data necessary to create an invitation""" | ||
|
||
issuer: str = Field( | ||
..., | ||
description="Identifies who issued the invitation. E.g. an email, a service name etc", | ||
min_length=1, | ||
max_length=30, | ||
) | ||
guest: LowerCaseEmailStr = Field( | ||
..., | ||
description="Invitee's email. Note that the registration can ONLY be used with this email", | ||
) | ||
trial_account_days: PositiveInt | None = Field( | ||
None, | ||
description="If set, this invitation will activate a trial account." | ||
"Sets the number of days from creation until the account expires", | ||
) | ||
|
||
|
||
class InvitationContent(InvitationInputs): | ||
"""Data in an invitation""" | ||
|
||
# avoid using default to mark exactly the time | ||
created: datetime = Field(..., description="Timestamp for creation") | ||
|
||
def as_invitation_inputs(self) -> InvitationInputs: | ||
return self.copy(exclude={"created"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.0.1 | ||
1.0.2 |
Oops, something went wrong.