Set the AAQ context for the wiki widget (#6337)

This commit is contained in:
Tasos Katsoulas 2024-11-06 19:38:39 +02:00 коммит произвёл GitHub
Родитель eae560d68c
Коммит 9915962290
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
7 изменённых файлов: 31 добавлений и 24 удалений

Просмотреть файл

@ -45,7 +45,7 @@
{{ topic_sidebar(topics[:10], subtopics, product, topic, subtopic) }}
{% endif %}
{{ aaq_widget(request, "topic", topic) }}
{{ aaq_widget(request, topic) }}
{% endblock %}

Просмотреть файл

@ -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,

Просмотреть файл

@ -316,7 +316,7 @@
{{ search_box(settings, id='support-search-sidebar', params=search_params, placeholder=_('Search Support')) }}
</div>
{{ aaq_widget(request, "question") }}
{{ aaq_widget(request) }}
<div class="questions-sidebar">
<nav class="sidebar-nav is-action-list" id="question-tools">

Просмотреть файл

@ -59,6 +59,7 @@ from kitsune.sumo.utils import (
has_aaq_config,
is_ratelimited,
paginate,
set_aaq_context,
simple_paginate,
)
from kitsune.tags.utils import add_existing_tag
@ -552,13 +553,8 @@ def aaq(request, product_slug=None, step=1, is_loginless=False):
}
# If the selected product doesn't exist in DB, render a 404
if step > 1:
set_aaq_context(request, product)
has_public_forum = product.questions_enabled(locale=request.LANGUAGE_CODE)
if has_aaq_config(product_slug):
request.session["aaq_context"] = {
"product_slug": product_slug,
"has_public_forum": has_public_forum,
"has_ticketing_support": product.has_ticketing_support,
}
context["has_ticketing_support"] = product.has_ticketing_support
context["ga_products"] = f"/{product_slug}/"

Просмотреть файл

@ -394,3 +394,16 @@ def has_aaq_config(product=None):
return AAQConfig.objects.filter(product=product, is_active=True).exists()
except AAQConfig.DoesNotExist:
return False
def set_aaq_context(request, product):
"""Set the AAQ context for a product."""
if not has_aaq_config(product):
request.session["aaq_context"] = {}
return
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),
}

Просмотреть файл

@ -56,7 +56,7 @@
{{ search_box(settings, id='support-search-sidebar', params=search_params) }}
</div>
{{ 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. #}

Просмотреть файл

@ -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