185 lines
7.6 KiB
Python
185 lines
7.6 KiB
Python
from django.contrib import admin
|
|
from django.conf import settings
|
|
from django import forms
|
|
|
|
from .emailing import send_system_email
|
|
from .models import EmployeeProfile, FormFieldConfig, FormOption, IntroChecklistItem, NotificationRule, NotificationTemplate, OffboardingRequest, OnboardingIntroductionSession, OnboardingRequest, ScheduledWelcomeEmail, SystemEmailConfig, WorkflowConfig
|
|
|
|
|
|
@admin.register(EmployeeProfile)
|
|
class EmployeeProfileAdmin(admin.ModelAdmin):
|
|
list_display = ('full_name', 'work_email', 'department', 'job_title', 'updated_at')
|
|
search_fields = ('full_name', 'work_email', 'department')
|
|
|
|
|
|
@admin.register(OnboardingRequest)
|
|
class OnboardingRequestAdmin(admin.ModelAdmin):
|
|
list_display = ('id', 'full_name', 'work_email', 'department', 'contract_start', 'created_at')
|
|
search_fields = ('full_name', 'work_email', 'department')
|
|
list_filter = ('department', 'created_at', 'group_mailboxes_required', 'additional_software_needed')
|
|
|
|
|
|
@admin.register(OffboardingRequest)
|
|
class OffboardingRequestAdmin(admin.ModelAdmin):
|
|
list_display = ('id', 'full_name', 'work_email', 'department', 'last_working_day', 'generated_pdf_path', 'created_at')
|
|
search_fields = ('full_name', 'work_email', 'department')
|
|
list_filter = ('department', 'created_at')
|
|
|
|
|
|
@admin.register(FormOption)
|
|
class FormOptionAdmin(admin.ModelAdmin):
|
|
list_display = ('category', 'label', 'label_en', 'value', 'sort_order', 'is_active')
|
|
list_filter = ('category', 'is_active')
|
|
search_fields = ('label', 'label_en', 'value')
|
|
ordering = ('category', 'sort_order', 'label')
|
|
|
|
|
|
@admin.register(FormFieldConfig)
|
|
class FormFieldConfigAdmin(admin.ModelAdmin):
|
|
list_display = ('form_type', 'field_name', 'page_key', 'sort_order', 'is_visible', 'is_required')
|
|
list_filter = ('form_type', 'page_key', 'is_visible', 'is_required')
|
|
search_fields = ('field_name', 'label_override', 'label_override_en', 'help_text_override', 'help_text_override_en')
|
|
ordering = ('form_type', 'sort_order', 'field_name')
|
|
list_editable = ('page_key', 'sort_order', 'is_visible', 'is_required')
|
|
|
|
|
|
@admin.register(IntroChecklistItem)
|
|
class IntroChecklistItemAdmin(admin.ModelAdmin):
|
|
list_display = ('section', 'label', 'label_en', 'condition_field', 'condition_operator', 'condition_value', 'sort_order', 'is_active')
|
|
list_filter = ('section', 'condition_operator', 'is_active')
|
|
search_fields = ('label', 'label_en', 'condition_field', 'condition_value')
|
|
ordering = ('section', 'sort_order', 'label')
|
|
list_editable = ('sort_order', 'is_active')
|
|
|
|
|
|
@admin.register(OnboardingIntroductionSession)
|
|
class OnboardingIntroductionSessionAdmin(admin.ModelAdmin):
|
|
list_display = ('onboarding_request', 'status', 'completed_by_name', 'completed_at', 'updated_at')
|
|
list_filter = ('status', 'completed_at', 'updated_at')
|
|
search_fields = ('onboarding_request__full_name', 'onboarding_request__work_email', 'completed_by_name')
|
|
ordering = ('-updated_at', '-id')
|
|
|
|
|
|
@admin.register(WorkflowConfig)
|
|
class WorkflowConfigAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
'name',
|
|
'it_onboarding_email',
|
|
'general_info_email',
|
|
'business_card_email',
|
|
'hr_works_email',
|
|
'key_notification_email',
|
|
'nextcloud_enabled_override',
|
|
'email_test_mode_override',
|
|
)
|
|
fieldsets = (
|
|
('Benachrichtigungen', {
|
|
'fields': (
|
|
'name',
|
|
'it_onboarding_email',
|
|
'general_info_email',
|
|
'business_card_email',
|
|
'hr_works_email',
|
|
'key_notification_email',
|
|
)
|
|
}),
|
|
('Modi', {
|
|
'fields': (
|
|
'nextcloud_enabled_override',
|
|
'email_test_mode_override',
|
|
'sync_interval_seconds',
|
|
)
|
|
}),
|
|
('Nextcloud Konfiguration', {
|
|
'fields': (
|
|
'nextcloud_base_url_override',
|
|
'nextcloud_username_override',
|
|
'nextcloud_password_override',
|
|
'nextcloud_directory_override',
|
|
)
|
|
}),
|
|
('Mail Server Konfiguration', {
|
|
'fields': (
|
|
'imap_server',
|
|
'mailbox',
|
|
'smtp_server',
|
|
'smtp_port',
|
|
'email_account',
|
|
'email_password',
|
|
'smtp_use_ssl',
|
|
'smtp_use_tls',
|
|
)
|
|
}),
|
|
('Rechtlicher Text', {'fields': ('legal_text',)}),
|
|
)
|
|
|
|
def formfield_for_dbfield(self, db_field, request, **kwargs):
|
|
if db_field.name in {'nextcloud_password_override', 'email_password'}:
|
|
kwargs['widget'] = forms.PasswordInput(render_value=True)
|
|
return super().formfield_for_dbfield(db_field, request, **kwargs)
|
|
|
|
|
|
@admin.register(NotificationTemplate)
|
|
class NotificationTemplateAdmin(admin.ModelAdmin):
|
|
list_display = ('key', 'is_active', 'updated_at')
|
|
list_filter = ('is_active', 'key')
|
|
search_fields = ('key', 'subject_template', 'body_template')
|
|
|
|
|
|
@admin.register(NotificationRule)
|
|
class NotificationRuleAdmin(admin.ModelAdmin):
|
|
list_display = ('name', 'event_type', 'operator', 'field_name', 'is_active', 'sort_order')
|
|
list_filter = ('event_type', 'operator', 'is_active')
|
|
search_fields = ('name', 'field_name', 'expected_value', 'recipients', 'template_key')
|
|
ordering = ('event_type', 'sort_order', 'id')
|
|
|
|
|
|
@admin.register(ScheduledWelcomeEmail)
|
|
class ScheduledWelcomeEmailAdmin(admin.ModelAdmin):
|
|
list_display = ('id', 'onboarding_request', 'recipient_email', 'send_at', 'status', 'sent_at', 'updated_at')
|
|
list_filter = ('status', 'send_at', 'sent_at')
|
|
search_fields = ('recipient_email', 'onboarding_request__full_name', 'onboarding_request__work_email')
|
|
ordering = ('-send_at', '-id')
|
|
|
|
|
|
@admin.register(SystemEmailConfig)
|
|
class SystemEmailConfigAdmin(admin.ModelAdmin):
|
|
list_display = ('name', 'is_active', 'host', 'port', 'username', 'use_tls', 'use_ssl', 'from_email', 'updated_at')
|
|
list_filter = ('is_active', 'use_tls', 'use_ssl')
|
|
search_fields = ('name', 'host', 'username', 'from_email')
|
|
actions = ('send_smtp_test',)
|
|
|
|
def save_model(self, request, obj, form, change):
|
|
super().save_model(request, obj, form, change)
|
|
if obj.is_active:
|
|
SystemEmailConfig.objects.exclude(id=obj.id).update(is_active=False)
|
|
|
|
def send_smtp_test(self, request, queryset):
|
|
cfg = queryset.first()
|
|
if not cfg:
|
|
self.message_user(request, 'Bitte eine SMTP-Konfiguration auswählen.', level='warning')
|
|
return
|
|
|
|
prev_active_ids = list(SystemEmailConfig.objects.filter(is_active=True).values_list('id', flat=True))
|
|
try:
|
|
SystemEmailConfig.objects.filter(id=cfg.id).update(is_active=True)
|
|
SystemEmailConfig.objects.exclude(id=cfg.id).update(is_active=False)
|
|
send_system_email(
|
|
subject='SMTP Test aus Admin',
|
|
body=(
|
|
f'SMTP Test erfolgreich für Konfiguration: {cfg.name}\n'
|
|
f'Host: {cfg.host}:{cfg.port}\n'
|
|
f'User: {cfg.username or "-"}'
|
|
),
|
|
to=[settings.TEST_NOTIFICATION_EMAIL],
|
|
)
|
|
self.message_user(request, f'SMTP-Testmail gesendet über "{cfg.name}".')
|
|
except Exception as exc:
|
|
self.message_user(request, f'SMTP-Test fehlgeschlagen: {exc}', level='error')
|
|
finally:
|
|
if prev_active_ids:
|
|
SystemEmailConfig.objects.update(is_active=False)
|
|
SystemEmailConfig.objects.filter(id__in=prev_active_ids).update(is_active=True)
|
|
|
|
send_smtp_test.short_description = 'SMTP-Testmail mit ausgewählter Konfiguration senden'
|