Skip to content

schemas

ListUniqueAbsolutePathStr = Annotated[list[AbsolutePathStr], AfterValidator(val_unique_list)] module-attribute

List of unique absolute-path-string items.

ListUniqueNonEmptyString = Annotated[list[NonEmptyStr], AfterValidator(val_unique_list)] module-attribute

List of unique non-empty-string items.

ListUniqueNonNegativeInt = Annotated[list[NonNegativeInt], AfterValidator(val_unique_list)] module-attribute

List of unique non-negative-integer items.

NonEmptyStr = Annotated[str, StringConstraints(min_length=1, strip_whitespace=True)] module-attribute

A non-empty string, with no leading/trailing whitespaces.

OAuthAccountRead

Bases: BaseModel

Schema for storing essential OAuthAccount information within UserRead.oauth_accounts.

ATTRIBUTE DESCRIPTION
id

ID of the row in fractal-owned oauthaccount table.

TYPE: int

account_email

Email associated to OAuth account

TYPE: str

oauth_name

Name of the OAuth provider (e.g. github)

TYPE: str

Source code in fractal_server/app/schemas/user.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class OAuthAccountRead(BaseModel):
    """
    Schema for storing essential `OAuthAccount` information within
    `UserRead.oauth_accounts`.

    Attributes:
        id: ID of the row in fractal-owned `oauthaccount` table.
        account_email: Email associated to OAuth account
        oauth_name: Name of the OAuth provider (e.g. `github`)
    """

    id: int
    account_email: str
    oauth_name: str

UserCreate

Bases: BaseUserCreate

Schema for User creation.

ATTRIBUTE DESCRIPTION
profile_id

TYPE: int | None

project_dirs

TYPE: Annotated[ListUniqueAbsolutePathStr, AfterValidator(_validate_cmd_list)]

slurm_accounts

TYPE: list[str]

Source code in fractal_server/app/schemas/user.py
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
class UserCreate(schemas.BaseUserCreate):
    """
    Schema for `User` creation.

    Attributes:
        profile_id:
        project_dirs:
        slurm_accounts:
    """

    profile_id: int | None = None
    project_dirs: Annotated[
        ListUniqueAbsolutePathStr, AfterValidator(_validate_cmd_list)
    ] = Field(min_length=1)
    slurm_accounts: list[str] = Field(default_factory=list)

UserGroupCreate

Bases: BaseModel

Schema for UserGroup creation

ATTRIBUTE DESCRIPTION
name

Group name

TYPE: NonEmptyStr

Source code in fractal_server/app/schemas/user_group.py
40
41
42
43
44
45
46
47
48
49
50
class UserGroupCreate(BaseModel):
    """
    Schema for `UserGroup` creation

    Attributes:
        name: Group name
    """

    model_config = ConfigDict(extra="forbid")

    name: NonEmptyStr

UserGroupRead

Bases: BaseModel

Schema for UserGroup read

NOTE: user_ids does not correspond to a column of the UserGroup table, but it is rather computed dynamically in relevant endpoints.

ATTRIBUTE DESCRIPTION
id

Group ID

TYPE: int

name

Group name

TYPE: str

timestamp_created

Creation timestamp

TYPE: AwareDatetime

user_ids

IDs of users of this group

TYPE: list[int] | None

Source code in fractal_server/app/schemas/user_group.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class UserGroupRead(BaseModel):
    """
    Schema for `UserGroup` read

    NOTE: `user_ids` does not correspond to a column of the `UserGroup` table,
    but it is rather computed dynamically in relevant endpoints.

    Attributes:
        id: Group ID
        name: Group name
        timestamp_created: Creation timestamp
        user_ids: IDs of users of this group
    """

    id: int
    name: str
    timestamp_created: AwareDatetime
    user_ids: list[int] | None = None

    @field_serializer("timestamp_created")
    def serialize_datetime(v: datetime) -> str:
        return v.isoformat()

UserProfileInfo

Bases: BaseModel

ATTRIBUTE DESCRIPTION
has_profile

TYPE: bool

resource_name

TYPE: str | None

profile_name

TYPE: str | None

username

TYPE: str | None

Source code in fractal_server/app/schemas/user.py
128
129
130
131
132
133
134
135
136
137
138
139
140
class UserProfileInfo(BaseModel):
    """
    Attributes:
        has_profile:
        resource_name:
        profile_name:
        username:
    """

    has_profile: bool
    resource_name: str | None = None
    profile_name: str | None = None
    username: str | None = None

UserRead

Bases: BaseUser[int]

Schema for User read from database.

ATTRIBUTE DESCRIPTION
group_ids_names

