selfprivacy-rest-api/selfprivacy_api/repositories/users/abstract_user_repository.py

89 lines
2.4 KiB
Python
Raw Normal View History

from abc import ABC, abstractmethod
from typing import Optional
2024-12-13 13:51:40 +00:00
from selfprivacy_api.models.group import Group
from selfprivacy_api.models.user import UserDataUser
class AbstractUserRepository(ABC):
2024-11-29 15:32:02 +00:00
@staticmethod
@abstractmethod
def create_user(
username: str,
password: Optional[str] = None,
directmemberof: Optional[list[str]] = None,
2024-12-10 00:52:13 +00:00
displayname: Optional[str] = None,
2024-11-29 15:32:02 +00:00
) -> None:
"""
Creates a new user.
! In KanidmUserRepository "password" is a legacy field,
please use generate_password_reset_link() instead !
2024-11-29 15:32:02 +00:00
"""
@staticmethod
@abstractmethod
def get_users(
exclude_primary: bool = False,
exclude_root: bool = False,
) -> list[UserDataUser]:
2024-11-29 15:32:02 +00:00
"""
Gets a list of users with options to exclude specific user groups.
! In KanidmUserRepository, the root user will never return !
2024-11-29 15:32:02 +00:00
"""
@staticmethod
@abstractmethod
def delete_user(username: str) -> None:
2024-12-13 13:51:40 +00:00
"""
2024-12-18 02:20:50 +00:00
Deletes an existing user.
2024-12-13 13:51:40 +00:00
"""
@staticmethod
@abstractmethod
2024-11-29 15:32:02 +00:00
def update_user(
username: str,
2024-12-10 00:52:13 +00:00
displayname: Optional[str] = None,
2024-11-29 15:32:02 +00:00
) -> None:
"""
Update user information.
In the JsonUserRepository, only update the password of an existing user.
! Do not update the password in KanidmUserRepository,
use generate_password_reset_link() instead !
2024-11-29 15:32:02 +00:00
"""
@staticmethod
@abstractmethod
def get_user_by_username(username: str) -> UserDataUser:
2024-12-13 13:51:40 +00:00
"""
2024-12-18 02:20:50 +00:00
Retrieves user data (UserDataUser) by username.
2024-12-13 13:51:40 +00:00
"""
# ! Not implemented in JsonUserRepository !
# | |
# \|/ \|/
2024-11-29 15:32:02 +00:00
@staticmethod
@abstractmethod
def generate_password_reset_link(username: str) -> str:
"""
Do not reset the password, just generate a link to reset the password.
"""
2024-12-12 12:00:07 +00:00
@staticmethod
@abstractmethod
2024-12-13 13:51:40 +00:00
def groups_list() -> list[Group]:
"""
Get groups list.
"""
2024-12-18 02:20:50 +00:00
@staticmethod
@abstractmethod
def add_users_to_group(users: list[str], group_name: str) -> None:
2024-12-19 00:26:58 +00:00
"""Add users to a specified group."""
2024-12-18 02:20:50 +00:00
@staticmethod
@abstractmethod
def remove_users_from_group(users: list[str], group_name: str) -> None:
2024-12-19 00:26:58 +00:00
"""Remove users from a specified group."""