Add base for members
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from pydantic import EmailStr, field_validator
|
||||
from sqlmodel import Field, Relationship, Session, select
|
||||
@@ -17,6 +17,7 @@ from .base import (
|
||||
if TYPE_CHECKING:
|
||||
from .apikey import ApiKey
|
||||
from .event import EventUserLink
|
||||
from .member import Member
|
||||
|
||||
|
||||
# region # User ################################################################
|
||||
@@ -29,6 +30,7 @@ class PermissionModule(DocumentedStrEnum):
|
||||
TEAM = auto_enum()
|
||||
ASSOCIATION = auto_enum()
|
||||
DIVISION = auto_enum()
|
||||
MEMBER = auto_enum()
|
||||
|
||||
|
||||
class PermissionPart(DocumentedStrEnum):
|
||||
@@ -45,8 +47,17 @@ class PermissionRight(DocumentedIntFlag):
|
||||
MANAGE_USERS = auto_enum()
|
||||
MANAGE_TEAMS = auto_enum()
|
||||
MANAGE_DIVISIONS = auto_enum()
|
||||
MANAGE_MEMBERS = auto_enum()
|
||||
|
||||
ADMIN = CREATE | READ | UPDATE | DELETE | MANAGE_USERS | MANAGE_TEAMS | MANAGE_DIVISIONS
|
||||
ADMIN = ( CREATE
|
||||
| READ
|
||||
| UPDATE
|
||||
| DELETE
|
||||
| MANAGE_USERS
|
||||
| MANAGE_TEAMS
|
||||
| MANAGE_DIVISIONS
|
||||
| MANAGE_MEMBERS
|
||||
)
|
||||
|
||||
|
||||
# ##############################################################################
|
||||
@@ -75,13 +86,16 @@ class UserRoleLink(BaseSQLModel, table=True):
|
||||
class UserBase(
|
||||
mixin.UserName,
|
||||
mixin.Email,
|
||||
mixin.FullName,
|
||||
mixin.ScoutingId,
|
||||
mixin.IsActive,
|
||||
mixin.IsVerified,
|
||||
BaseSQLModel,
|
||||
):
|
||||
pass
|
||||
member_id: RowId | None = Field(
|
||||
default=None,
|
||||
foreign_key="member.id",
|
||||
nullable=True,
|
||||
ondelete="SET NULL",
|
||||
)
|
||||
|
||||
|
||||
# Properties to receive via API on creation
|
||||
@@ -89,7 +103,7 @@ class UserCreate(mixin.Password, UserBase):
|
||||
pass
|
||||
|
||||
|
||||
class UserRegister(mixin.Password, mixin.FullName, BaseSQLModel):
|
||||
class UserRegister(mixin.Password, BaseSQLModel):
|
||||
email: EmailStr = Field(max_length=255)
|
||||
|
||||
|
||||
@@ -98,7 +112,7 @@ class UserUpdate(mixin.EmailUpdate, mixin.PasswordUpdate, UserBase):
|
||||
pass
|
||||
|
||||
|
||||
class UserUpdateMe(mixin.FullName, mixin.EmailUpdate, BaseSQLModel):
|
||||
class UserUpdateMe(mixin.EmailUpdate, BaseSQLModel):
|
||||
pass
|
||||
|
||||
|
||||
@@ -113,6 +127,10 @@ class User(mixin.RowId, UserBase, table=True):
|
||||
hashed_password: str
|
||||
|
||||
# --- back_populates links -------------------------------------------------
|
||||
member: Optional["Member"] = Relationship(
|
||||
back_populates="user",
|
||||
sa_relationship_kwargs={"foreign_keys": "User.member_id"},
|
||||
)
|
||||
api_keys: list["ApiKey"] = Relationship(back_populates="user", cascade_delete=True)
|
||||
|
||||
# --- many-to-many links ---------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user