mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: support account creation without an org
This commit is contained in:
parent
23036351a8
commit
4aa2d537e1
1 changed files with 18 additions and 10 deletions
|
|
@ -2,7 +2,10 @@ from datetime import datetime
|
||||||
from typing import Literal
|
from typing import Literal
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
from fastapi import HTTPException, Request, status
|
from fastapi import HTTPException, Request, status
|
||||||
from src.security.rbac.rbac import authorization_verify_based_on_roles, authorization_verify_if_user_is_anon
|
from src.security.rbac.rbac import (
|
||||||
|
authorization_verify_based_on_roles,
|
||||||
|
authorization_verify_if_user_is_anon,
|
||||||
|
)
|
||||||
from src.security.security import security_hash_password, security_verify_password
|
from src.security.security import security_hash_password, security_verify_password
|
||||||
from src.services.users.schemas.users import (
|
from src.services.users.schemas.users import (
|
||||||
PasswordChangeForm,
|
PasswordChangeForm,
|
||||||
|
|
@ -55,19 +58,27 @@ async def create_user(
|
||||||
isOrgExists = await orgs.find_one({"slug": org_slug})
|
isOrgExists = await orgs.find_one({"slug": org_slug})
|
||||||
|
|
||||||
# If the org does not exist, raise an error
|
# If the org does not exist, raise an error
|
||||||
if not isOrgExists:
|
if not isOrgExists and (org_slug != "None"):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_409_CONFLICT,
|
status_code=status.HTTP_409_CONFLICT,
|
||||||
detail="You are trying to create a user in an organization that does not exist",
|
detail="You are trying to create a user in an organization that does not exist",
|
||||||
)
|
)
|
||||||
|
|
||||||
org_id = isOrgExists["org_id"]
|
org_id = isOrgExists["org_id"] if org_slug != "None" else ''
|
||||||
|
|
||||||
# Create initial orgs list with the org_id passed in
|
# Create initial orgs list with the org_id passed in
|
||||||
orgs = [UserOrganization(org_id=org_id, org_role="member")]
|
orgs = (
|
||||||
|
[UserOrganization(org_id=org_id, org_role="member")]
|
||||||
|
if org_slug != "None"
|
||||||
|
else []
|
||||||
|
)
|
||||||
|
|
||||||
# Give role
|
# Give role
|
||||||
roles = [UserRolesInOrganization(role_id="role_member", org_id=org_id)]
|
roles = (
|
||||||
|
[UserRolesInOrganization(role_id="role_member", org_id=org_id)]
|
||||||
|
if org_slug != "None"
|
||||||
|
else []
|
||||||
|
)
|
||||||
|
|
||||||
# Create the user
|
# Create the user
|
||||||
user = UserInDB(
|
user = UserInDB(
|
||||||
|
|
@ -266,7 +277,6 @@ async def verify_user_rights_on_user(
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if action == "read":
|
if action == "read":
|
||||||
|
|
||||||
await authorization_verify_if_user_is_anon(current_user.user_id)
|
await authorization_verify_if_user_is_anon(current_user.user_id)
|
||||||
|
|
||||||
if current_user.user_id == user_id:
|
if current_user.user_id == user_id:
|
||||||
|
|
@ -279,7 +289,6 @@ async def verify_user_rights_on_user(
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if action == "update":
|
if action == "update":
|
||||||
|
|
||||||
await authorization_verify_if_user_is_anon(current_user.user_id)
|
await authorization_verify_if_user_is_anon(current_user.user_id)
|
||||||
|
|
||||||
if current_user.user_id == user_id:
|
if current_user.user_id == user_id:
|
||||||
|
|
@ -297,7 +306,6 @@ async def verify_user_rights_on_user(
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if action == "delete":
|
if action == "delete":
|
||||||
|
|
||||||
await authorization_verify_if_user_is_anon(current_user.user_id)
|
await authorization_verify_if_user_is_anon(current_user.user_id)
|
||||||
|
|
||||||
if current_user.user_id == user_id:
|
if current_user.user_id == user_id:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue