Skip to content

Commit

Permalink
Fix updating an organization
Browse files Browse the repository at this point in the history
  • Loading branch information
aloftus23 committed Dec 5, 2024
1 parent 2b0dc22 commit 6338cd4
Showing 1 changed file with 44 additions and 6 deletions.
50 changes: 44 additions & 6 deletions backend/src/xfd_django/xfd_api/api_methods/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,13 @@ def create_organization(organization_data, current_user):
tags = find_or_create_tags(organization_data.tags)
organization.tags.add(*tags)

if isinstance(organization.pendingDomains, str):
pending_domains = json.loads(organization.pendingDomains)
elif isinstance(organization.pendingDomains, list):
pending_domains = organization.pendingDomains
else:
pending_domains = []

# Return the organization details in response
return {
"id": str(organization.id),
Expand All @@ -415,7 +422,7 @@ def create_organization(organization_data, current_user):
"rootDomains": organization.rootDomains,
"ipBlocks": organization.ipBlocks,
"isPassive": organization.isPassive,
"pendingDomains": organization.pendingDomains,
"pendingDomains": pending_domains,
"country": organization.country,
"state": organization.state,
"regionId": organization.regionId,
Expand Down Expand Up @@ -490,6 +497,13 @@ def upsert_organization(organization_data, current_user):
tags = find_or_create_tags(organization_data.tags)
organization.tags.add(*tags)

if isinstance(organization.pendingDomains, str):
pending_domains = json.loads(organization.pendingDomains)
elif isinstance(organization.pendingDomains, list):
pending_domains = organization.pendingDomains
else:
pending_domains = []

# Return the organization details in response
return {
"id": str(organization.id),
Expand All @@ -500,7 +514,7 @@ def upsert_organization(organization_data, current_user):
"rootDomains": organization.rootDomains,
"ipBlocks": organization.ipBlocks,
"isPassive": organization.isPassive,
"pendingDomains": organization.pendingDomains,
"pendingDomains": pending_domains,
"country": organization.country,
"state": organization.state,
"regionId": organization.regionId,
Expand All @@ -509,7 +523,12 @@ def upsert_organization(organization_data, current_user):
"county": organization.county,
"countyFips": organization.countyFips,
"type": organization.type,
"createdBy": organization.createdBy,
"createdBy": {
"id": str(organization.createdBy.id),
"firstName": organization.createdBy.firstName,
"lastName": organization.createdBy.lastName,
"email": organization.createdBy.email,
},
"tags": [
{
"id": str(tag.id),
Expand Down Expand Up @@ -584,6 +603,13 @@ def update_organization(organization_id: str, organization_data, current_user):
# Save the updated organization object
organization.save()

if isinstance(organization.pendingDomains, str):
pending_domains = json.loads(organization.pendingDomains)
elif isinstance(organization.pendingDomains, list):
pending_domains = organization.pendingDomains
else:
pending_domains = []

# Return the updated organization details in response
return {
"id": str(organization.id),
Expand All @@ -594,7 +620,7 @@ def update_organization(organization_id: str, organization_data, current_user):
"rootDomains": organization.rootDomains,
"ipBlocks": organization.ipBlocks,
"isPassive": organization.isPassive,
"pendingDomains": organization.pendingDomains,
"pendingDomains": pending_domains,
"country": organization.country,
"state": organization.state,
"regionId": organization.regionId,
Expand All @@ -603,7 +629,12 @@ def update_organization(organization_id: str, organization_data, current_user):
"county": organization.county,
"countyFips": organization.countyFips,
"type": organization.type,
"createdBy": organization.createdBy,
"createdBy": {
"id": str(organization.createdBy.id),
"firstName": organization.createdBy.firstName,
"lastName": organization.createdBy.lastName,
"email": organization.createdBy.email,
},
"tags": [
{
"id": str(tag.id),
Expand Down Expand Up @@ -897,6 +928,13 @@ def update_org_scan(organization_id: str, scan_id, scan_data, current_user):
# Save the updated organization
organization.save()

if isinstance(organization.pendingDomains, str):
pending_domains = json.loads(organization.pendingDomains)
elif isinstance(organization.pendingDomains, list):
pending_domains = organization.pendingDomains
else:
pending_domains = []

# Return a success response
return {
"id": str(organization.id),
Expand All @@ -907,7 +945,7 @@ def update_org_scan(organization_id: str, scan_id, scan_data, current_user):
"rootDomains": organization.rootDomains,
"ipBlocks": organization.ipBlocks,
"isPassive": organization.isPassive,
"pendingDomains": organization.pendingDomains,
"pendingDomains": pending_domains,
"country": organization.country,
"state": organization.state,
"regionId": organization.regionId,
Expand Down

0 comments on commit 6338cd4

Please sign in to comment.