forked from intelowlproject/IntelOwl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.py
More file actions
74 lines (59 loc) · 2.12 KB
/
Copy pathadmin.py
File metadata and controls
74 lines (59 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# This file is a part of IntelOwl https://github.com/intelowlproject/IntelOwl
# See the file 'LICENSE' for copying permission.
from django.contrib import admin
from durin.admin import AuthTokenAdmin
from durin.models import AuthToken, Client
from guardian.admin import GuardedModelAdmin
from .models import Job, Tag
class JobAdminView(GuardedModelAdmin):
list_display = (
"id",
"status",
"source",
"observable_name",
"observable_classification",
"file_name",
"file_mimetype",
"received_request_time",
)
list_display_link = ("id", "status")
search_fields = ("source", "md5", "observable_name")
class TagAdminView(GuardedModelAdmin):
list_display = ("id", "label", "color")
search_fields = ("label", "color")
# Auth Token stuff
class CustomAuthTokenAdmin(AuthTokenAdmin):
"""
Custom admin view for AuthToken model
"""
exclude = []
raw_id_fields = ("user",)
readonly_fields = ("token", "expiry", "created", "expires_in")
def get_fieldsets(self, request, obj=None):
if not obj:
return [
(
"Create token for PyIntelOwl",
{
"fields": ("user",),
"description": """
<h3>Token will be auto-generated on save.</h3>
<h3>This token will be valid for 10 years.</h3>
""",
},
),
]
return super().get_fieldsets(request, obj)
def has_change_permission(self, *args, **kwargs):
return False
def save_model(self, request, obj, form, change):
obj.client = Client.objects.get(name="pyintelowl")
super(CustomAuthTokenAdmin, self).save_model(request, obj, form, change)
admin.site.register(Job, JobAdminView)
admin.site.register(Tag, TagAdminView)
# Unregister Client admin view
admin.site.unregister(Client)
# Unregister the default admin view for AuthToken
admin.site.unregister(AuthToken)
# Register our custom admin view for AuthToken
admin.site.register(AuthToken, CustomAuthTokenAdmin)