Skip to content

Commit a66e5db

Browse files
authored
Prevent kern users from being deleted on org deletion (#352)
1 parent 2848b62 commit a66e5db

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

controller/organization/manager.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ def create_organization(name: str) -> Organization:
9393

9494
def delete_organization(name: str) -> None:
9595
org = organization.get_by_name(name)
96+
97+
if not org:
98+
return
99+
all_users = user.get_all(org.id)
100+
unassigned = False
101+
for u in all_users:
102+
if (u.email or "").endswith("@kern.ai"):
103+
unassigned = True
104+
u.organization_id = None
105+
if unassigned:
106+
general.commit()
107+
96108
organization.delete(org.id, with_commit=True)
97109

98110

0 commit comments

Comments
 (0)