Skip to content

Commit e58a07a

Browse files
committed
Fixed users not being in a default organization at account creation
1 parent 429542a commit e58a07a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

backend/app/api/routes/users.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ def register_user(session: SessionDep, user_in: UserRegister) -> Any:
152152
)
153153
user_create = UserCreate.model_validate(user_in)
154154
user = crud.create_user(session=session, user_create=user_create)
155+
156+
# Assign user to default organization
157+
default_org = crud.get_default_organization(session=session)
158+
if default_org:
159+
user.organization_id = default_org.id
160+
session.add(user)
161+
session.commit()
162+
session.refresh(user)
163+
155164
return user
156165

157166

backend/app/crud.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ def get_organization(
9292
return session.get(Organization, organization_id)
9393

9494

95+
def get_default_organization(*, session: Session) -> Organization | None:
96+
"""Get the default organization (typically 'Default Organization')"""
97+
statement = select(Organization).where(Organization.name == "Default Organization")
98+
return session.exec(statement).first()
99+
100+
95101
def update_organization(
96102
*,
97103
session: Session,

0 commit comments

Comments
 (0)