mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
chore: adapt to SQLModel 16 & SQLAlchemy 2.x
This commit is contained in:
parent
938c3a2349
commit
c8f6aff996
24 changed files with 120 additions and 123 deletions
|
|
@ -20,8 +20,7 @@ class Trail(TrailBase, table=True):
|
||||||
class TrailCreate(TrailBase):
|
class TrailCreate(TrailBase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# TODO: This is a hacky way to get around the list[TrailRun] issue, find a better way to do this
|
||||||
# trick because Lists are not supported in SQLModel (runs: list[TrailRun] )
|
|
||||||
class TrailRead(BaseModel):
|
class TrailRead(BaseModel):
|
||||||
id: Optional[int] = Field(default=None, primary_key=True)
|
id: Optional[int] = Field(default=None, primary_key=True)
|
||||||
trail_uuid: Optional[str]
|
trail_uuid: Optional[str]
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ async def login(
|
||||||
expires=int(timedelta(hours=8).total_seconds()),
|
expires=int(timedelta(hours=8).total_seconds()),
|
||||||
)
|
)
|
||||||
|
|
||||||
user = UserRead.from_orm(user)
|
user = UserRead.model_validate(user)
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
"user": user,
|
"user": user,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ router = APIRouter()
|
||||||
@router.get("/config")
|
@router.get("/config")
|
||||||
async def config():
|
async def config():
|
||||||
config = get_learnhouse_config()
|
config = get_learnhouse_config()
|
||||||
return config.dict()
|
return config.model_dump()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ async def api_get_current_user(current_user: User = Depends(get_current_user)):
|
||||||
"""
|
"""
|
||||||
Get current user
|
Get current user
|
||||||
"""
|
"""
|
||||||
return current_user.dict()
|
return current_user.model_dump()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/session")
|
@router.get("/session")
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ async def get_current_user(
|
||||||
user = await security_get_user(request, db_session, email=token_data.username) # type: ignore # treated as an email
|
user = await security_get_user(request, db_session, email=token_data.username) # type: ignore # treated as an email
|
||||||
if user is None:
|
if user is None:
|
||||||
raise credentials_exception
|
raise credentials_exception
|
||||||
return PublicUser(**user.dict())
|
return PublicUser(**user.model_dump())
|
||||||
else:
|
else:
|
||||||
return AnonymousUser()
|
return AnonymousUser()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ async def authorization_verify_based_on_roles(
|
||||||
|
|
||||||
# Find in roles list if there is a role that matches users action for this type of element
|
# Find in roles list if there is a role that matches users action for this type of element
|
||||||
for role in user_roles_in_organization_and_standard_roles:
|
for role in user_roles_in_organization_and_standard_roles:
|
||||||
role = Role.from_orm(role)
|
role = Role.model_validate(role)
|
||||||
if role.rights:
|
if role.rights:
|
||||||
rights = role.rights
|
rights = role.rights
|
||||||
if rights[element_type][f"action_{action}"] is True:
|
if rights[element_type][f"action_{action}"] is True:
|
||||||
|
|
@ -135,7 +135,7 @@ async def authorization_verify_based_on_org_admin_status(
|
||||||
|
|
||||||
# Find in roles list if there is a role that matches users action for this type of element
|
# Find in roles list if there is a role that matches users action for this type of element
|
||||||
for role in user_roles_in_organization_and_standard_roles:
|
for role in user_roles_in_organization_and_standard_roles:
|
||||||
role = Role.from_orm(role)
|
role = Role.model_validate(role)
|
||||||
if role.id == 1 or role.id == 2:
|
if role.id == 1 or role.id == 2:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ def ai_start_activity_chat_session(
|
||||||
)
|
)
|
||||||
activity = db_session.exec(statement).first()
|
activity = db_session.exec(statement).first()
|
||||||
|
|
||||||
activity = ActivityRead.from_orm(activity)
|
activity = ActivityRead.model_validate(activity)
|
||||||
|
|
||||||
# Get the Course
|
# Get the Course
|
||||||
statement = (
|
statement = (
|
||||||
|
|
@ -46,7 +46,7 @@ def ai_start_activity_chat_session(
|
||||||
.where(Activity.activity_uuid == chat_session_object.activity_uuid)
|
.where(Activity.activity_uuid == chat_session_object.activity_uuid)
|
||||||
)
|
)
|
||||||
course = db_session.exec(statement).first()
|
course = db_session.exec(statement).first()
|
||||||
course = CourseRead.from_orm(course)
|
course = CourseRead.model_validate(course)
|
||||||
|
|
||||||
# Get the Organization
|
# Get the Organization
|
||||||
statement = select(Organization).where(Organization.id == course.org_id)
|
statement = select(Organization).where(Organization.id == course.org_id)
|
||||||
|
|
@ -85,7 +85,7 @@ def ai_start_activity_chat_session(
|
||||||
result = db_session.exec(statement)
|
result = db_session.exec(statement)
|
||||||
org_config = result.first()
|
org_config = result.first()
|
||||||
|
|
||||||
org_config = OrganizationConfig.from_orm(org_config)
|
org_config = OrganizationConfig.model_validate(org_config)
|
||||||
embeddings = org_config.config["AIConfig"]["embeddings"]
|
embeddings = org_config.config["AIConfig"]["embeddings"]
|
||||||
ai_model = org_config.config["AIConfig"]["ai_model"]
|
ai_model = org_config.config["AIConfig"]["ai_model"]
|
||||||
|
|
||||||
|
|
@ -131,7 +131,7 @@ def ai_send_activity_chat_message(
|
||||||
)
|
)
|
||||||
activity = db_session.exec(statement).first()
|
activity = db_session.exec(statement).first()
|
||||||
|
|
||||||
activity = ActivityRead.from_orm(activity)
|
activity = ActivityRead.model_validate(activity)
|
||||||
|
|
||||||
# Get the Course
|
# Get the Course
|
||||||
statement = (
|
statement = (
|
||||||
|
|
@ -140,7 +140,7 @@ def ai_send_activity_chat_message(
|
||||||
.where(Activity.activity_uuid == chat_session_object.activity_uuid)
|
.where(Activity.activity_uuid == chat_session_object.activity_uuid)
|
||||||
)
|
)
|
||||||
course = db_session.exec(statement).first()
|
course = db_session.exec(statement).first()
|
||||||
course = CourseRead.from_orm(course)
|
course = CourseRead.model_validate(course)
|
||||||
|
|
||||||
# Get the Organization
|
# Get the Organization
|
||||||
statement = select(Organization).where(Organization.id == course.org_id)
|
statement = select(Organization).where(Organization.id == course.org_id)
|
||||||
|
|
@ -176,7 +176,7 @@ def ai_send_activity_chat_message(
|
||||||
result = db_session.exec(statement)
|
result = db_session.exec(statement)
|
||||||
org_config = result.first()
|
org_config = result.first()
|
||||||
|
|
||||||
org_config = OrganizationConfig.from_orm(org_config)
|
org_config = OrganizationConfig.model_validate(org_config)
|
||||||
embeddings = org_config.config["AIConfig"]["embeddings"]
|
embeddings = org_config.config["AIConfig"]["embeddings"]
|
||||||
ai_model = org_config.config["AIConfig"]["ai_model"]
|
ai_model = org_config.config["AIConfig"]["ai_model"]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ async def create_image_block(
|
||||||
block = Block(
|
block = Block(
|
||||||
activity_id=activity.id if activity.id else 0,
|
activity_id=activity.id if activity.id else 0,
|
||||||
block_type=BlockTypeEnum.BLOCK_IMAGE,
|
block_type=BlockTypeEnum.BLOCK_IMAGE,
|
||||||
content=block_data.dict(),
|
content=block_data.model_dump(),
|
||||||
org_id=org.id if org.id else 0,
|
org_id=org.id if org.id else 0,
|
||||||
course_id=course.id if course.id else 0,
|
course_id=course.id if course.id else 0,
|
||||||
block_uuid=block_uuid,
|
block_uuid=block_uuid,
|
||||||
|
|
@ -67,7 +67,7 @@ async def create_image_block(
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(block)
|
db_session.refresh(block)
|
||||||
|
|
||||||
block = BlockRead.from_orm(block)
|
block = BlockRead.model_validate(block)
|
||||||
|
|
||||||
return block
|
return block
|
||||||
|
|
||||||
|
|
@ -80,7 +80,7 @@ async def get_image_block(
|
||||||
|
|
||||||
if block:
|
if block:
|
||||||
|
|
||||||
block = BlockRead.from_orm(block)
|
block = BlockRead.model_validate(block)
|
||||||
|
|
||||||
return block
|
return block
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ async def create_pdf_block(
|
||||||
block = Block(
|
block = Block(
|
||||||
activity_id=activity.id if activity.id else 0,
|
activity_id=activity.id if activity.id else 0,
|
||||||
block_type=BlockTypeEnum.BLOCK_DOCUMENT_PDF,
|
block_type=BlockTypeEnum.BLOCK_DOCUMENT_PDF,
|
||||||
content=block_data.dict(),
|
content=block_data.model_dump(),
|
||||||
org_id=org.id if org.id else 0,
|
org_id=org.id if org.id else 0,
|
||||||
course_id=course.id if course.id else 0,
|
course_id=course.id if course.id else 0,
|
||||||
block_uuid=block_uuid,
|
block_uuid=block_uuid,
|
||||||
|
|
@ -68,7 +68,7 @@ async def create_pdf_block(
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(block)
|
db_session.refresh(block)
|
||||||
|
|
||||||
block = BlockRead.from_orm(block)
|
block = BlockRead.model_validate(block)
|
||||||
|
|
||||||
return block
|
return block
|
||||||
|
|
||||||
|
|
@ -84,6 +84,6 @@ async def get_pdf_block(
|
||||||
status_code=status.HTTP_404_NOT_FOUND, detail="Video file does not exist"
|
status_code=status.HTTP_404_NOT_FOUND, detail="Video file does not exist"
|
||||||
)
|
)
|
||||||
|
|
||||||
block = BlockRead.from_orm(block)
|
block = BlockRead.model_validate(block)
|
||||||
|
|
||||||
return block
|
return block
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ async def create_video_block(
|
||||||
block = Block(
|
block = Block(
|
||||||
activity_id=activity.id if activity.id else 0,
|
activity_id=activity.id if activity.id else 0,
|
||||||
block_type=BlockTypeEnum.BLOCK_VIDEO,
|
block_type=BlockTypeEnum.BLOCK_VIDEO,
|
||||||
content=block_data.dict(),
|
content=block_data.model_dump(),
|
||||||
org_id=org.id if org.id else 0,
|
org_id=org.id if org.id else 0,
|
||||||
course_id=course.id if course.id else 0,
|
course_id=course.id if course.id else 0,
|
||||||
block_uuid=block_uuid,
|
block_uuid=block_uuid,
|
||||||
|
|
@ -68,7 +68,7 @@ async def create_video_block(
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(block)
|
db_session.refresh(block)
|
||||||
|
|
||||||
block = BlockRead.from_orm(block)
|
block = BlockRead.model_validate(block)
|
||||||
|
|
||||||
return block
|
return block
|
||||||
|
|
||||||
|
|
@ -84,6 +84,6 @@ async def get_video_block(
|
||||||
status_code=status.HTTP_404_NOT_FOUND, detail="Video file does not exist"
|
status_code=status.HTTP_404_NOT_FOUND, detail="Video file does not exist"
|
||||||
)
|
)
|
||||||
|
|
||||||
block = BlockRead.from_orm(block)
|
block = BlockRead.model_validate(block)
|
||||||
|
|
||||||
return block
|
return block
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ async def create_activity(
|
||||||
await rbac_check(request, chapter.chapter_uuid, current_user, "create", db_session)
|
await rbac_check(request, chapter.chapter_uuid, current_user, "create", db_session)
|
||||||
|
|
||||||
# Create Activity
|
# Create Activity
|
||||||
activity = Activity(**activity_object.dict())
|
activity = Activity(**activity_object.model_dump())
|
||||||
|
|
||||||
activity.activity_uuid = str(f"activity_{uuid4()}")
|
activity.activity_uuid = str(f"activity_{uuid4()}")
|
||||||
activity.creation_date = str(datetime.now())
|
activity.creation_date = str(datetime.now())
|
||||||
|
|
@ -81,7 +81,7 @@ async def create_activity(
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(activity_chapter)
|
db_session.refresh(activity_chapter)
|
||||||
|
|
||||||
return ActivityRead.from_orm(activity)
|
return ActivityRead.model_validate(activity)
|
||||||
|
|
||||||
|
|
||||||
async def get_activity(
|
async def get_activity(
|
||||||
|
|
@ -112,7 +112,7 @@ async def get_activity(
|
||||||
# RBAC check
|
# RBAC check
|
||||||
await rbac_check(request, course.course_uuid, current_user, "read", db_session)
|
await rbac_check(request, course.course_uuid, current_user, "read", db_session)
|
||||||
|
|
||||||
activity = ActivityRead.from_orm(activity)
|
activity = ActivityRead.model_validate(activity)
|
||||||
|
|
||||||
return activity
|
return activity
|
||||||
|
|
||||||
|
|
@ -147,7 +147,7 @@ async def update_activity(
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(activity)
|
db_session.refresh(activity)
|
||||||
|
|
||||||
activity = ActivityRead.from_orm(activity)
|
activity = ActivityRead.model_validate(activity)
|
||||||
|
|
||||||
return activity
|
return activity
|
||||||
|
|
||||||
|
|
@ -216,7 +216,7 @@ async def get_activities(
|
||||||
# RBAC check
|
# RBAC check
|
||||||
await rbac_check(request, "activity_x", current_user, "read", db_session)
|
await rbac_check(request, "activity_x", current_user, "read", db_session)
|
||||||
|
|
||||||
activities = [ActivityRead.from_orm(activity) for activity in activities]
|
activities = [ActivityRead.model_validate(activity) for activity in activities]
|
||||||
|
|
||||||
return activities
|
return activities
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ async def create_documentpdf_activity(
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(activity_chapter)
|
db_session.refresh(activity_chapter)
|
||||||
|
|
||||||
return ActivityRead.from_orm(activity)
|
return ActivityRead.model_validate(activity)
|
||||||
|
|
||||||
|
|
||||||
## 🔒 RBAC Utils ##
|
## 🔒 RBAC Utils ##
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ async def create_video_activity(
|
||||||
)
|
)
|
||||||
|
|
||||||
# create activity
|
# create activity
|
||||||
activity = Activity.from_orm(activity_object)
|
activity = Activity.model_validate(activity_object)
|
||||||
db_session.add(activity)
|
db_session.add(activity)
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(activity)
|
db_session.refresh(activity)
|
||||||
|
|
@ -136,7 +136,7 @@ async def create_video_activity(
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(chapter_activity_object)
|
db_session.refresh(chapter_activity_object)
|
||||||
|
|
||||||
return ActivityRead.from_orm(activity)
|
return ActivityRead.model_validate(activity)
|
||||||
|
|
||||||
|
|
||||||
class ExternalVideo(BaseModel):
|
class ExternalVideo(BaseModel):
|
||||||
|
|
@ -200,7 +200,7 @@ async def create_external_video_activity(
|
||||||
)
|
)
|
||||||
|
|
||||||
# create activity
|
# create activity
|
||||||
activity = Activity.from_orm(activity_object)
|
activity = Activity.model_validate(activity_object)
|
||||||
db_session.add(activity)
|
db_session.add(activity)
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(activity)
|
db_session.refresh(activity)
|
||||||
|
|
@ -220,7 +220,7 @@ async def create_external_video_activity(
|
||||||
db_session.add(chapter_activity_object)
|
db_session.add(chapter_activity_object)
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
|
|
||||||
return ActivityRead.from_orm(activity)
|
return ActivityRead.model_validate(activity)
|
||||||
|
|
||||||
|
|
||||||
async def rbac_check(
|
async def rbac_check(
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ async def create_chapter(
|
||||||
current_user: PublicUser | AnonymousUser,
|
current_user: PublicUser | AnonymousUser,
|
||||||
db_session: Session,
|
db_session: Session,
|
||||||
) -> ChapterRead:
|
) -> ChapterRead:
|
||||||
chapter = Chapter.from_orm(chapter_object)
|
chapter = Chapter.model_validate(chapter_object)
|
||||||
|
|
||||||
# Get COurse
|
# Get COurse
|
||||||
statement = select(Course).where(Course.id == chapter_object.course_id)
|
statement = select(Course).where(Course.id == chapter_object.course_id)
|
||||||
|
|
@ -68,7 +68,7 @@ async def create_chapter(
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(chapter)
|
db_session.refresh(chapter)
|
||||||
|
|
||||||
chapter = ChapterRead(**chapter.dict(), activities=[])
|
chapter = ChapterRead(**chapter.model_dump(), activities=[])
|
||||||
|
|
||||||
# Check if COurseChapter link exists
|
# Check if COurseChapter link exists
|
||||||
|
|
||||||
|
|
@ -135,8 +135,8 @@ async def get_chapter(
|
||||||
activities = db_session.exec(statement).all()
|
activities = db_session.exec(statement).all()
|
||||||
|
|
||||||
chapter = ChapterRead(
|
chapter = ChapterRead(
|
||||||
**chapter.dict(),
|
**chapter.model_dump(),
|
||||||
activities=[ActivityRead(**activity.dict()) for activity in activities],
|
activities=[ActivityRead(**activity.model_dump()) for activity in activities],
|
||||||
)
|
)
|
||||||
|
|
||||||
return chapter
|
return chapter
|
||||||
|
|
@ -231,7 +231,7 @@ async def get_course_chapters(
|
||||||
)
|
)
|
||||||
chapters = db_session.exec(statement).all()
|
chapters = db_session.exec(statement).all()
|
||||||
|
|
||||||
chapters = [ChapterRead(**chapter.dict(), activities=[]) for chapter in chapters]
|
chapters = [ChapterRead(**chapter.model_dump(), activities=[]) for chapter in chapters]
|
||||||
|
|
||||||
# RBAC check
|
# RBAC check
|
||||||
await rbac_check(request, course.course_uuid, current_user, "read", db_session) # type: ignore
|
await rbac_check(request, course.course_uuid, current_user, "read", db_session) # type: ignore
|
||||||
|
|
@ -255,7 +255,7 @@ async def get_course_chapters(
|
||||||
activity = db_session.exec(statement).first()
|
activity = db_session.exec(statement).first()
|
||||||
|
|
||||||
if activity:
|
if activity:
|
||||||
chapter.activities.append(ActivityRead(**activity.dict()))
|
chapter.activities.append(ActivityRead(**activity.model_dump()))
|
||||||
|
|
||||||
return chapters
|
return chapters
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ async def get_collection(
|
||||||
|
|
||||||
courses = db_session.exec(statement).all()
|
courses = db_session.exec(statement).all()
|
||||||
|
|
||||||
collection = CollectionRead(**collection.dict(), courses=courses)
|
collection = CollectionRead(**collection.model_dump(), courses=courses)
|
||||||
|
|
||||||
return collection
|
return collection
|
||||||
|
|
||||||
|
|
@ -75,7 +75,7 @@ async def create_collection(
|
||||||
current_user: PublicUser,
|
current_user: PublicUser,
|
||||||
db_session: Session,
|
db_session: Session,
|
||||||
) -> CollectionRead:
|
) -> CollectionRead:
|
||||||
collection = Collection.from_orm(collection_object)
|
collection = Collection.model_validate(collection_object)
|
||||||
|
|
||||||
# RBAC check
|
# RBAC check
|
||||||
await rbac_check(request, "collection_x", current_user, "create", db_session)
|
await rbac_check(request, "collection_x", current_user, "create", db_session)
|
||||||
|
|
@ -115,9 +115,9 @@ async def create_collection(
|
||||||
)
|
)
|
||||||
courses = db_session.exec(statement).all()
|
courses = db_session.exec(statement).all()
|
||||||
|
|
||||||
collection = CollectionRead(**collection.dict(), courses=courses)
|
collection = CollectionRead(**collection.model_dump(), courses=courses)
|
||||||
|
|
||||||
return CollectionRead.from_orm(collection)
|
return CollectionRead.model_validate(collection)
|
||||||
|
|
||||||
|
|
||||||
async def update_collection(
|
async def update_collection(
|
||||||
|
|
@ -189,7 +189,7 @@ async def update_collection(
|
||||||
|
|
||||||
courses = db_session.exec(statement).all()
|
courses = db_session.exec(statement).all()
|
||||||
|
|
||||||
collection = CollectionRead(**collection.dict(), courses=courses)
|
collection = CollectionRead(**collection.model_dump(), courses=courses)
|
||||||
|
|
||||||
return collection
|
return collection
|
||||||
|
|
||||||
|
|
@ -270,7 +270,7 @@ async def get_collections(
|
||||||
|
|
||||||
courses = db_session.exec(statement).all()
|
courses = db_session.exec(statement).all()
|
||||||
|
|
||||||
collection = CollectionRead(**collection.dict(), courses=courses)
|
collection = CollectionRead(**collection.model_dump(), courses=courses)
|
||||||
collections_with_courses.append(collection)
|
collections_with_courses.append(collection)
|
||||||
|
|
||||||
return collections_with_courses
|
return collections_with_courses
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ from sqlmodel import Session, select
|
||||||
from src.db.usergroup_resources import UserGroupResource
|
from src.db.usergroup_resources import UserGroupResource
|
||||||
from src.db.usergroup_user import UserGroupUser
|
from src.db.usergroup_user import UserGroupUser
|
||||||
from src.db.organizations import Organization
|
from src.db.organizations import Organization
|
||||||
from src.db.trails import TrailRead
|
|
||||||
from src.services.trail.trail import get_user_trail_with_orgid
|
from src.services.trail.trail import get_user_trail_with_orgid
|
||||||
from src.db.resource_authors import ResourceAuthor, ResourceAuthorshipEnum
|
from src.db.resource_authors import ResourceAuthor, ResourceAuthorshipEnum
|
||||||
from src.db.users import PublicUser, AnonymousUser, User, UserRead
|
from src.db.users import PublicUser, AnonymousUser, User, UserRead
|
||||||
|
|
@ -53,9 +52,9 @@ async def get_course(
|
||||||
authors = db_session.exec(authors_statement).all()
|
authors = db_session.exec(authors_statement).all()
|
||||||
|
|
||||||
# convert from User to UserRead
|
# convert from User to UserRead
|
||||||
authors = [UserRead.from_orm(author) for author in authors]
|
authors = [UserRead.model_validate(author) for author in authors]
|
||||||
|
|
||||||
course = CourseRead(**course.dict(), authors=authors)
|
course = CourseRead(**course.model_dump(), authors=authors)
|
||||||
|
|
||||||
return course
|
return course
|
||||||
|
|
||||||
|
|
@ -90,9 +89,9 @@ async def get_course_meta(
|
||||||
authors = db_session.exec(authors_statement).all()
|
authors = db_session.exec(authors_statement).all()
|
||||||
|
|
||||||
# convert from User to UserRead
|
# convert from User to UserRead
|
||||||
authors = [UserRead.from_orm(author) for author in authors]
|
authors = [UserRead.model_validate(author) for author in authors]
|
||||||
|
|
||||||
course = CourseRead(**course.dict(), authors=authors)
|
course = CourseRead(**course.model_dump(), authors=authors)
|
||||||
|
|
||||||
# Get course chapters
|
# Get course chapters
|
||||||
chapters = await get_course_chapters(request, course.id, db_session, current_user)
|
chapters = await get_course_chapters(request, course.id, db_session, current_user)
|
||||||
|
|
@ -106,10 +105,9 @@ async def get_course_meta(
|
||||||
trail = await get_user_trail_with_orgid(
|
trail = await get_user_trail_with_orgid(
|
||||||
request, current_user, course.org_id, db_session
|
request, current_user, course.org_id, db_session
|
||||||
)
|
)
|
||||||
trail = TrailRead.from_orm(trail)
|
|
||||||
|
|
||||||
return FullCourseReadWithTrail(
|
return FullCourseReadWithTrail(
|
||||||
**course.dict(),
|
**course.model_dump(),
|
||||||
chapters=chapters,
|
chapters=chapters,
|
||||||
trail=trail if trail else None,
|
trail=trail if trail else None,
|
||||||
)
|
)
|
||||||
|
|
@ -123,7 +121,7 @@ async def create_course(
|
||||||
db_session: Session,
|
db_session: Session,
|
||||||
thumbnail_file: UploadFile | None = None,
|
thumbnail_file: UploadFile | None = None,
|
||||||
):
|
):
|
||||||
course = Course.from_orm(course_object)
|
course = Course.model_validate(course_object)
|
||||||
|
|
||||||
# RBAC check
|
# RBAC check
|
||||||
await rbac_check(request, "course_x", current_user, "create", db_session)
|
await rbac_check(request, "course_x", current_user, "create", db_session)
|
||||||
|
|
@ -178,11 +176,11 @@ async def create_course(
|
||||||
authors = db_session.exec(authors_statement).all()
|
authors = db_session.exec(authors_statement).all()
|
||||||
|
|
||||||
# convert from User to UserRead
|
# convert from User to UserRead
|
||||||
authors = [UserRead.from_orm(author) for author in authors]
|
authors = [UserRead.model_validate(author) for author in authors]
|
||||||
|
|
||||||
course = CourseRead(**course.dict(), authors=authors)
|
course = CourseRead(**course.model_dump(), authors=authors)
|
||||||
|
|
||||||
return CourseRead.from_orm(course)
|
return CourseRead.model_validate(course)
|
||||||
|
|
||||||
|
|
||||||
async def update_course_thumbnail(
|
async def update_course_thumbnail(
|
||||||
|
|
@ -242,9 +240,9 @@ async def update_course_thumbnail(
|
||||||
authors = db_session.exec(authors_statement).all()
|
authors = db_session.exec(authors_statement).all()
|
||||||
|
|
||||||
# convert from User to UserRead
|
# convert from User to UserRead
|
||||||
authors = [UserRead.from_orm(author) for author in authors]
|
authors = [UserRead.model_validate(author) for author in authors]
|
||||||
|
|
||||||
course = CourseRead(**course.dict(), authors=authors)
|
course = CourseRead(**course.model_dump(), authors=authors)
|
||||||
|
|
||||||
return course
|
return course
|
||||||
|
|
||||||
|
|
@ -289,9 +287,9 @@ async def update_course(
|
||||||
authors = db_session.exec(authors_statement).all()
|
authors = db_session.exec(authors_statement).all()
|
||||||
|
|
||||||
# convert from User to UserRead
|
# convert from User to UserRead
|
||||||
authors = [UserRead.from_orm(author) for author in authors]
|
authors = [UserRead.model_validate(author) for author in authors]
|
||||||
|
|
||||||
course = CourseRead(**course.dict(), authors=authors)
|
course = CourseRead(**course.model_dump(), authors=authors)
|
||||||
|
|
||||||
return course
|
return course
|
||||||
|
|
||||||
|
|
@ -351,9 +349,7 @@ async def get_courses_orgslug(
|
||||||
statement_usergroup = (
|
statement_usergroup = (
|
||||||
select(Course)
|
select(Course)
|
||||||
.join(Organization)
|
.join(Organization)
|
||||||
.join(
|
.join(UserGroupResource, UserGroupResource.resource_uuid == Course.course_uuid)
|
||||||
UserGroupResource, UserGroupResource.resource_uuid == Course.course_uuid
|
|
||||||
)
|
|
||||||
.join(
|
.join(
|
||||||
UserGroupUser, UserGroupUser.usergroup_id == UserGroupResource.usergroup_id
|
UserGroupUser, UserGroupUser.usergroup_id == UserGroupResource.usergroup_id
|
||||||
)
|
)
|
||||||
|
|
@ -365,10 +361,12 @@ async def get_courses_orgslug(
|
||||||
statement_public, statement_author, statement_usergroup
|
statement_public, statement_author, statement_usergroup
|
||||||
).subquery()
|
).subquery()
|
||||||
|
|
||||||
courses = db_session.execute(select([statement_complete])).all()
|
# TODO: migrate this to exec
|
||||||
|
courses = db_session.execute(select(statement_complete)).all()
|
||||||
|
|
||||||
# TODO: I have no idea why this is necessary, but it is
|
# TODO: I have no idea why this is necessary, but it is
|
||||||
courses = [CourseRead(**dict(course._mapping), authors=[]) for course in courses]
|
courses = [CourseRead(**course._asdict(), authors=[]) for course in courses]
|
||||||
|
|
||||||
|
|
||||||
# for every course, get the authors
|
# for every course, get the authors
|
||||||
for course in courses:
|
for course in courses:
|
||||||
|
|
@ -380,7 +378,7 @@ async def get_courses_orgslug(
|
||||||
authors = db_session.exec(authors_statement).all()
|
authors = db_session.exec(authors_statement).all()
|
||||||
|
|
||||||
# convert from User to UserRead
|
# convert from User to UserRead
|
||||||
authors = [UserRead.from_orm(author) for author in authors]
|
authors = [UserRead.model_validate(author) for author in authors]
|
||||||
|
|
||||||
course.authors = authors
|
course.authors = authors
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ async def isInstallModeEnabled():
|
||||||
|
|
||||||
|
|
||||||
async def create_install_instance(request: Request, data: dict, db_session: Session):
|
async def create_install_instance(request: Request, data: dict, db_session: Session):
|
||||||
install = Install.from_orm(data)
|
install = Install.model_validate(data)
|
||||||
|
|
||||||
# complete install instance
|
# complete install instance
|
||||||
install.install_uuid = str(f"install_{uuid4()}")
|
install.install_uuid = str(f"install_{uuid4()}")
|
||||||
|
|
@ -41,7 +41,7 @@ async def create_install_instance(request: Request, data: dict, db_session: Sess
|
||||||
# refresh install instance
|
# refresh install instance
|
||||||
db_session.refresh(install)
|
db_session.refresh(install)
|
||||||
|
|
||||||
install = InstallRead.from_orm(install)
|
install = InstallRead.model_validate(install)
|
||||||
|
|
||||||
return install
|
return install
|
||||||
|
|
||||||
|
|
@ -56,7 +56,7 @@ async def get_latest_install_instance(request: Request, db_session: Session):
|
||||||
detail="No install instance found",
|
detail="No install instance found",
|
||||||
)
|
)
|
||||||
|
|
||||||
install = InstallRead.from_orm(install)
|
install = InstallRead.model_validate(install)
|
||||||
|
|
||||||
return install
|
return install
|
||||||
|
|
||||||
|
|
@ -82,7 +82,7 @@ async def update_install_instance(
|
||||||
# refresh install instance
|
# refresh install instance
|
||||||
db_session.refresh(install)
|
db_session.refresh(install)
|
||||||
|
|
||||||
install = InstallRead.from_orm(install)
|
install = InstallRead.model_validate(install)
|
||||||
|
|
||||||
return install
|
return install
|
||||||
|
|
||||||
|
|
@ -279,9 +279,9 @@ async def install_default_elements(db_session: Session):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Serialize rights to JSON
|
# Serialize rights to JSON
|
||||||
role_global_admin.rights = role_global_admin.rights.dict() # type: ignore
|
role_global_admin.rights = role_global_admin.rights.model_dump() # type: ignore
|
||||||
role_global_maintainer.rights = role_global_maintainer.rights.dict() # type: ignore
|
role_global_maintainer.rights = role_global_maintainer.rights.model_dump() # type: ignore
|
||||||
role_global_user.rights = role_global_user.rights.dict() # type: ignore
|
role_global_user.rights = role_global_user.rights.model_dump() # type: ignore
|
||||||
|
|
||||||
# Insert roles in DB
|
# Insert roles in DB
|
||||||
db_session.add(role_global_admin)
|
db_session.add(role_global_admin)
|
||||||
|
|
@ -301,7 +301,7 @@ async def install_default_elements(db_session: Session):
|
||||||
async def install_create_organization(
|
async def install_create_organization(
|
||||||
org_object: OrganizationCreate, db_session: Session
|
org_object: OrganizationCreate, db_session: Session
|
||||||
):
|
):
|
||||||
org = Organization.from_orm(org_object)
|
org = Organization.model_validate(org_object)
|
||||||
|
|
||||||
# Complete the org object
|
# Complete the org object
|
||||||
org.org_uuid = f"org_{uuid4()}"
|
org.org_uuid = f"org_{uuid4()}"
|
||||||
|
|
@ -318,7 +318,7 @@ async def install_create_organization(
|
||||||
async def install_create_organization_user(
|
async def install_create_organization_user(
|
||||||
user_object: UserCreate, org_slug: str, db_session: Session
|
user_object: UserCreate, org_slug: str, db_session: Session
|
||||||
):
|
):
|
||||||
user = User.from_orm(user_object)
|
user = User.model_validate(user_object)
|
||||||
|
|
||||||
# Complete the user object
|
# Complete the user object
|
||||||
user.user_uuid = f"user_{uuid4()}"
|
user.user_uuid = f"user_{uuid4()}"
|
||||||
|
|
@ -390,6 +390,6 @@ async def install_create_organization_user(
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(user_organization)
|
db_session.refresh(user_organization)
|
||||||
|
|
||||||
user = UserRead.from_orm(user)
|
user = UserRead.model_validate(user)
|
||||||
|
|
||||||
return user
|
return user
|
||||||
|
|
|
||||||
|
|
@ -59,9 +59,9 @@ async def get_organization(
|
||||||
if org_config is None:
|
if org_config is None:
|
||||||
logging.error(f"Organization {org_id} has no config")
|
logging.error(f"Organization {org_id} has no config")
|
||||||
|
|
||||||
config = OrganizationConfig.from_orm(org_config) if org_config else {}
|
config = OrganizationConfig.model_validate(org_config) if org_config else {}
|
||||||
|
|
||||||
org = OrganizationRead(**org.dict(), config=config)
|
org = OrganizationRead(**org.model_dump(), config=config)
|
||||||
|
|
||||||
return org
|
return org
|
||||||
|
|
||||||
|
|
@ -95,9 +95,9 @@ async def get_organization_by_slug(
|
||||||
if org_config is None:
|
if org_config is None:
|
||||||
logging.error(f"Organization {org_slug} has no config")
|
logging.error(f"Organization {org_slug} has no config")
|
||||||
|
|
||||||
config = OrganizationConfig.from_orm(org_config) if org_config else {}
|
config = OrganizationConfig.model_validate(org_config) if org_config else {}
|
||||||
|
|
||||||
org = OrganizationRead(**org.dict(), config=config)
|
org = OrganizationRead(**org.model_dump(), config=config)
|
||||||
|
|
||||||
return org
|
return org
|
||||||
|
|
||||||
|
|
@ -119,7 +119,7 @@ async def create_org(
|
||||||
detail="Organization already exists",
|
detail="Organization already exists",
|
||||||
)
|
)
|
||||||
|
|
||||||
org = Organization.from_orm(org_object)
|
org = Organization.model_validate(org_object)
|
||||||
|
|
||||||
if isinstance(current_user, AnonymousUser):
|
if isinstance(current_user, AnonymousUser):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -203,9 +203,9 @@ async def create_org(
|
||||||
if org_config is None:
|
if org_config is None:
|
||||||
logging.error(f"Organization {org.id} has no config")
|
logging.error(f"Organization {org.id} has no config")
|
||||||
|
|
||||||
config = OrganizationConfig.from_orm(org_config)
|
config = OrganizationConfig.model_validate(org_config)
|
||||||
|
|
||||||
org = OrganizationRead(**org.dict(), config=config)
|
org = OrganizationRead(**org.model_dump(), config=config)
|
||||||
|
|
||||||
return org
|
return org
|
||||||
|
|
||||||
|
|
@ -229,7 +229,7 @@ async def create_org_with_config(
|
||||||
detail="Organization already exists",
|
detail="Organization already exists",
|
||||||
)
|
)
|
||||||
|
|
||||||
org = Organization.from_orm(org_object)
|
org = Organization.model_validate(org_object)
|
||||||
|
|
||||||
if isinstance(current_user, AnonymousUser):
|
if isinstance(current_user, AnonymousUser):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -284,9 +284,9 @@ async def create_org_with_config(
|
||||||
if org_config is None:
|
if org_config is None:
|
||||||
logging.error(f"Organization {org.id} has no config")
|
logging.error(f"Organization {org.id} has no config")
|
||||||
|
|
||||||
config = OrganizationConfig.from_orm(org_config)
|
config = OrganizationConfig.model_validate(org_config)
|
||||||
|
|
||||||
org = OrganizationRead(**org.dict(), config=config)
|
org = OrganizationRead(**org.model_dump(), config=config)
|
||||||
|
|
||||||
return org
|
return org
|
||||||
|
|
||||||
|
|
@ -336,7 +336,7 @@ async def update_org(
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(org)
|
db_session.refresh(org)
|
||||||
|
|
||||||
org = OrganizationRead.from_orm(org)
|
org = OrganizationRead.model_validate(org)
|
||||||
|
|
||||||
return org
|
return org
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,8 +84,8 @@ async def get_organization_users(
|
||||||
# skip this user
|
# skip this user
|
||||||
continue
|
continue
|
||||||
|
|
||||||
user = UserRead.from_orm(user)
|
user = UserRead.model_validate(user)
|
||||||
role = RoleRead.from_orm(role)
|
role = RoleRead.model_validate(role)
|
||||||
|
|
||||||
org_user = OrganizationUser(
|
org_user = OrganizationUser(
|
||||||
user=user,
|
user=user,
|
||||||
|
|
@ -293,8 +293,8 @@ async def invite_batch_users(
|
||||||
# skip this user
|
# skip this user
|
||||||
continue
|
continue
|
||||||
|
|
||||||
org = OrganizationRead.from_orm(org)
|
org = OrganizationRead.model_validate(org)
|
||||||
user = UserRead.from_orm(user)
|
user = UserRead.model_validate(user)
|
||||||
|
|
||||||
isEmailSent = send_invite_email(
|
isEmailSent = send_invite_email(
|
||||||
org,
|
org,
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ async def create_role(
|
||||||
role_object: RoleCreate,
|
role_object: RoleCreate,
|
||||||
current_user: PublicUser,
|
current_user: PublicUser,
|
||||||
):
|
):
|
||||||
role = Role.from_orm(role_object)
|
role = Role.model_validate(role_object)
|
||||||
|
|
||||||
# RBAC check
|
# RBAC check
|
||||||
await rbac_check(request, current_user, "create", "role_xxx", db_session)
|
await rbac_check(request, current_user, "create", "role_xxx", db_session)
|
||||||
|
|
@ -31,7 +31,7 @@ async def create_role(
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(role)
|
db_session.refresh(role)
|
||||||
|
|
||||||
role = RoleRead(**role.dict())
|
role = RoleRead(**role.model_dump())
|
||||||
|
|
||||||
return role
|
return role
|
||||||
|
|
||||||
|
|
@ -53,7 +53,7 @@ async def read_role(
|
||||||
# RBAC check
|
# RBAC check
|
||||||
await rbac_check(request, current_user, "read", role.role_uuid, db_session)
|
await rbac_check(request, current_user, "read", role.role_uuid, db_session)
|
||||||
|
|
||||||
role = RoleRead(**role.dict())
|
role = RoleRead(**role.model_dump())
|
||||||
|
|
||||||
return role
|
return role
|
||||||
|
|
||||||
|
|
@ -93,7 +93,7 @@ async def update_role(
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(role)
|
db_session.refresh(role)
|
||||||
|
|
||||||
role = RoleRead(**role.dict())
|
role = RoleRead(**role.model_dump())
|
||||||
|
|
||||||
return role
|
return role
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ async def create_user_trail(
|
||||||
detail="Trail already exists",
|
detail="Trail already exists",
|
||||||
)
|
)
|
||||||
|
|
||||||
trail = Trail.from_orm(trail_object)
|
trail = Trail.model_validate(trail_object)
|
||||||
|
|
||||||
trail.creation_date = str(datetime.now())
|
trail.creation_date = str(datetime.now())
|
||||||
trail.update_date = str(datetime.now())
|
trail.update_date = str(datetime.now())
|
||||||
|
|
@ -91,7 +91,7 @@ async def get_user_trails(
|
||||||
trail_step.data = dict(course=course)
|
trail_step.data = dict(course=course)
|
||||||
|
|
||||||
trail_read = TrailRead(
|
trail_read = TrailRead(
|
||||||
**trail.dict(),
|
**trail.model_dump(),
|
||||||
runs=trail_runs,
|
runs=trail_runs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -176,7 +176,7 @@ async def get_user_trail_with_orgid(
|
||||||
trail_step.data = dict(course=course)
|
trail_step.data = dict(course=course)
|
||||||
|
|
||||||
trail_read = TrailRead(
|
trail_read = TrailRead(
|
||||||
**trail.dict(),
|
**trail.model_dump(),
|
||||||
runs=trail_runs,
|
runs=trail_runs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -276,7 +276,7 @@ async def add_activity_to_trail(
|
||||||
trail_step.data = dict(course=course)
|
trail_step.data = dict(course=course)
|
||||||
|
|
||||||
trail_read = TrailRead(
|
trail_read = TrailRead(
|
||||||
**trail.dict(),
|
**trail.model_dump(),
|
||||||
runs=trail_runs,
|
runs=trail_runs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -357,7 +357,7 @@ async def add_course_to_trail(
|
||||||
trail_step.data = dict(course=course)
|
trail_step.data = dict(course=course)
|
||||||
|
|
||||||
trail_read = TrailRead(
|
trail_read = TrailRead(
|
||||||
**trail.dict(),
|
**trail.model_dump(),
|
||||||
runs=trail_runs,
|
runs=trail_runs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -426,7 +426,7 @@ async def remove_course_from_trail(
|
||||||
trail_step.data = dict(course=course)
|
trail_step.data = dict(course=course)
|
||||||
|
|
||||||
trail_read = TrailRead(
|
trail_read = TrailRead(
|
||||||
**trail.dict(),
|
**trail.model_dump(),
|
||||||
runs=trail_runs,
|
runs=trail_runs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,9 +93,9 @@ async def send_reset_password_code(
|
||||||
ex=ttl,
|
ex=ttl,
|
||||||
)
|
)
|
||||||
|
|
||||||
user = UserRead.from_orm(user)
|
user = UserRead.model_validate(user)
|
||||||
|
|
||||||
org = OrganizationRead.from_orm(org)
|
org = OrganizationRead.model_validate(org)
|
||||||
|
|
||||||
# Send reset code via email
|
# Send reset code via email
|
||||||
isEmailSent = send_password_reset_email(
|
isEmailSent = send_password_reset_email(
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ async def create_usergroup(
|
||||||
usergroup_create: UserGroupCreate,
|
usergroup_create: UserGroupCreate,
|
||||||
) -> UserGroupRead:
|
) -> UserGroupRead:
|
||||||
|
|
||||||
usergroup = UserGroup.from_orm(usergroup_create)
|
usergroup = UserGroup.model_validate(usergroup_create)
|
||||||
|
|
||||||
# RBAC check
|
# RBAC check
|
||||||
await rbac_check(
|
await rbac_check(
|
||||||
|
|
@ -53,7 +53,7 @@ async def create_usergroup(
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(usergroup)
|
db_session.refresh(usergroup)
|
||||||
|
|
||||||
usergroup = UserGroupRead.from_orm(usergroup)
|
usergroup = UserGroupRead.model_validate(usergroup)
|
||||||
|
|
||||||
return usergroup
|
return usergroup
|
||||||
|
|
||||||
|
|
@ -83,7 +83,7 @@ async def read_usergroup_by_id(
|
||||||
db_session=db_session,
|
db_session=db_session,
|
||||||
)
|
)
|
||||||
|
|
||||||
usergroup = UserGroupRead.from_orm(usergroup)
|
usergroup = UserGroupRead.model_validate(usergroup)
|
||||||
|
|
||||||
return usergroup
|
return usergroup
|
||||||
|
|
||||||
|
|
@ -125,7 +125,7 @@ async def get_users_linked_to_usergroup(
|
||||||
user = db_session.exec(statement).first()
|
user = db_session.exec(statement).first()
|
||||||
users.append(user)
|
users.append(user)
|
||||||
|
|
||||||
users = [UserRead.from_orm(user) for user in users]
|
users = [UserRead.model_validate(user) for user in users]
|
||||||
|
|
||||||
return users
|
return users
|
||||||
|
|
||||||
|
|
@ -149,7 +149,7 @@ async def read_usergroups_by_org_id(
|
||||||
db_session=db_session,
|
db_session=db_session,
|
||||||
)
|
)
|
||||||
|
|
||||||
usergroups = [UserGroupRead.from_orm(usergroup) for usergroup in usergroups]
|
usergroups = [UserGroupRead.model_validate(usergroup) for usergroup in usergroups]
|
||||||
|
|
||||||
return usergroups
|
return usergroups
|
||||||
|
|
||||||
|
|
@ -184,7 +184,7 @@ async def get_usergroups_by_resource(
|
||||||
usergroup = db_session.exec(statement).first()
|
usergroup = db_session.exec(statement).first()
|
||||||
usergroups.append(usergroup)
|
usergroups.append(usergroup)
|
||||||
|
|
||||||
usergroups = [UserGroupRead.from_orm(usergroup) for usergroup in usergroups]
|
usergroups = [UserGroupRead.model_validate(usergroup) for usergroup in usergroups]
|
||||||
|
|
||||||
return usergroups
|
return usergroups
|
||||||
|
|
||||||
|
|
@ -223,7 +223,7 @@ async def update_usergroup_by_id(
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(usergroup)
|
db_session.refresh(usergroup)
|
||||||
|
|
||||||
usergroup = UserGroupRead.from_orm(usergroup)
|
usergroup = UserGroupRead.model_validate(usergroup)
|
||||||
|
|
||||||
return usergroup
|
return usergroup
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ async def create_user(
|
||||||
user_object: UserCreate,
|
user_object: UserCreate,
|
||||||
org_id: int,
|
org_id: int,
|
||||||
):
|
):
|
||||||
user = User.from_orm(user_object)
|
user = User.model_validate(user_object)
|
||||||
|
|
||||||
# RBAC check
|
# RBAC check
|
||||||
await rbac_check(request, current_user, "create", "user_x", db_session)
|
await rbac_check(request, current_user, "create", "user_x", db_session)
|
||||||
|
|
@ -104,7 +104,7 @@ async def create_user(
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(user_organization)
|
db_session.refresh(user_organization)
|
||||||
|
|
||||||
user = UserRead.from_orm(user)
|
user = UserRead.model_validate(user)
|
||||||
|
|
||||||
# Send Account creation email
|
# Send Account creation email
|
||||||
send_account_creation_email(
|
send_account_creation_email(
|
||||||
|
|
@ -157,7 +157,7 @@ async def create_user_without_org(
|
||||||
current_user: PublicUser | AnonymousUser,
|
current_user: PublicUser | AnonymousUser,
|
||||||
user_object: UserCreate,
|
user_object: UserCreate,
|
||||||
):
|
):
|
||||||
user = User.from_orm(user_object)
|
user = User.model_validate(user_object)
|
||||||
|
|
||||||
# RBAC check
|
# RBAC check
|
||||||
await rbac_check(request, current_user, "create", "user_x", db_session)
|
await rbac_check(request, current_user, "create", "user_x", db_session)
|
||||||
|
|
@ -201,7 +201,7 @@ async def create_user_without_org(
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(user)
|
db_session.refresh(user)
|
||||||
|
|
||||||
user = UserRead.from_orm(user)
|
user = UserRead.model_validate(user)
|
||||||
|
|
||||||
# Send Account creation email
|
# Send Account creation email
|
||||||
send_account_creation_email(
|
send_account_creation_email(
|
||||||
|
|
@ -270,7 +270,7 @@ async def update_user(
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(user)
|
db_session.refresh(user)
|
||||||
|
|
||||||
user = UserRead.from_orm(user)
|
user = UserRead.model_validate(user)
|
||||||
|
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
@ -315,7 +315,7 @@ async def update_user_avatar(
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(user)
|
db_session.refresh(user)
|
||||||
|
|
||||||
user = UserRead.from_orm(user)
|
user = UserRead.model_validate(user)
|
||||||
|
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
@ -354,7 +354,7 @@ async def update_user_password(
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
db_session.refresh(user)
|
db_session.refresh(user)
|
||||||
|
|
||||||
user = UserRead.from_orm(user)
|
user = UserRead.model_validate(user)
|
||||||
|
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
@ -378,7 +378,7 @@ async def read_user_by_id(
|
||||||
# RBAC check
|
# RBAC check
|
||||||
await rbac_check(request, current_user, "read", user.user_uuid, db_session)
|
await rbac_check(request, current_user, "read", user.user_uuid, db_session)
|
||||||
|
|
||||||
user = UserRead.from_orm(user)
|
user = UserRead.model_validate(user)
|
||||||
|
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
@ -402,7 +402,7 @@ async def read_user_by_uuid(
|
||||||
# RBAC check
|
# RBAC check
|
||||||
await rbac_check(request, current_user, "read", user.user_uuid, db_session)
|
await rbac_check(request, current_user, "read", user.user_uuid, db_session)
|
||||||
|
|
||||||
user = UserRead.from_orm(user)
|
user = UserRead.model_validate(user)
|
||||||
|
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
@ -422,7 +422,7 @@ async def get_user_session(
|
||||||
detail="User does not exist",
|
detail="User does not exist",
|
||||||
)
|
)
|
||||||
|
|
||||||
user = UserRead.from_orm(user)
|
user = UserRead.model_validate(user)
|
||||||
|
|
||||||
# Get roles and orgs
|
# Get roles and orgs
|
||||||
statement = (
|
statement = (
|
||||||
|
|
@ -445,8 +445,8 @@ async def get_user_session(
|
||||||
|
|
||||||
roles.append(
|
roles.append(
|
||||||
UserRoleWithOrg(
|
UserRoleWithOrg(
|
||||||
role=RoleRead.from_orm(role),
|
role=RoleRead.model_validate(role),
|
||||||
org=OrganizationRead.from_orm(org),
|
org=OrganizationRead.model_validate(org),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -531,7 +531,7 @@ async def security_get_user(request: Request, db_session: Session, email: str) -
|
||||||
detail="User with Email does not exist",
|
detail="User with Email does not exist",
|
||||||
)
|
)
|
||||||
|
|
||||||
user = User(**user.dict())
|
user = User(**user.model_dump())
|
||||||
|
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue