2024-10-26 18:22:31 +00:00
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
from typing import Optional
|
|
|
|
|
2024-12-13 13:51:40 +00:00
|
|
|
from selfprivacy_api.models.group import Group
|
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,
|
|
|
|
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:
|
|
|
|
"""
|
2024-12-11 11:16:14 +00:00
|
|
|
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
|
|
|
"""
|
|
|
|
|
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.
|
2024-12-11 11:16:14 +00:00
|
|
|
! In KanidmUserRepository, the root user will never return !
|
2024-11-29 15:32:02 +00:00
|
|
|
"""
|
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:
|
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
|
|
|
"""
|
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
|
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.
|
2024-12-11 11:16:14 +00:00
|
|
|
! Do not update the password in KanidmUserRepository,
|
|
|
|
use generate_password_reset_link() instead !
|
2024-11-29 15:32:02 +00:00
|
|
|
"""
|
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
|
2024-12-11 03:13:02 +00:00
|
|
|
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:
|
|
|
|
""""""
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
@abstractmethod
|
|
|
|
def remove_users_from_group(users: list[str], group_name: str) -> None:
|
|
|
|
""""""
|