2024-10-26 18:22:31 +00:00
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
from typing import Optional
|
|
|
|
|
2024-11-02 23:15:51 +00:00
|
|
|
from selfprivacy_api.models.user import UserDataUser
|
2024-10-26 18:22:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AbstractUserRepository(ABC):
|
2024-11-29 15:32:02 +00:00
|
|
|
@staticmethod
|
|
|
|
@abstractmethod
|
|
|
|
def create_user(
|
|
|
|
username: str,
|
|
|
|
password: Optional[str] = None,
|
|
|
|
displayname: Optional[str] = None,
|
|
|
|
email: Optional[str] = None,
|
|
|
|
directmemberof: Optional[list[str]] = None,
|
|
|
|
memberof: Optional[list[str]] = None,
|
|
|
|
) -> None:
|
|
|
|
"""
|
|
|
|
Creates a new user. In KanidmUserRepository "password" is a legacy field,
|
|
|
|
please use generate_password_reset_link() instead.
|
|
|
|
"""
|
|
|
|
|
2024-11-02 23:15:51 +00:00
|
|
|
@staticmethod
|
2024-10-26 18:22:31 +00:00
|
|
|
@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-10-26 18:22:31 +00:00
|
|
|
|
2024-11-02 23:15:51 +00:00
|
|
|
@staticmethod
|
2024-10-26 18:22:31 +00:00
|
|
|
@abstractmethod
|
|
|
|
def delete_user(username: str) -> None:
|
|
|
|
"""Deletes an existing user"""
|
|
|
|
|
2024-11-02 23:15:51 +00:00
|
|
|
@staticmethod
|
2024-10-26 18:22:31 +00:00
|
|
|
@abstractmethod
|
2024-11-29 15:32:02 +00:00
|
|
|
def update_user(
|
|
|
|
username: str,
|
|
|
|
password: Optional[str] = None,
|
|
|
|
displayname: Optional[str] = None,
|
|
|
|
email: Optional[str] = None,
|
|
|
|
directmemberof: Optional[list[str]] = None,
|
|
|
|
memberof: Optional[list[str]] = None,
|
|
|
|
) -> 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-10-26 18:22:31 +00:00
|
|
|
|
2024-11-02 23:15:51 +00:00
|
|
|
@staticmethod
|
2024-10-26 18:22:31 +00:00
|
|
|
@abstractmethod
|
|
|
|
def get_user_by_username(username: str) -> Optional[UserDataUser]:
|
|
|
|
"""Retrieves user data (UserDataUser) by username"""
|
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.
|
|
|
|
Not implemented in JsonUserRepository.
|
|
|
|
"""
|