User and Role Services

Domain services encapsulating the business logic for User and Role data models.

User Service (UserService)

class UserService[source]

Bases: SQLAlchemyAsyncRepositoryService[User, Any]

Handles database operations for users.

default_role: ClassVar[str] = 'application-access'
async authenticate(username: str, password: str) User[source]

Authenticate a user.

Parameters:
  • username (str) – User email.

  • password (str) – User password.

Raises:

UnauthorizedException – If the user is not found, not verified, or inactive.

Returns:

The user object.

Return type:

User

async update_password(data: PasswordUpdate, user_id: UUID) None[source]

Modify the stored user password.

Parameters:
  • data (PasswordUpdate) – The Pydantic schema with current and new passwords.

  • user_id (UUID) – The unique ID of the target user.

Raises:

UnauthorizedException – If the current password is incorrect.

async get_and_validate_for_role_change(email: str) User[source]

Retrieve an active user by email for role modification.

Parameters:

email (str) – The email of the user whose role is being modified.

Returns:

The User model object from the database.

Return type:

User

Raises:
async get_users_paginated_dto(params: UserFilters) OffsetPagination[UserDto][source]

Provide a filtered and paginated list of users with caching.

Role Service (RoleService)

class RoleService[source]

Bases: SQLAlchemyAsyncRepositoryService[Role, Any]

Handles database operations for roles.

async get_id_and_slug_by_slug(slug: str) Role[source]

Retrieve the role object with column optimization.

async get_default_role(default_role_slug: str) Role[source]

Retrieve the default role object with column optimization.

Parameters:

default_role_slug (str) – The slug of the default role (e.g., ‘application-access’).

Returns:

A Role object (with id, name, and slug loaded).

Return type:

Role

Raises:

NotFoundError – Signals a critical infrastructure failure. This role is required, and its absence means that the initial database seeding did not complete.