Download apps/security/admin.py from Rsnarsna/Saas-Base: direct link, hf CLI and curl.
- Browser
- Download file 2.56 kB
-
https://huggingface.co/spaces/Rsnarsna/Saas-Base/resolve/main/apps/security/admin.py
- Command line
-
hf download hf://spaces/Rsnarsna/Saas-Base/apps/security/admin.py
-
curl -L -o admin.py https://huggingface.co/spaces/Rsnarsna/Saas-Base/resolve/main/apps/security/admin.py
2.56 kB
| """ | |
| Admin configuration for the security app. | |
| """ | |
| from django.contrib import admin | |
| from apps.security.models import ( | |
| BackupCode, | |
| MFAFactor, | |
| RateLimit, | |
| RefreshToken, | |
| SecurityEvent, | |
| Session, | |
| TokenBlacklist, | |
| TrustedDevice, | |
| ) | |
| class SessionAdmin(admin.ModelAdmin): | |
| list_display = ("user", "ip_address", "is_active", "expires_at", "created_at") | |
| list_filter = ("revoked_at",) | |
| search_fields = ("user__email", "ip_address") | |
| readonly_fields = ("user", "fingerprint", "ip_address", "user_agent", "created_at") | |
| ordering = ("-created_at",) | |
| def is_active(self, obj) -> bool: | |
| return obj.is_active | |
| is_active.boolean = True | |
| class RefreshTokenAdmin(admin.ModelAdmin): | |
| list_display = ("user", "is_active", "rotated_from", "expires_at", "created_at") | |
| search_fields = ("user__email",) | |
| ordering = ("-created_at",) | |
| def is_active(self, obj) -> bool: | |
| return obj.is_active | |
| is_active.boolean = True | |
| class TokenBlacklistAdmin(admin.ModelAdmin): | |
| list_display = ("token_id", "user", "reason", "revoked_at") | |
| search_fields = ("token_id", "user__email") | |
| ordering = ("-revoked_at",) | |
| class MFAFactorAdmin(admin.ModelAdmin): | |
| list_display = ("user", "type", "enabled", "created_at") | |
| list_filter = ("type", "enabled") | |
| search_fields = ("user__email",) | |
| class BackupCodeAdmin(admin.ModelAdmin): | |
| list_display = ("user", "is_used", "created_at") | |
| list_filter = ("used_at",) | |
| search_fields = ("user__email",) | |
| def is_used(self, obj) -> bool: | |
| return obj.is_used | |
| is_used.boolean = True | |
| class TrustedDeviceAdmin(admin.ModelAdmin): | |
| list_display = ("user", "device_id", "approved", "last_used_at") | |
| list_filter = ("approved",) | |
| search_fields = ("user__email", "device_id") | |
| class SecurityEventAdmin(admin.ModelAdmin): | |
| list_display = ("user", "event_type", "created_at") | |
| list_filter = ("event_type",) | |
| search_fields = ("user__email",) | |
| readonly_fields = ("user", "event_type", "metadata", "created_at") | |
| ordering = ("-created_at",) | |
| class RateLimitAdmin(admin.ModelAdmin): | |
| list_display = ("key", "attempts", "is_blocked", "blocked_until", "updated_at") | |
| search_fields = ("key",) | |
| def is_blocked(self, obj) -> bool: | |
| return obj.is_blocked | |
| is_blocked.boolean = True | |