services#

Services for the teams domain.

Teams domain services.

class app.domain.teams.services.TeamInvitationService(session: ~sqlalchemy.ext.asyncio.session.AsyncSession | ~sqlalchemy.ext.asyncio.scoping.async_scoped_session[~sqlalchemy.ext.asyncio.session.AsyncSession], *, statement: ~sqlalchemy.sql.selectable.Select | None = None, model_type: type[~advanced_alchemy.repository.typing.ModelT] | None = None, repository_type: type[~advanced_alchemy.repository.typing.SQLAlchemyAsyncRepositoryT] | None = None, auto_expunge: bool = False, auto_refresh: bool = True, auto_commit: bool = False, order_by: ~typing.List[tuple[str | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any], bool] | ~sqlalchemy.sql.elements.UnaryExpression[~typing.Any]] | tuple[str | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any], bool] | ~sqlalchemy.sql.elements.UnaryExpression[~typing.Any] | None = None, error_messages: ~advanced_alchemy.exceptions.ErrorMessages | type[~advanced_alchemy.utils.dataclass.Empty] | None = <class 'advanced_alchemy.utils.dataclass.Empty'>, wrap_exceptions: bool = True, load: ~collections.abc.Sequence[~sqlalchemy.orm.interfaces.LoaderOption | ~typing.Literal['*'] | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any] | ~sqlalchemy.orm.relationships.RelationshipProperty[~typing.Any] | ~sqlalchemy.orm.interfaces.MapperProperty[~typing.Any] | ~collections.abc.Sequence[~sqlalchemy.orm.interfaces.LoaderOption | ~typing.Literal['*'] | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any] | ~sqlalchemy.orm.relationships.RelationshipProperty[~typing.Any] | ~sqlalchemy.orm.interfaces.MapperProperty[~typing.Any]]] | ~sqlalchemy.orm.interfaces.LoaderOption | ~typing.Literal['*'] | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any] | ~sqlalchemy.orm.relationships.RelationshipProperty[~typing.Any] | ~sqlalchemy.orm.interfaces.MapperProperty[~typing.Any] | ~sqlalchemy.sql.base.ExecutableOption | ~collections.abc.Sequence[~sqlalchemy.sql.base.ExecutableOption] | None = None, execution_options: dict[str, ~typing.Any] | None = None, uniquify: bool | None = None, count_with_window_function: bool | None = None, **repo_kwargs: ~typing.Any)[source]#

Bases: SQLAlchemyAsyncRepositoryService[TeamInvitation, Any]

Handles team invitations from issue through the invitee’s response.

Configure the service object.

Parameters:
  • session – Session managing the unit-of-work for the operation.

  • statement – To facilitate customization of the underlying select query.

  • model_type – Optional SQLAlchemy model type when instantiating directly without subclassing.

  • repository_type – Optional repository class override when instantiating directly.

  • auto_expunge – Remove object from session before returning.

  • auto_refresh – Refresh object from session before returning.

  • auto_commit – Commit objects before returning.

  • order_by – Set default order options for queries.

  • error_messages – A set of custom error messages to use for operations

  • wrap_exceptions – Wrap exceptions in a RepositoryError

  • load – Set default relationships to be loaded

  • execution_options – Set default execution options

  • uniquify – Optionally apply the unique() method to results before returning.

  • count_with_window_function – When false, list and count will use two queries instead of an analytical window function. Defaults to True in 1.x (planned to change to False in v2.0).

  • **repo_kwargs – passed as keyword args to repo instantiation.

async to_model_on_create(data: service.ModelDictT[m.TeamInvitation]) → service.ModelDictT[m.TeamInvitation][source]#

Resolve inviter metadata before creating an invitation.

Returns:

Normalized invitation payload with inviter fields populated.

async to_model_on_update(data: service.ModelDictT[m.TeamInvitation]) → service.ModelDictT[m.TeamInvitation][source]#

Resolve inviter metadata before updating an invitation.

Returns:

Normalized invitation payload with inviter fields populated.

async to_model_on_upsert(data: service.ModelDictT[m.TeamInvitation]) → service.ModelDictT[m.TeamInvitation][source]#

Resolve inviter metadata before upserting an invitation.

Returns:

Normalized invitation payload with inviter fields populated.

async invite(team: Team, *, email: str, role: TeamRoles, invited_by: User) → TeamInvitation[source]#

Invite the person at email to join team with role, matching members regardless of letter case.

Returns:

The pending invitation.

Raises:

HTTPException – If the invitee is already a member of the team.

async get_for_team(invitation_id: UUID, team_id: UUID) → m.TeamInvitation[source]#

Load an invitation that must have been issued by team_id.

Returns:

The invitation.

Raises:

HTTPException – If the invitation belongs to a different team.

async reject(invitation_id: UUID, *, team_id: UUID, user: m.User) → None[source]#

Delete a team’s invitation on behalf of the invitee who declines it.

Raises:

PermissionDeniedException – If the invitation is addressed to someone other than user.

static is_addressed_to(invitation: TeamInvitation, user: User) → bool[source]#

Return whether invitation was sent to user’s email address, ignoring letter case.

repository_type#

alias of TeamInvitationRepository

class app.domain.teams.services.TeamMemberService(session: ~sqlalchemy.ext.asyncio.session.AsyncSession | ~sqlalchemy.ext.asyncio.scoping.async_scoped_session[~sqlalchemy.ext.asyncio.session.AsyncSession], *, statement: ~sqlalchemy.sql.selectable.Select | None = None, model_type: type[~advanced_alchemy.repository.typing.ModelT] | None = None, repository_type: type[~advanced_alchemy.repository.typing.SQLAlchemyAsyncRepositoryT] | None = None, auto_expunge: bool = False, auto_refresh: bool = True, auto_commit: bool = False, order_by: ~typing.List[tuple[str | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any], bool] | ~sqlalchemy.sql.elements.UnaryExpression[~typing.Any]] | tuple[str | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any], bool] | ~sqlalchemy.sql.elements.UnaryExpression[~typing.Any] | None = None, error_messages: ~advanced_alchemy.exceptions.ErrorMessages | type[~advanced_alchemy.utils.dataclass.Empty] | None = <class 'advanced_alchemy.utils.dataclass.Empty'>, wrap_exceptions: bool = True, load: ~collections.abc.Sequence[~sqlalchemy.orm.interfaces.LoaderOption | ~typing.Literal['*'] | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any] | ~sqlalchemy.orm.relationships.RelationshipProperty[~typing.Any] | ~sqlalchemy.orm.interfaces.MapperProperty[~typing.Any] | ~collections.abc.Sequence[~sqlalchemy.orm.interfaces.LoaderOption | ~typing.Literal['*'] | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any] | ~sqlalchemy.orm.relationships.RelationshipProperty[~typing.Any] | ~sqlalchemy.orm.interfaces.MapperProperty[~typing.Any]]] | ~sqlalchemy.orm.interfaces.LoaderOption | ~typing.Literal['*'] | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any] | ~sqlalchemy.orm.relationships.RelationshipProperty[~typing.Any] | ~sqlalchemy.orm.interfaces.MapperProperty[~typing.Any] | ~sqlalchemy.sql.base.ExecutableOption | ~collections.abc.Sequence[~sqlalchemy.sql.base.ExecutableOption] | None = None, execution_options: dict[str, ~typing.Any] | None = None, uniquify: bool | None = None, count_with_window_function: bool | None = None, **repo_kwargs: ~typing.Any)[source]#

Bases: SQLAlchemyAsyncRepositoryService[TeamMember, Any]

Handles team memberships and the rules that keep every team owned.

Configure the service object.

Parameters:
  • session – Session managing the unit-of-work for the operation.

  • statement – To facilitate customization of the underlying select query.

  • model_type – Optional SQLAlchemy model type when instantiating directly without subclassing.

  • repository_type – Optional repository class override when instantiating directly.

  • auto_expunge – Remove object from session before returning.

  • auto_refresh – Refresh object from session before returning.

  • auto_commit – Commit objects before returning.

  • order_by – Set default order options for queries.

  • error_messages – A set of custom error messages to use for operations

  • wrap_exceptions – Wrap exceptions in a RepositoryError

  • load – Set default relationships to be loaded

  • execution_options – Set default execution options

  • uniquify – Optionally apply the unique() method to results before returning.

  • count_with_window_function – When false, list and count will use two queries instead of an analytical window function. Defaults to True in 1.x (planned to change to False in v2.0).

  • **repo_kwargs – passed as keyword args to repo instantiation.

async add_member(team_id: UUID, user_id: UUID) → m.TeamMember[source]#

Add a user to a team as a regular member.

Returns:

The new membership.

Raises:

IntegrityError – If the user is already a member of the team.

async remove_member(team_id: UUID, user_id: UUID) → None[source]#

Remove a user from a team, failing with IntegrityError when they are not a member.

Raises:

HTTPException – If the user is the sole owner of the team.

async change_role(team_id: UUID, user_id: UUID, role: m.TeamRoles) → m.TeamMember[source]#

Change a member’s role, failing with IntegrityError when the user is not a member.

Returns:

The updated membership.

Raises:

HTTPException – If the change would demote a team owner from the ADMIN role.

repository_type#

alias of TeamMemberRepository

