Skip to content

Commit

Permalink
Added model import/export for users, webhooks and tags
Browse files Browse the repository at this point in the history
  • Loading branch information
neonbunny committed Dec 6, 2024
1 parent ca34c7f commit fed48f6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
52 changes: 49 additions & 3 deletions event_tracker/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from import_export import resources
from import_export.admin import ImportExportModelAdmin, ImportExportMixin
from reversion.admin import VersionAdmin
from taggit.admin import TagAdmin
from taggit.models import Tag
from taggit_bulk.actions import tag_wizard

from .models import Task, Context, Event, AttackTactic, AttackTechnique, AttackSubTechnique, File, FileDistribution, \
Expand Down Expand Up @@ -38,7 +42,6 @@ def __repr__(self):


admin.site.register(Credential)
admin.site.register(Webhook)

admin.site.register(AttackTactic)
admin.site.register(AttackTechnique)
Expand All @@ -51,10 +54,53 @@ class UserPreferencesInline(admin.StackedInline):
can_delete = False
verbose_name_plural = 'preferences'


class UserResource(resources.ModelResource):

class Meta:
name = "User"
model = User


class UserPreferencesResource(resources.ModelResource):
class Meta:
name = "User's Preferences"
model = UserPreferences


# Define a new User admin
class UserAdmin(BaseUserAdmin):
class UserAdmin(ImportExportMixin, BaseUserAdmin):
resource_classes = [UserResource, UserPreferencesResource]
inlines = (UserPreferencesInline,)

# Re-register UserAdmin
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
admin.site.register(User, UserAdmin)

# -- Make Tags importable/exportable and add buttons to the admin UI

class TagResource(resources.ModelResource):

class Meta:
model = Tag


class MyTagAdmin(ImportExportMixin, TagAdmin):
resource_classes = [TagResource]

# Re-register TagAdmin
admin.site.unregister(Tag)
admin.site.register(Tag, MyTagAdmin)


# -- Make WebHooks importable/exportable and add buttons to the admin UI
class WebhookResource(resources.ModelResource):

class Meta:
model = Webhook


@admin.register(Webhook)
class WebhookAdmin(ImportExportModelAdmin):
resource_classes = [WebhookResource]
list_display = ["url"]
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ django-permissions-policy==4.23.0
ansi2html==1.9.2
django-plugins-bihealth==0.5.2
yara-x==0.10.0
django-import-export==4.3.3
4 changes: 4 additions & 0 deletions stepping_stones/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
'html_reports',
'markdown_reports',
'external_tool_reports',
'import_export',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -215,3 +216,6 @@

# Define backend for matplotlib. Ensure a non-interactive backend is chosen to avoid dangling resources
matplotlib.use('agg')

IMPORT_EXPORT_IMPORT_PERMISSION_CODE = "add"
IMPORT_EXPORT_EXPORT_PERMISSION_CODE = "view"

0 comments on commit fed48f6

Please sign in to comment.