Skip to content

security

CLASS DESCRIPTION
OAuthAccount

ORM model for OAuth accounts (oauthaccount database table).

UserGroup

ORM model for the usergroup database table.

UserOAuth

ORM model for the user_oauth database table.

Classes

OAuthAccount

Bases: Base

ORM model for OAuth accounts (oauthaccount database table).

This class is a modification of SQLAlchemyBaseOAuthAccountTable. Original Copyright: 2021 François Voron, released under MIT licence.

ATTRIBUTE DESCRIPTION
id

TYPE: Mapped[int]

user_id

TYPE: Mapped[int]

user

TYPE: Mapped[UserOAuth | None]

oauth_name

TYPE: Mapped[str]

access_token

TYPE: Mapped[str]

expires_at

TYPE: Mapped[int | None]

refresh_token

TYPE: Mapped[str | None]

account_id

TYPE: Mapped[str]

account_email

TYPE: Mapped[str]

Source code in fractal_server/app/models/security.py
class OAuthAccount(Base):
    """
    ORM model for OAuth accounts (`oauthaccount` database table).

    This class is a modification of
    [`SQLAlchemyBaseOAuthAccountTable`](https://github.com/fastapi-users/fastapi-users-db-sqlalchemy/blob/main/fastapi_users_db_sqlalchemy/__init__.py).
    Original Copyright: 2021 François Voron, released under MIT licence.

    Attributes:
        id:
        user_id:
        user:
        oauth_name:
        access_token:
        expires_at:
        refresh_token:
        account_id:
        account_email:
    """

    __tablename__ = "oauthaccount"

    id: Mapped[int] = mapped_column(primary_key=True)
    user_id: Mapped[int] = mapped_column(
        ForeignKey("user_oauth.id"), nullable=False
    )
    user: Mapped["UserOAuth | None"] = relationship(
        back_populates="oauth_accounts"
    )
    oauth_name: Mapped[str] = mapped_column(index=True, nullable=False)
    access_token: Mapped[str] = mapped_column(nullable=False)
    expires_at: Mapped[int | None] = mapped_column(
        nullable=True, default=lambda: None
    )
    refresh_token: Mapped[str | None] = mapped_column(
        nullable=True, default=lambda: None
    )
    account_id: Mapped[str] = mapped_column(index=True, nullable=False)
    account_email: Mapped[str] = mapped_column(nullable=False)

UserGroup

Bases: Base

ORM model for the usergroup database table.

ATTRIBUTE DESCRIPTION
id

ID of the group

TYPE: Mapped[int]

name

Name of the group

TYPE: Mapped[str]

timestamp_created

Time of creation

TYPE: Mapped[datetime]

Source code in fractal_server/app/models/security.py
class UserGroup(Base):
    """
    ORM model for the `usergroup` database table.

    Attributes:
        id: ID of the group
        name: Name of the group
        timestamp_created: Time of creation
    """

    __tablename__ = "usergroup"

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column(unique=True)
    timestamp_created: Mapped[datetime] = mapped_column(
        DateTime(timezone=True), nullable=False, default=get_timestamp
    )

UserOAuth

Bases: Base

ORM model for the user_oauth database table.

This class is a modification of SQLAlchemyBaseUserTable from fastapi_users_db_sqlalchemy. Original Copyright: 2021 François Voron, released under MIT licence.

Note that some class attributes (e.g is_active, is_verified and is_superuser) are the default ones from fastapi-users - see https://fastapi-users.github.io/fastapi-users/latest/configuration/schemas.

ATTRIBUTE DESCRIPTION
id

TYPE: Mapped[int]

email

TYPE: Mapped[str]

hashed_password

TYPE: Mapped[str]

is_active

If this is False, the user has no access to the /api/v2/ endpoints.

TYPE: Mapped[bool]

is_superuser

TYPE: Mapped[bool]

is_verified

If this is False, the user has no access to the /api/v2/ endpoints.

TYPE: Mapped[bool]

oauth_accounts

TYPE: Mapped[list[OAuthAccount]]

profile_id

Foreign key linking the user to a Profile. If this is unset, the user has no access to the /api/v2/ endpoints.

TYPE: Mapped[int | None]

project_dirs

Absolute paths of the user's project directory. This is used (A) as a default base folder for the zarr_dir of new datasets (where the output Zarr are located), and (B) as a folder which is included by default in the paths that a user is allowed to stream (if the fractal-data integration is set up). two goals:

TYPE: Mapped[list[str]]

slurm_accounts

List of SLURM accounts that the user can select upon running a job.

TYPE: Mapped[list[str]]

Source code in fractal_server/app/models/security.py
class UserOAuth(Base):
    """
    ORM model for the `user_oauth` database table.

    This class is a modification of
    [`SQLAlchemyBaseUserTable`](https://github.com/fastapi-users/fastapi-users-db-sqlalchemy/blob/main/fastapi_users_db_sqlalchemy/__init__.py)
    from `fastapi_users_db_sqlalchemy`.
    Original Copyright: 2021 François Voron, released under MIT licence.

    Note that some class attributes (e.g `is_active`, `is_verified` and
    `is_superuser`) are the default ones from `fastapi-users` - see
    https://fastapi-users.github.io/fastapi-users/latest/configuration/schemas.

    Attributes:
        id:
        email:
        hashed_password:
        is_active:
            If this is `False`, the user has no access to the `/api/v2/`
            endpoints.
        is_superuser:
        is_verified:
            If this is `False`, the user has no access to the `/api/v2/`
            endpoints.
        oauth_accounts:
        profile_id:
            Foreign key linking the user to a `Profile`. If this is unset,
            the user has no access to the `/api/v2/` endpoints.
        project_dirs:
            Absolute paths of the user's project directory. This is used (A) as
            a default base folder for the `zarr_dir` of new datasets (where
            the output Zarr are located), and (B) as a folder which is included
            by default in the paths that a user is allowed to stream (if the
            `fractal-data` integration is set up).
            two goals:
        slurm_accounts:
            List of SLURM accounts that the user can select upon running a job.
    """

    __tablename__ = "user_oauth"

    id: Mapped[int] = mapped_column(primary_key=True)

    email: Mapped[str] = mapped_column(unique=True, index=True, nullable=False)
    hashed_password: Mapped[str]
    is_active: Mapped[bool] = mapped_column(default=True, nullable=False)
    is_superuser: Mapped[bool] = mapped_column(default=False, nullable=False)
    is_verified: Mapped[bool] = mapped_column(default=False, nullable=False)
    is_guest: Mapped[bool] = mapped_column(
        BOOLEAN,
        server_default="false",
        nullable=False,
    )

    oauth_accounts: Mapped[list["OAuthAccount"]] = relationship(
        back_populates="user",
        lazy="joined",
        cascade="all, delete",
    )

    profile_id: Mapped[int | None] = mapped_column(
        ForeignKey("profile.id", ondelete="RESTRICT"), default=lambda: None
    )

    project_dirs: Mapped[list[str]] = mapped_column(
        ARRAY(String), nullable=False
    )

    slurm_accounts: Mapped[list[str]] = mapped_column(
        ARRAY(String), nullable=True, server_default="{}"
    )

    __table_args__ = (
        CheckConstraint(
            "NOT (is_superuser AND is_guest)",
            name="superuser_is_not_guest",
        ),
    )

Functions: