-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathusers_base.py
More file actions
144 lines (107 loc) · 3.21 KB
/
users_base.py
File metadata and controls
144 lines (107 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
"""Abstract base class for user service."""
from abc import ABC, abstractmethod
from invokeai.app.services.users.users_common import UserCreateRequest, UserDTO, UserUpdateRequest
class UserServiceBase(ABC):
"""High-level service for user management."""
@abstractmethod
def create(self, user_data: UserCreateRequest) -> UserDTO:
"""Create a new user.
Args:
user_data: User creation data
Returns:
The created user
Raises:
ValueError: If email already exists or password is weak
"""
pass
@abstractmethod
def get(self, user_id: str) -> UserDTO | None:
"""Get user by ID.
Args:
user_id: The user ID
Returns:
UserDTO if found, None otherwise
"""
pass
@abstractmethod
def get_by_email(self, email: str) -> UserDTO | None:
"""Get user by email.
Args:
email: The email address
Returns:
UserDTO if found, None otherwise
"""
pass
@abstractmethod
def update(self, user_id: str, changes: UserUpdateRequest) -> UserDTO:
"""Update user.
Args:
user_id: The user ID
changes: Fields to update
Returns:
The updated user
Raises:
ValueError: If user not found or password is weak
"""
pass
@abstractmethod
def delete(self, user_id: str) -> None:
"""Delete user.
Args:
user_id: The user ID
Raises:
ValueError: If user not found
"""
pass
@abstractmethod
def authenticate(self, email: str, password: str) -> UserDTO | None:
"""Authenticate user credentials.
Args:
email: User email
password: User password
Returns:
UserDTO if authentication successful, None otherwise
"""
pass
@abstractmethod
def has_admin(self) -> bool:
"""Check if any admin user exists.
Returns:
True if at least one admin user exists, False otherwise
"""
pass
@abstractmethod
def create_admin(self, user_data: UserCreateRequest) -> UserDTO:
"""Create an admin user (for initial setup).
Args:
user_data: User creation data
Returns:
The created admin user
Raises:
ValueError: If admin already exists or password is weak
"""
pass
@abstractmethod
def list_users(self, limit: int = 100, offset: int = 0) -> list[UserDTO]:
"""List all users.
Args:
limit: Maximum number of users to return
offset: Number of users to skip
Returns:
List of users
"""
pass
@abstractmethod
def get_admin_email(self) -> str | None:
"""Get the email address of the first active admin user.
Returns:
Email address of the first active admin, or None if no admin exists
"""
pass
@abstractmethod
def count_admins(self) -> int:
"""Count active admin users.
Returns:
The number of active admin users
"""
pass