play with somort of permission management

This commit is contained in:
Holger Sielaff
2024-07-04 14:05:55 +02:00
parent 030d3c8059
commit 7d53df6ea5
4 changed files with 42 additions and 7 deletions

View File

@@ -3,24 +3,25 @@ from django.utils.safestring import mark_safe
from content.models import Link, MediaFile, Question, QuestionVersion, Level, Label
from lib.utils import color_label
from lib.mixins import PermissionsAdminMixin
@admin.register(Level)
class LevelAdmin(admin.ModelAdmin):
class LevelAdmin(PermissionsAdminMixin, admin.ModelAdmin):
search_fields = ('name', 'value',)
list_display = ('name', 'value', 'color')
list_editable = ('color',)
@admin.register(Label)
class LabelAdmin(admin.ModelAdmin):
class LabelAdmin(PermissionsAdminMixin, admin.ModelAdmin):
search_fields = ('name',)
list_display = ('name', 'color')
list_editable = ('color',)
@admin.register(Question)
class QuestionAdmin(admin.ModelAdmin):
class QuestionAdmin(PermissionsAdminMixin, admin.ModelAdmin):
autocomplete_fields = ('medias', 'links', 'labels',)
list_display = ('name', 'list_labels', 'list_level', 'author')
search_fields = ('name', 'question', 'awnser', 'description', 'label__name', 'level__value', 'level__name',)
@@ -46,13 +47,13 @@ class QuestionAdmin(admin.ModelAdmin):
@admin.register(MediaFile)
class MediaFileAdmin(admin.ModelAdmin):
class MediaFileAdmin(PermissionsAdminMixin, admin.ModelAdmin):
search_fields = ('name', 'file__name')
list_display = ('name', 'file')
@admin.register(Link)
class LinkAdmin(admin.ModelAdmin):
class LinkAdmin(PermissionsAdminMixin, admin.ModelAdmin):
search_fields = ('url',)
@@ -71,3 +72,6 @@ class QuestionVersionAdmin(admin.ModelAdmin):
def has_delete_permission(self, request, obj=None):
"""Versions are immutable """
return False
def has_view_permission(self, request, obj=None):
return True