From 93e82f546982ac12d6852974349a0a9eaa1354e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Dlouh=C3=BD?= Date: Tue, 25 Feb 2020 14:46:21 +0100 Subject: [PATCH] allow KBItems to be disabled for users --- helpdesk/admin.py | 2 +- helpdesk/migrations/0032_kbitem_enabled.py | 18 ++++++++++++++++++ helpdesk/models.py | 5 +++++ helpdesk/views/kb.py | 2 +- 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 helpdesk/migrations/0032_kbitem_enabled.py diff --git a/helpdesk/admin.py b/helpdesk/admin.py index 8b1dedf9..301a9c43 100644 --- a/helpdesk/admin.py +++ b/helpdesk/admin.py @@ -70,7 +70,7 @@ class FollowUpAdmin(admin.ModelAdmin): @admin.register(KBItem) class KBItemAdmin(admin.ModelAdmin): - list_display = ('category', 'title', 'last_updated', 'team', 'order') + list_display = ('category', 'title', 'last_updated', 'team', 'order', 'enabled') inlines = [KBIAttachmentInline] readonly_fields = ('voted_by', 'downvoted_by') diff --git a/helpdesk/migrations/0032_kbitem_enabled.py b/helpdesk/migrations/0032_kbitem_enabled.py new file mode 100644 index 00000000..7868bfe1 --- /dev/null +++ b/helpdesk/migrations/0032_kbitem_enabled.py @@ -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'), + ), + ] diff --git a/helpdesk/models.py b/helpdesk/models.py index 15465160..7e4b61c5 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -1323,6 +1323,11 @@ class KBItem(models.Model): null=True, ) + enabled = models.BooleanField( + _('Enabled to display to users'), + default=True, + ) + def save(self, *args, **kwargs): if not self.last_updated: self.last_updated = timezone.now() diff --git a/helpdesk/views/kb.py b/helpdesk/views/kb.py index a1bead71..55b3424d 100644 --- a/helpdesk/views/kb.py +++ b/helpdesk/views/kb.py @@ -30,7 +30,7 @@ def category(request, slug, iframe=False): category = get_object_or_404(KBCategory, slug__iexact=slug) if not user.huser_from_request(request).can_access_kbcategory(category): raise Http404 - items = category.kbitem_set.all() + items = category.kbitem_set.filter(enabled=True) selected_item = request.GET.get('kbitem', None) try: selected_item = int(selected_item)