diff --git a/event_tracker/admin.py b/event_tracker/admin.py index a547165..aeea8a7 100644 --- a/event_tracker/admin.py +++ b/event_tracker/admin.py @@ -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, \ @@ -38,7 +42,6 @@ def __repr__(self): admin.site.register(Credential) -admin.site.register(Webhook) admin.site.register(AttackTactic) admin.site.register(AttackTechnique) @@ -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) \ No newline at end of file +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"] diff --git a/requirements.txt b/requirements.txt index 2825c3b..b16c755 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/stepping_stones/settings.py b/stepping_stones/settings.py index 8670f2e..d02215f 100644 --- a/stepping_stones/settings.py +++ b/stepping_stones/settings.py @@ -51,6 +51,7 @@ 'html_reports', 'markdown_reports', 'external_tool_reports', + 'import_export', ] MIDDLEWARE = [ @@ -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"