BLT icon indicating copy to clipboard operation
BLT copied to clipboard

Create an Company table and a Team table - allow Teams to be setup by anyone and Teams to belong to companies

Open fredfalcon opened this issue 1 year ago • 4 comments

Create an Company table and a Team table - allow Teams to be setup by anyone and Teams to belong to companies

an Entity table is fine too for things that don't have a company or team - like an OWASP project

class Company(models.Model):
    name = models.CharField(max_length=255)
    corporate_name = models.CharField(max_length=255)
    main_website = one to one with domains
    image = models.ImageField(upload_to='entity_images')
    description = models.TextField()
   
    # allow any user connected to the company to modify it's settings - users must be verified with a company email address
    users = models.ManyToManyField('auth.User', related_name='entities', blank=True)
    domains = models.ManyToManyField('Domain', related_name='entities', blank=True)
    hunts = models.ManyToManyField('Hunt', related_name='entities', blank=True)
    teams = models.ManyToManyField('Team', related_name='entities', blank=True)

    def __str__(self):
        return self.name

Then run this script;

from django.contrib.auth.models import User
from myapp.models import Entity, Domain, Hunt

# Get all Domain objects
domains = Domain.objects.all()

# Iterate over each Domain object
for domain in domains:
   # update this
    entity = Company()
    entity.name = domain.url.replace('www.', '').replace('.com', '') # Set the entity name based on the domain url
    entity.image = 'default_image.jpg' # Set a default image
    entity.description = f'This is the entity for {domain.url}' # Set a default description
    entity.save() # Save the new entity object

    # Get all Users with an email containing the domain name
    users = User.objects.filter(email__icontains=domain.url.replace('www.', ''))
    entity.users.set(users) # Add the users to the entity using the many-to-many relationship

    # Get all Hunt objects that match the domain
    hunts = Hunt.objects.filter(domain=domain)
    for hunt in hunts:
        hunt.entities.add(entity) # Add the entity to the hunt using the many-to-many relationship
        hunt.save()

fredfalcon avatar Mar 09 '23 06:03 fredfalcon

/assign

pranav-iitr avatar Mar 12 '23 17:03 pranav-iitr

/assign

HanilJain avatar Feb 13 '24 17:02 HanilJain

You cannot be assigned to this issue because you are already assigned to the following issues without an open pull request: #1239. Please submit a pull request for these issues before getting assigned to a new one.

github-actions[bot] avatar Feb 13 '24 17:02 github-actions[bot]

/assign

thedudeontitan avatar Feb 21 '24 17:02 thedudeontitan

these are now organizations, anyone can setup an Organization and that can be a team

DonnieBLT avatar Aug 03 '24 20:08 DonnieBLT