mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: get config with orgs
This commit is contained in:
parent
66610a1493
commit
1423e4c432
3 changed files with 34 additions and 6 deletions
|
|
@ -20,6 +20,10 @@ class Organization(OrganizationBase, table=True):
|
||||||
creation_date: str = ""
|
creation_date: str = ""
|
||||||
update_date: str = ""
|
update_date: str = ""
|
||||||
|
|
||||||
|
class OrganizationWithConfig(BaseModel):
|
||||||
|
org: Organization
|
||||||
|
config: OrganizationConfig
|
||||||
|
|
||||||
|
|
||||||
class OrganizationUpdate(OrganizationBase):
|
class OrganizationUpdate(OrganizationBase):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ from src.services.orgs.users import (
|
||||||
from src.db.organization_config import OrganizationConfigBase
|
from src.db.organization_config import OrganizationConfigBase
|
||||||
from src.db.users import PublicUser
|
from src.db.users import PublicUser
|
||||||
from src.db.organizations import (
|
from src.db.organizations import (
|
||||||
Organization,
|
|
||||||
OrganizationCreate,
|
OrganizationCreate,
|
||||||
OrganizationRead,
|
OrganizationRead,
|
||||||
OrganizationUpdate,
|
OrganizationUpdate,
|
||||||
|
|
@ -321,7 +320,7 @@ async def api_user_orgs(
|
||||||
limit: int,
|
limit: int,
|
||||||
current_user: PublicUser = Depends(get_current_user),
|
current_user: PublicUser = Depends(get_current_user),
|
||||||
db_session: Session = Depends(get_db_session),
|
db_session: Session = Depends(get_db_session),
|
||||||
) -> List[Organization]:
|
) -> List[OrganizationRead]:
|
||||||
"""
|
"""
|
||||||
Get orgs by page and limit by current user
|
Get orgs by page and limit by current user
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -209,6 +209,7 @@ async def create_org(
|
||||||
|
|
||||||
return org
|
return org
|
||||||
|
|
||||||
|
|
||||||
async def create_org_with_config(
|
async def create_org_with_config(
|
||||||
request: Request,
|
request: Request,
|
||||||
org_object: OrganizationCreate,
|
org_object: OrganizationCreate,
|
||||||
|
|
@ -338,6 +339,7 @@ async def update_org(
|
||||||
|
|
||||||
return org
|
return org
|
||||||
|
|
||||||
|
|
||||||
async def update_org_with_config_no_auth(
|
async def update_org_with_config_no_auth(
|
||||||
request: Request,
|
request: Request,
|
||||||
orgconfig: OrganizationConfigBase,
|
orgconfig: OrganizationConfigBase,
|
||||||
|
|
@ -462,20 +464,43 @@ async def get_orgs_by_user(
|
||||||
user_id: str,
|
user_id: str,
|
||||||
page: int = 1,
|
page: int = 1,
|
||||||
limit: int = 10,
|
limit: int = 10,
|
||||||
) -> list[Organization]:
|
) -> list[OrganizationRead]:
|
||||||
|
|
||||||
statement = (
|
statement = (
|
||||||
select(Organization)
|
select(Organization)
|
||||||
.join(UserOrganization)
|
.join(UserOrganization)
|
||||||
.where(
|
.where(
|
||||||
Organization.id == UserOrganization.org_id,
|
|
||||||
UserOrganization.user_id == user_id,
|
UserOrganization.user_id == user_id,
|
||||||
|
UserOrganization.role_id == 1, # Only where the user is admin
|
||||||
)
|
)
|
||||||
|
.offset((page - 1) * limit)
|
||||||
|
.limit(limit)
|
||||||
)
|
)
|
||||||
result = db_session.exec(statement)
|
|
||||||
|
|
||||||
|
# Get organizations where the user is an admin
|
||||||
|
result = db_session.exec(statement)
|
||||||
orgs = result.all()
|
orgs = result.all()
|
||||||
|
|
||||||
return orgs #type:ignore
|
orgsWithConfig = []
|
||||||
|
|
||||||
|
for org in orgs:
|
||||||
|
|
||||||
|
# Get org config
|
||||||
|
statement = select(OrganizationConfig).where(
|
||||||
|
OrganizationConfig.org_id == org.id
|
||||||
|
)
|
||||||
|
result = db_session.exec(statement)
|
||||||
|
|
||||||
|
org_config = result.first()
|
||||||
|
|
||||||
|
config = OrganizationConfig.model_validate(org_config) if org_config else {}
|
||||||
|
|
||||||
|
org = OrganizationRead(**org.model_dump(), config=config)
|
||||||
|
|
||||||
|
orgsWithConfig.append(org)
|
||||||
|
|
||||||
|
return orgsWithConfig
|
||||||
|
|
||||||
|
|
||||||
# Config related
|
# Config related
|
||||||
async def update_org_signup_mechanism(
|
async def update_org_signup_mechanism(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue