From 99159622900e206e495adb4c9cf720ce3c5860b7 Mon Sep 17 00:00:00 2001 From: Tasos Katsoulas Date: Wed, 6 Nov 2024 19:38:39 +0200 Subject: [PATCH] Set the AAQ context for the wiki widget (#6337) --- .../products/jinja2/products/documents.html | 2 +- kitsune/products/views.py | 10 ++-------- .../jinja2/questions/question_details.html | 2 +- kitsune/questions/views.py | 8 ++------ kitsune/sumo/utils.py | 13 +++++++++++++ kitsune/wiki/jinja2/wiki/document.html | 2 +- kitsune/wiki/views.py | 18 +++++++++++------- 7 files changed, 31 insertions(+), 24 deletions(-) diff --git a/kitsune/products/jinja2/products/documents.html b/kitsune/products/jinja2/products/documents.html index 4354b2806..b0b8fc1e3 100644 --- a/kitsune/products/jinja2/products/documents.html +++ b/kitsune/products/jinja2/products/documents.html @@ -45,7 +45,7 @@ {{ topic_sidebar(topics[:10], subtopics, product, topic, subtopic) }} {% endif %} -{{ aaq_widget(request, "topic", topic) }} +{{ aaq_widget(request, topic) }} {% endblock %} diff --git a/kitsune/products/views.py b/kitsune/products/views.py index bc85ad92d..f87fda713 100644 --- a/kitsune/products/views.py +++ b/kitsune/products/views.py @@ -7,7 +7,7 @@ from django.shortcuts import get_object_or_404, redirect, render from product_details import product_details from kitsune.products.models import Product, Topic, TopicSlugHistory -from kitsune.sumo.utils import has_aaq_config +from kitsune.sumo.utils import has_aaq_config, set_aaq_context from kitsune.wiki.decorators import check_simple_wiki_locale from kitsune.wiki.facets import documents_for, topics_for from kitsune.wiki.models import Document, Revision @@ -85,7 +85,6 @@ def document_listing(request, topic_slug, product_slug=None, subtopic_slug=None) if product_slug: redirect_params["product_slug"] = product_slug - return redirect(document_listing, **redirect_params) except TopicSlugHistory.DoesNotExist: ... @@ -95,12 +94,7 @@ def document_listing(request, topic_slug, product_slug=None, subtopic_slug=None) product = None if product_slug: product = get_object_or_404(Product, slug=product_slug) - if has_aaq_config(product): - request.session["aaq_context"] = { - "has_ticketing_support": product.has_ticketing_support, - "product_slug": product_slug, - "has_public_forum": product.questions_enabled(locale=request.LANGUAGE_CODE), - } + set_aaq_context(request, product) doc_kw = { "locale": request.LANGUAGE_CODE, diff --git a/kitsune/questions/jinja2/questions/question_details.html b/kitsune/questions/jinja2/questions/question_details.html index 47296947f..6eb63addc 100644 --- a/kitsune/questions/jinja2/questions/question_details.html +++ b/kitsune/questions/jinja2/questions/question_details.html @@ -316,7 +316,7 @@ {{ search_box(settings, id='support-search-sidebar', params=search_params, placeholder=_('Search Support')) }} -{{ aaq_widget(request, "question") }} +{{ aaq_widget(request) }}
- {{ aaq_widget(request, "document") }} + {{ aaq_widget(request) }} {% if fallback_reason == 'no_translation' %} {# If there is no translation, there is no document and the (future) parent is document. #} diff --git a/kitsune/wiki/views.py b/kitsune/wiki/views.py index 32b94faaa..0f686fc57 100644 --- a/kitsune/wiki/views.py +++ b/kitsune/wiki/views.py @@ -14,12 +14,7 @@ from django.core.exceptions import PermissionDenied from django.db.models import Count, Exists, OuterRef, Q from django.db.models.functions import Now, TruncDate from django.forms.utils import ErrorList -from django.http import ( - Http404, - HttpResponse, - HttpResponseBadRequest, - HttpResponseRedirect, -) +from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseRedirect from django.shortcuts import get_object_or_404, redirect, render from django.template.loader import render_to_string from django.utils.cache import patch_vary_headers @@ -37,7 +32,13 @@ from kitsune.sumo.i18n import normalize_language from kitsune.sumo.redis_utils import RedisError, redis_client from kitsune.sumo.templatetags.jinja_helpers import urlparams from kitsune.sumo.urlresolvers import reverse -from kitsune.sumo.utils import get_next_url, paginate, smart_int, truncated_json_dumps +from kitsune.sumo.utils import ( + get_next_url, + paginate, + set_aaq_context, + smart_int, + truncated_json_dumps, +) from kitsune.wiki.config import ( CATEGORIES, COLLAPSIBLE_DOCUMENTS, @@ -236,6 +237,9 @@ def document(request, document_slug, document=None): else: product = products.first() + # Set the AAQ context for the widget + set_aaq_context(request, product) + product_topics = Topic.active.filter(products=product, visible=True) # Create serialized versions of the document's associated products and topics