Exemplo n.º 1
0
    def copy_existing_tags_to_tags_from_django_tagging_field(
            apps, schema_editor):
        # We can't import the models directly as it may be a newer
        # version than this migration expects. We use the historical version.
        logger.info(
            'Migrating tags from django-tagging to django-tagulous step1. Enable DEBUG logging to find out more.'
        )
        import tagulous.utils
        # for model_name in ['Product']:
        for model_name in [
                'Product', 'test', 'finding', 'engagement', 'endpoint',
                'finding_template', 'app_Analysis', 'objects'
        ]:
            model_class = apps.get_model('dojo', model_name)
            # the get_model returns a fake class proxy, which is not registered with django-tagging
            tag_register(model_class)

            for obj in model_class.objects.all():
                # logger.debug('%s:%s:%s', model_class, obj.id, obj)
                if obj.tags:
                    tags_as_string = tagulous.utils.render_tags(obj.tags.all())
                    logger.debug('%s:%s:%s: found tags: %s', model_class,
                                 obj.id, obj, tags_as_string)
                    obj.tags_from_django_tagging = tags_as_string
                    # obj.description = tags_as_string
                    # finding.save() doesn't look at push_all_jira_issue, so we should be good
                    # if model_name == 'finding2':
                    #     obj.save(dedupe_option=False, rules_option=False, issue_updater_option=False, push_to_jira=False)
                    # else:
                    obj.save()
    def copy_existing_tags_to_tags_from_django_tagging_field(
            apps, schema_editor):
        # We can't import the models directly as it may be a newer
        # version than this migration expects. We use the historical version.
        logger.info(
            'Migrating tags from django-tagging to django-tagulous step1. Enable DEBUG logging to find out more.'
        )
        import tagulous.utils
        # for model_name in ['Product']:
        for model_name in [
                'Product', 'test', 'finding', 'engagement', 'endpoint',
                'finding_template', 'app_Analysis', 'objects'
        ]:
            model_class = apps.get_model('dojo', model_name)
            # the get_model returns a fake class proxy, which is not registered with django-tagging
            tag_register(model_class)

            for obj in model_class.objects.all():
                # logger.debug('%s:%s:%s', model_class, obj.id, obj)
                if obj.tags:
                    tags_as_string = tagulous.utils.render_tags(obj.tags.all())
                    logger.debug('%s:%s:%s: found tags: %s', model_class,
                                 obj.id, obj, tags_as_string)
                    obj.tags_from_django_tagging = tags_as_string
                    # obj.description = tags_as_string
                    # finding.save() doesn't look at push_all_jira_issue, so we should be good
                    # if model_name == 'finding2':
                    #     obj.save(dedupe_option=False, rules_option=False, issue_updater_option=False, push_to_jira=False)
                    # else:
                    try:
                        if hasattr(obj,
                                   'prod_type_id') and obj.prod_type_id == 0:
                            logger.warning(
                                'product found without product type (prod_type==0), changing to: "_tag migration lost and found" product type'
                            )
                            prod_type_lost_and_found, created = Product_Type.objects.get_or_create(
                                name='_tag migration lost and found')
                            obj.prod_type = prod_type_lost_and_found
                            obj.save()
                            logger.warning(
                                'product type succesfully changed to %i',
                                prod_type_lost_and_found.id)

                        obj.save()
                    except Exception as e:
                        logger.error(
                            'Error saving old existing django-tagging tags to new string field'
                        )
                        logger.error('Details of object:')
                        logger.error(vars(obj))
                        logger.error('Model to dict:')
                        logger.error(model_to_dict(obj))
Exemplo n.º 3
0
    user_id = models.ForeignKey(User, null=True, editable=False)
    created = models.DateTimeField(null=False, editable=False, default=now)
    display_date = models.DateTimeField(null=False, default=now)

# Register for automatic logging to database
auditlog.register(Dojo_User)
auditlog.register(Endpoint)
auditlog.register(Engagement)
auditlog.register(Finding)
auditlog.register(Product)
auditlog.register(Test)
auditlog.register(Risk_Acceptance)
auditlog.register(Finding_Template)

# Register tagging for models
tag_register(Product)
tag_register(Test)
tag_register(Finding)
tag_register(Engagement)
tag_register(Endpoint)
tag_register(Finding_Template)

admin.site.register(Test)
admin.site.register(Finding)
admin.site.register(FindingImage)
admin.site.register(FindingImageAccessToken)
admin.site.register(Stub_Finding)
admin.site.register(Engagement)
admin.site.register(Risk_Acceptance)
admin.site.register(Check_List)
admin.site.register(Test_Type)
Exemplo n.º 4
0
        if not self.token:
            self.token = uuid4()
        return super(FindingImageAccessToken, self).save(*args, **kwargs)


# Register for automatic logging to database
auditlog.register(Dojo_User)
auditlog.register(Endpoint)
auditlog.register(Engagement)
auditlog.register(Finding)
auditlog.register(Product)
auditlog.register(Test)
auditlog.register(Risk_Acceptance)

# Register tagging for models
tag_register(Product)
tag_register(Test)
tag_register(Finding)
tag_register(Engagement)
tag_register(Endpoint)
tag_register(Finding_Template)

admin.site.register(Test)
admin.site.register(Finding)
admin.site.register(FindingImage)
admin.site.register(FindingImageAccessToken)
admin.site.register(Stub_Finding)
admin.site.register(Engagement)
admin.site.register(Risk_Acceptance)
admin.site.register(Check_List)
admin.site.register(Test_Type)
Exemplo n.º 5
0
from tagging.registry import register as tag_register


class SiteUrl(models.Model):
    url = models.CharField(max_length=100)

    def __str__(self):
        return f'{self.url}'


class Author(models.Model):
    name = models.CharField(max_length=100)

    def __str__(self):
        return f'{self.name}'


class Post(models.Model):
    site_url = models.ForeignKey(SiteUrl, on_delete=models.CASCADE)
    post_url = models.URLField(unique=True)
    title = models.CharField(max_length=300)
    author = models.ForeignKey(Author, on_delete=models.CASCADE)
    body_content = models.TextField()

    def __str__(self):
        return f'{self.site_url} {self.title}'


tag_register(Post)