-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
162 lines (98 loc) · 2.98 KB
/
models.py
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
from __future__ import annotations
from datetime import datetime
from typing import Annotated
from annotated_types import Gt, MinLen
from pydantic import field_validator
from auth_backend.base import Base
from auth_backend.schemas.types.scopes import Scope
class PinchedScope(Base):
id: int
name: Scope
class Group(Base):
id: Annotated[int, Gt(0)]
name: str
parent_id: Annotated[int, Gt(0)] | None = None
class GroupScopes(Base):
scopes: list[PinchedScope] | None = None
class GroupChilds(Base):
child: list[Group] | None = None
class GroupIndirectScopes(Base):
indirect_scopes: list[PinchedScope] | None = None
class GroupUserList(Base):
users: list[int] | None = None
class GroupGet(Group, GroupChilds, GroupIndirectScopes, GroupScopes, GroupUserList):
pass
class User(Base):
id: int
class UserInfo(User):
email: str | None = None
class UserGroups(Base):
groups: list[int] | None = None
class UserIndirectGroups(Base):
indirect_groups: list[int] | None = None
class UserScopes(Base):
user_scopes: list[PinchedScope] | None = None
class UserAuthMethods(Base):
auth_methods: list[str] | None = None
class SessionScopes(Base):
session_scopes: list[PinchedScope] | None = None
class UserGet(UserInfo, UserGroups, UserIndirectGroups, UserScopes, SessionScopes, UserAuthMethods):
pass
class UsersGet(Base):
items: list[UserGet]
class UserPatch(Base):
groups: list[int]
class GroupPost(Base):
name: str
parent_id: Annotated[int, Gt(0)] | None = None
scopes: list[int]
class GroupsGet(Base):
items: list[GroupGet]
class GroupPatch(Base):
name: str | None = None
parent_id: Annotated[int, Gt(0)] | None = None
scopes: list[int] | None = None
class UserGroupGet(Base):
group_id: Annotated[int, Gt(0)]
user_id: Annotated[int, Gt(0)]
class UserGroupPost(Base):
user_id: Annotated[int, Gt(0)]
class GroupUserListGet(Base):
items: list[UserInfo]
class ScopeGet(Base):
id: int
name: Scope
comment: str | None = None
class ScopePost(Base):
name: Scope
comment: str | None = None
class ScopePatch(Base):
name: Scope | None = None
comment: str | None = None
class Session(Base):
session_name: str | None = None
token: Annotated[str, MinLen(1)] | None = None
expires: datetime | None = None
id: int
user_id: int
session_scopes: list[Scope] | None = None
last_activity: datetime
class SessionPost(Base):
session_name: str | None = None
scopes: list[Scope] = []
expires: datetime | None = None
@classmethod
@field_validator("expires")
@classmethod
def expires_validator(cls, exp):
if exp < datetime.utcnow():
raise ValueError()
return exp
class SessionPatch(Base):
session_name: str | None = None
scopes: list[Scope] | None = None
Group.model_rebuild()
GroupGet.model_rebuild()
UserScopes.model_rebuild()
UserGet.model_rebuild()
SessionScopes.model_rebuild()