class app.domain.teams.services.TeamService(session: ~sqlalchemy.ext.asyncio.session.AsyncSession | ~sqlalchemy.ext.asyncio.scoping.async_scoped_session[~sqlalchemy.ext.asyncio.session.AsyncSession], *, statement: ~sqlalchemy.sql.selectable.Select | None = None, model_type: type[~advanced_alchemy.repository.typing.ModelT] | None = None, repository_type: type[~advanced_alchemy.repository.typing.SQLAlchemyAsyncRepositoryT] | None = None, auto_expunge: bool = False, auto_refresh: bool = True, auto_commit: bool = False, order_by: ~typing.List[tuple[str | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any], bool] | ~sqlalchemy.sql.elements.UnaryExpression[~typing.Any]] | tuple[str | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any], bool] | ~sqlalchemy.sql.elements.UnaryExpression[~typing.Any] | None = None, error_messages: ~advanced_alchemy.exceptions.ErrorMessages | type[~advanced_alchemy.utils.dataclass.Empty] | None = <class 'advanced_alchemy.utils.dataclass.Empty'>, wrap_exceptions: bool = True, load: ~collections.abc.Sequence[~sqlalchemy.orm.interfaces.LoaderOption | ~typing.Literal['*'] | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any] | ~sqlalchemy.orm.relationships.RelationshipProperty[~typing.Any] | ~sqlalchemy.orm.interfaces.MapperProperty[~typing.Any] | ~collections.abc.Sequence[~sqlalchemy.orm.interfaces.LoaderOption | ~typing.Literal['*'] | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any] | ~sqlalchemy.orm.relationships.RelationshipProperty[~typing.Any] | ~sqlalchemy.orm.interfaces.MapperProperty[~typing.Any]]] | ~sqlalchemy.orm.interfaces.LoaderOption | ~typing.Literal['*'] | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any] | ~sqlalchemy.orm.relationships.RelationshipProperty[~typing.Any] | ~sqlalchemy.orm.interfaces.MapperProperty[~typing.Any] | ~sqlalchemy.sql.base.ExecutableOption | ~collections.abc.Sequence[~sqlalchemy.sql.base.ExecutableOption] | None = None, execution_options: dict[str, ~typing.Any] | None = None, uniquify: bool | None = None, count_with_window_function: bool | None = None, **repo_kwargs: ~typing.Any)[source]#

Bases: SQLAlchemyAsyncRepositoryService[Team, Any]

Handles CRUD operations, unique slugs, tag assignment, and ownership transfer for teams.

Configure the service object.

Parameters:
  • session – Session managing the unit-of-work for the operation.

  • statement – To facilitate customization of the underlying select query.

  • model_type – Optional SQLAlchemy model type when instantiating directly without subclassing.

  • repository_type – Optional repository class override when instantiating directly.

  • auto_expunge – Remove object from session before returning.

  • auto_refresh – Refresh object from session before returning.

  • auto_commit – Commit objects before returning.

  • order_by – Set default order options for queries.

  • error_messages – A set of custom error messages to use for operations

  • wrap_exceptions – Wrap exceptions in a RepositoryError

  • load – Set default relationships to be loaded

  • execution_options – Set default execution options

  • uniquify – Optionally apply the unique() method to results before returning.

  • count_with_window_function – When false, list and count will use two queries instead of an analytical window function. Defaults to True in 1.x (planned to change to False in v2.0).

  • **repo_kwargs – passed as keyword args to repo instantiation.

class Repo(*, statement: ~sqlalchemy.sql.selectable.Select | None = None, session: ~sqlalchemy.ext.asyncio.session.AsyncSession | ~sqlalchemy.ext.asyncio.scoping.async_scoped_session[~sqlalchemy.ext.asyncio.session.AsyncSession], model_type: type[~advanced_alchemy.repository.typing.ModelT] | None = None, auto_expunge: bool = False, auto_refresh: bool = True, auto_commit: bool = False, order_by: ~typing.List[tuple[str | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any], bool] | ~sqlalchemy.sql.elements.UnaryExpression[~typing.Any]] | tuple[str | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any], bool] | ~sqlalchemy.sql.elements.UnaryExpression[~typing.Any] | None = None, error_messages: ~advanced_alchemy.exceptions.ErrorMessages | type[~advanced_alchemy.utils.dataclass.Empty] | None = <class 'advanced_alchemy.utils.dataclass.Empty'>, load: ~collections.abc.Sequence[~sqlalchemy.orm.interfaces.LoaderOption | ~typing.Literal['*'] | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any] | ~sqlalchemy.orm.relationships.RelationshipProperty[~typing.Any] | ~sqlalchemy.orm.interfaces.MapperProperty[~typing.Any] | ~collections.abc.Sequence[~sqlalchemy.orm.interfaces.LoaderOption | ~typing.Literal['*'] | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any] | ~sqlalchemy.orm.relationships.RelationshipProperty[~typing.Any] | ~sqlalchemy.orm.interfaces.MapperProperty[~typing.Any]]] | ~sqlalchemy.orm.interfaces.LoaderOption | ~typing.Literal['*'] | ~sqlalchemy.orm.attributes.InstrumentedAttribute[~typing.Any] | ~sqlalchemy.orm.relationships.RelationshipProperty[~typing.Any] | ~sqlalchemy.orm.interfaces.MapperProperty[~typing.Any] | ~sqlalchemy.sql.base.ExecutableOption | ~collections.abc.Sequence[~sqlalchemy.sql.base.ExecutableOption] | None = None, execution_options: dict[str, ~typing.Any] | None = None, wrap_exceptions: bool = True, uniquify: bool | None = None, count_with_window_function: bool | None = None, cache_manager: CacheManager | None = None, bind_group: str | None = None, **kwargs: ~typing.Any)[source]#

