allow KBItems to be disabled for users

This commit is contained in:
Petr Dlouhý 2020-02-25 14:46:21 +01:00
parent d0aafd6135
commit 93e82f5469
4 changed files with 25 additions and 2 deletions

View File

@ -70,7 +70,7 @@ class FollowUpAdmin(admin.ModelAdmin):
@admin.register(KBItem) @admin.register(KBItem)
class KBItemAdmin(admin.ModelAdmin): class KBItemAdmin(admin.ModelAdmin):
list_display = ('category', 'title', 'last_updated', 'team', 'order') list_display = ('category', 'title', 'last_updated', 'team', 'order', 'enabled')
inlines = [KBIAttachmentInline] inlines = [KBIAttachmentInline]
readonly_fields = ('voted_by', 'downvoted_by') readonly_fields = ('voted_by', 'downvoted_by')

View File

@ -0,0 +1,18 @@
# Generated by Django 2.2.10 on 2020-02-25 13:44
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('helpdesk', '0031_auto_20200225_1440'),
]
operations = [
migrations.AddField(
model_name='kbitem',
name='enabled',
field=models.BooleanField(default=True, verbose_name='Enabled to display to users'),
),
]

View File

@ -1323,6 +1323,11 @@ class KBItem(models.Model):
null=True, null=True,
) )
enabled = models.BooleanField(
_('Enabled to display to users'),
default=True,
)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
if not self.last_updated: if not self.last_updated:
self.last_updated = timezone.now() self.last_updated = timezone.now()

View File

@ -30,7 +30,7 @@ def category(request, slug, iframe=False):
category = get_object_or_404(KBCategory, slug__iexact=slug) category = get_object_or_404(KBCategory, slug__iexact=slug)
if not user.huser_from_request(request).can_access_kbcategory(category): if not user.huser_from_request(request).can_access_kbcategory(category):
raise Http404 raise Http404
items = category.kbitem_set.all() items = category.kbitem_set.filter(enabled=True)
selected_item = request.GET.get('kbitem', None) selected_item = request.GET.get('kbitem', None)
try: try:
selected_item = int(selected_item) selected_item = int(selected_item)