Skip to content

Commit

Permalink
Merge pull request #1425 from yogeshojha/492-create-organization-when…
Browse files Browse the repository at this point in the history
…-adding-targets

feat: Create organization when quick adding targets #492
  • Loading branch information
yogeshojha authored Sep 6, 2024
2 parents 7ad2eb2 + d3631ce commit 9beca84
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
46 changes: 19 additions & 27 deletions web/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from recon_note.models import *
from reNgine.celery import app
from reNgine.common_func import *
from reNgine.database_utils import *
from reNgine.definitions import ABORTED_TASK
from reNgine.tasks import *
from reNgine.llm import *
Expand Down Expand Up @@ -932,35 +933,26 @@ def post(self, request):
if not validators.domain(domain_name):
return Response({'status': False, 'message': 'Invalid domain or IP'})

project = Project.objects.get(slug=slug)

# Create domain object in DB
domain, _ = Domain.objects.get_or_create(name=domain_name)
domain.project = project
domain.h1_team_handle = h1_team_handle
domain.description = description
if not domain.insert_date:
domain.insert_date = timezone.now()
domain.save()

# Create org object in DB
if organization_name:
organization_obj = None
organization_query = Organization.objects.filter(name=organization_name)
if organization_query.exists():
organization_obj = organization_query[0]
else:
organization_obj = Organization.objects.create(
name=organization_name,
project=project,
insert_date=timezone.now())
organization_obj.domains.add(domain)
status = bulk_import_targets(
targets=[{
'name': domain_name,
'description': description,
}],
organization_name=organization_name,
h1_team_handle=h1_team_handle,
project_slug=slug
)

if status:
return Response({
'status': True,
'message': 'Domain successfully added as target !',
'domain_name': domain_name,
# 'domain_id': domain.id
})
return Response({
'status': True,
'message': 'Domain successfully added as target !',
'domain_name': domain_name,
'domain_id': domain.id
'status': False,
'message': 'Failed to add as target !'
})


Expand Down
3 changes: 3 additions & 0 deletions web/reNgine/database_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def bulk_import_targets(
organization_name (str): name of the organization to tag these targets
org_description (str): description of the organization
h1_team_handle (str): hackerone team handle (if imported from hackerone)
Returns:
bool: True if new targets are imported, False otherwise
"""
new_targets_imported = False
project = Project.objects.get(slug=project_slug)
Expand Down

0 comments on commit 9beca84

Please sign in to comment.