TYPE: list[tuple[int, str]] | None

oauth_accounts

TYPE: list[OAuthAccountRead]

profile_id

TYPE: int | None

project_dirs

TYPE: list[str]

slurm_accounts

TYPE: list[str]

Source code in fractal_server/app/schemas/user.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class UserRead(schemas.BaseUser[int]):
    """
    Schema for `User` read from database.

    Attributes:
        group_ids_names:
        oauth_accounts:
        profile_id:
        project_dirs:
        slurm_accounts:
    """

    group_ids_names: list[tuple[int, str]] | None = None
    oauth_accounts: list[OAuthAccountRead]
    profile_id: int | None = None
    project_dirs: list[str]
    slurm_accounts: list[str]

UserUpdate

Bases: BaseUserUpdate

Schema for User update.

ATTRIBUTE DESCRIPTION
password

TYPE: NonEmptyStr

email

TYPE: EmailStr

is_active

TYPE: bool

is_superuser

TYPE: bool

is_verified

TYPE: bool

profile_id

TYPE: int | None

project_dirs

TYPE: Annotated[ListUniqueAbsolutePathStr, AfterValidator(_validate_cmd_list)]

slurm_accounts

TYPE: ListUniqueNonEmptyString

Source code in fractal_server/app/schemas/user.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
class UserUpdate(schemas.BaseUserUpdate):
    """
    Schema for `User` update.

    Attributes:
        password:
        email:
        is_active:
        is_superuser:
        is_verified:
        profile_id:
        project_dirs:
        slurm_accounts:
    """

    model_config = ConfigDict(extra="forbid")
    password: NonEmptyStr = None
    email: EmailStr = None
    is_active: bool = None
    is_superuser: bool = None
    is_verified: bool = None
    profile_id: int | None = None
    project_dirs: Annotated[
        ListUniqueAbsolutePathStr, AfterValidator(_validate_cmd_list)
    ] = Field(default=None, min_length=1)
    slurm_accounts: ListUniqueNonEmptyString = None

UserUpdateGroups

Bases: BaseModel

Schema for POST /auth/users/{user_id}/set-groups/

ATTRIBUTE DESCRIPTION
group_ids

TYPE: ListUniqueNonNegativeInt

Source code in fractal_server/app/schemas/user.py
115
116
117
118
119
120
121
122
123
124
125
class UserUpdateGroups(BaseModel):
    """
    Schema for `POST /auth/users/{user_id}/set-groups/`

    Attributes:
        group_ids:
    """

    model_config = ConfigDict(extra="forbid")

    group_ids: ListUniqueNonNegativeInt = Field(min_length=1)

UserUpdateStrict

Bases: BaseModel

Schema for User self-editing.

ATTRIBUTE DESCRIPTION
slurm_accounts

TYPE: ListUniqueNonEmptyString

Source code in fractal_server/app/schemas/user.py
86
87
88
89
90
91
92
93
94
95
class UserUpdateStrict(BaseModel):
    """
    Schema for `User` self-editing.

    Attributes:
        slurm_accounts:
    """

    model_config = ConfigDict(extra="forbid")
    slurm_accounts: ListUniqueNonEmptyString = None

validate_cmd(command, *, allow_char=None, attribute_name='Command')

Assert that the provided command does not contain any of the forbidden characters for commands (fractal_server.string_tools.NOT_ALLOWED_FOR_COMMANDS)

PARAMETER DESCRIPTION
command

command to validate.

TYPE: str

allow_char

chars to accept among the forbidden ones

TYPE: str | None DEFAULT: None

attribute_name

Name of the attribute, to be used in error message.

TYPE: str DEFAULT: 'Command'

Source code in fractal_server/string_tools.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def validate_cmd(
    command: str,
    *,
    allow_char: str | None = None,
    attribute_name: str = "Command",
):
    """
    Assert that the provided `command` does not contain any of the forbidden
    characters for commands
    (fractal_server.string_tools.__NOT_ALLOWED_FOR_COMMANDS__)

    Args:
        command: command to validate.
        allow_char: chars to accept among the forbidden ones
        attribute_name: Name of the attribute, to be used in error message.
    """
    if not isinstance(command, str):
        raise ValueError(f"{command=} is not a string.")
    forbidden = set(__NOT_ALLOWED_FOR_COMMANDS__)
    if allow_char is not None:
        forbidden = forbidden - set(allow_char)
    if not forbidden.isdisjoint(set(command)):
        raise ValueError(
            f"{attribute_name} must not contain any of this characters: "
            f"'{forbidden}'\n"
            f"Provided {attribute_name.lower()}: '{command}'."
        )