Bases: SQLAlchemyAsyncSlugRepository[Team]

Team SQLAlchemy slug repository.

Repository for SQLAlchemy models.

Parameters:
  • statement – To facilitate customization of the underlying select query.

  • session – Session managing the unit-of-work for the operation.

  • model_type – Optional SQLAlchemy model type when instantiating directly without subclassing.

  • auto_expunge – Remove object from session before returning.

  • auto_refresh – Refresh object from session before returning.

  • auto_commit – Commit objects before returning.

  • order_by – Set default order options for queries.

  • load – Set default relationships to be loaded

  • execution_options – Set default execution options

  • error_messages – A set of custom error messages to use for operations

  • wrap_exceptions – Wrap SQLAlchemy exceptions in a RepositoryError. When set to False, the original exception will be raised.

  • uniquify – Optionally apply the unique() method to results before returning.

  • count_with_window_function – When false, list and count will use two queries instead of an analytical window function. Defaults to True in 1.x (planned to change to False in v2.0).

  • cache_manager – Optional cache manager for repository-level caching. If not provided, retrieved from session.info.

  • bind_group – Optional default routing group to use for all operations. Can be overridden per-method.

  • **kwargs – Additional arguments.

model_type#

alias of Team

repository_type#

alias of Repo

match_fields: ClassVar[List[str] | str | None] = ['name']#

List of dialects that prefer to use field.id = ANY(:1) instead of field.id IN (...).

async to_model_on_create(data: ModelDictT[m.Team]) → ModelDictT[m.Team][source]#

Populate unique slug, initial owner membership, and tags on team creation.

Returns:

Prepared Team model or payload for creation.

async to_model_on_update(data: ModelDictT[m.Team]) → ModelDictT[m.Team][source]#

Populate unique slug and resolve tag associations on team update.

Returns:

Prepared Team model or payload for update.

async to_model_on_upsert(data: ModelDictT[m.Team]) → ModelDictT[m.Team][source]#

Populate unique slug and resolve tag associations on team upsert.

Returns:

Prepared Team model or payload for upsert.

async update(data: ModelDictT[m.Team], item_id: Any | None = None, **kwargs: Any) → m.Team[source]#

Update team details and optionally transfer ownership when owner_id is provided.

Returns:

The updated Team model instance.

async list_visible_to(user: m.User, *filters: StatementFilter | ColumnElement[bool]) → tuple[Sequence[m.Team], int][source]#

List the teams user may see: every team for workspace superusers, otherwise only their own.

Returns:

The matching teams and their total count before pagination.

static can_view_all(user: User) → bool[source]#

Return whether user may list all teams across the workspace.

class app.domain.teams.services.TeamServices(session: ~sqlalchemy.ext.asyncio.session.AsyncSession | ~sqlalchemy.ext.asyncio.scoping.async_scoped_session[~sqlalchemy.ext.asyncio.session.AsyncSession] | ~sqlalchemy.orm.session.Session | ~sqlalchemy.orm.scoping.scoped_session[~sqlalchemy.orm.session.Session], *, error_messages: ~advanced_alchemy.exceptions.ErrorMessages | type[~advanced_alchemy.utils.dataclass.Empty] | None = <class 'advanced_alchemy.utils.dataclass.Empty'>, execution_options: dict[str, ~typing.Any] | None = None, uniquify: bool | None = None, count_with_window_function: bool | None = None, auto_expunge: bool | None = None, auto_refresh: bool | None = None, auto_commit: bool | None = None, wrap_exceptions: bool | None = None)[source]#

Bases: ServiceGroup

Unified team-domain service group sharing a single SQLAlchemy async session.

Instantiate every declared service on the provided SQLAlchemy session.

async accept_invitation(invitation_id: UUID, *, team_id: UUID, user: User) → None[source]#

Add user to the team and mark their invitation accepted in one transaction.

Raises:
  • HTTPException – If the invitation was already accepted or user is already a member of the team.

  • PermissionDeniedException – If the invitation is addressed to someone other than user.