Skip to content

Commit e64785c

Browse files
Ken LippoldKen Lippold
authored andcommitted
Minor bug fixes
1 parent 5afea83 commit e64785c

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

iam/schemas/account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class OrganizationFields(Schema):
1111
code: str = Field(..., max_length=255)
12-
name: str = Field(..., max_length=30)
12+
name: str = Field(..., max_length=255)
1313
description: Optional[str] = None
1414
link: Optional[str] = Field(None, max_length=2000)
1515
organization_type: str = Field(..., max_length=255, alias="type")

iam/services/account.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ def update(user: User, data: AccountPatchBody):
4848
exclude=["organization"],
4949
exclude_unset=True,
5050
)
51+
update_organization = "organization" in data.dict(
52+
include=["organization"],
53+
exclude_unset=True,
54+
)
55+
5156
organization_body = (
5257
data.organization.dict(
5358
include=set(data.organization.model_fields.keys()),
@@ -60,13 +65,18 @@ def update(user: User, data: AccountPatchBody):
6065
for field, value in user_body.items():
6166
setattr(user, field, value)
6267

63-
if organization_body:
64-
if user.organization:
65-
for field, value in organization_body.items():
66-
setattr(user.organization, field, value)
67-
user.organization.save()
68+
if update_organization:
69+
if organization_body:
70+
if user.organization:
71+
for field, value in organization_body.items():
72+
setattr(user.organization, field, value)
73+
user.organization.save()
74+
else:
75+
user.organization = Organization.objects.create(**organization_body)
6876
else:
69-
user.organization = Organization.objects.create(**organization_body)
77+
if user.organization:
78+
user.organization.delete()
79+
user.organization = None
7080

7181
except ValueError as e:
7282
raise HttpError(422, str(e))

0 commit comments

Comments
 (0)