-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
109 additions
and
109 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
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
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
91 changes: 91 additions & 0 deletions
91
services/web/server/src/simcore_service_webserver/tags/schemas.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,91 @@ | ||
import re | ||
from datetime import datetime | ||
|
||
from models_library.api_schemas_webserver._base import InputSchema, OutputSchema | ||
from models_library.users import GroupID, UserID | ||
from pydantic import ConstrainedStr, Field, PositiveInt | ||
from servicelib.aiohttp.requests_validation import RequestParams, StrictRequestParams | ||
from servicelib.request_keys import RQT_USERID_KEY | ||
from simcore_postgres_database.utils_tags import TagDict | ||
|
||
|
||
class TagRequestContext(RequestParams): | ||
user_id: UserID = Field(..., alias=RQT_USERID_KEY) # type: ignore[literal-required] | ||
|
||
|
||
class TagPathParams(StrictRequestParams): | ||
tag_id: PositiveInt | ||
|
||
|
||
class ColorStr(ConstrainedStr): | ||
regex = re.compile(r"^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$") | ||
|
||
|
||
class TagUpdate(InputSchema): | ||
name: str | None = None | ||
description: str | None = None | ||
color: ColorStr | None = None | ||
|
||
|
||
class TagCreate(InputSchema): | ||
name: str | ||
description: str | None = None | ||
color: ColorStr | ||
|
||
|
||
class TagAccessRights(OutputSchema): | ||
# NOTE: analogous to GroupAccessRights | ||
read: bool | ||
write: bool | ||
delete: bool | ||
|
||
|
||
class TagGet(OutputSchema): | ||
id: PositiveInt | ||
name: str | ||
description: str | None = None | ||
color: str | ||
|
||
# analogous to UsersGroup | ||
access_rights: TagAccessRights = Field(..., alias="accessRights") | ||
|
||
@classmethod | ||
def from_db(cls, tag: TagDict) -> "TagGet": | ||
# NOTE: cls(access_rights=tag, **tag) would also work because of Config | ||
return cls( | ||
id=tag["id"], | ||
name=tag["name"], | ||
description=tag["description"], | ||
color=tag["color"], | ||
access_rights=TagAccessRights( # type: ignore[call-arg] | ||
read=tag["read"], | ||
write=tag["write"], | ||
delete=tag["delete"], | ||
), | ||
) | ||
|
||
|
||
# | ||
# Share API: GROUPS | ||
# | ||
|
||
|
||
class TagGroupPathParams(TagPathParams): | ||
group_id: GroupID | ||
|
||
|
||
class TagGroupCreate(InputSchema): | ||
read: bool | ||
write: bool | ||
delete: bool | ||
|
||
|
||
class TagGroupGet(OutputSchema): | ||
gid: GroupID | ||
# access | ||
read: bool | ||
write: bool | ||
delete: bool | ||
# timestamps | ||
created: datetime | ||
modified: datetime |