mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: invite-only org signup
This commit is contained in:
parent
689625b0d5
commit
0d775a0fe9
22 changed files with 1733 additions and 387 deletions
|
|
@ -1,6 +1,7 @@
|
|||
from typing import Literal
|
||||
from fastapi import APIRouter, Depends, Request, UploadFile
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, UploadFile
|
||||
from sqlmodel import Session
|
||||
from src.services.orgs.orgs import get_org_join_mechanism
|
||||
from src.security.auth import get_current_user
|
||||
from src.core.events.database import get_db_session
|
||||
|
||||
|
|
@ -16,6 +17,7 @@ from src.db.users import (
|
|||
from src.services.users.users import (
|
||||
authorize_user_action,
|
||||
create_user,
|
||||
create_user_with_invite,
|
||||
create_user_without_org,
|
||||
delete_user_by_id,
|
||||
get_user_session,
|
||||
|
|
@ -78,7 +80,48 @@ async def api_create_user_with_orgid(
|
|||
"""
|
||||
Create User with Org ID
|
||||
"""
|
||||
return await create_user(request, db_session, current_user, user_object, org_id)
|
||||
print(await get_org_join_mechanism(request, org_id, current_user, db_session))
|
||||
|
||||
# TODO(fix) : This is temporary, logic should be moved to service
|
||||
if (
|
||||
await get_org_join_mechanism(request, org_id, current_user, db_session)
|
||||
== "inviteOnly"
|
||||
):
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail="You need an invite to join this organization",
|
||||
)
|
||||
else:
|
||||
return await create_user(request, db_session, current_user, user_object, org_id)
|
||||
|
||||
|
||||
@router.post("/{org_id}/invite/{invite_code}", response_model=UserRead, tags=["users"])
|
||||
async def api_create_user_with_orgid_and_invite(
|
||||
*,
|
||||
request: Request,
|
||||
db_session: Session = Depends(get_db_session),
|
||||
current_user: PublicUser = Depends(get_current_user),
|
||||
user_object: UserCreate,
|
||||
invite_code: str,
|
||||
org_id: int,
|
||||
) -> UserRead:
|
||||
"""
|
||||
Create User with Org ID and invite code
|
||||
"""
|
||||
|
||||
# TODO: This is temporary, logic should be moved to service
|
||||
if (
|
||||
await get_org_join_mechanism(request, org_id, current_user, db_session)
|
||||
== "inviteOnly"
|
||||
):
|
||||
return await create_user_with_invite(
|
||||
request, db_session, current_user, user_object, org_id, invite_code
|
||||
)
|
||||
else:
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail="This organization does not require an invite code",
|
||||
)
|
||||
|
||||
|
||||
@router.post("/", response_model=UserRead, tags=["users"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue