Skip to content

Commit

Permalink
Merge pull request #6160 from akatsoulas/aaq-topics
Browse files Browse the repository at this point in the history
Use internal IA for the AAQ instead of a config.
  • Loading branch information
escattone authored Aug 8, 2024
2 parents 5797b0c + 41cc8d6 commit 7b2b199
Show file tree
Hide file tree
Showing 48 changed files with 541 additions and 952 deletions.
12 changes: 6 additions & 6 deletions docs/hacking_howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ and follow the following steps.
```

3. Pull base Kitsune Docker images, install node packages and build the Webpack bundle, and create your database.
On non-Apple silicon:
On non-Apple silicon:

```
make init
Expand All @@ -39,12 +39,12 @@ and follow the following steps.
```

Then:

```
make build
```

3. Run Kitsune.
4. Run Kitsune.

```
make run
Expand Down Expand Up @@ -163,7 +163,7 @@ running this command::
Create a topic in the admin interface with its `slug` set to `download-and-install` and its product set to the product you just created.

3. Finally add an AAQ locale for that product.
You can do this through the admin interface at `/admin/questions/questionlocale/add/`.
You can do this through the admin interface at `/admin/questions/aaqconfig`.

### Get search working

Expand Down Expand Up @@ -215,7 +215,7 @@ every time you commit,
pre-commit will check your changes for style problems.
To run it manually you can use the command:

```bash
```bash
$ pre-commit run
```

Expand All @@ -230,7 +230,7 @@ For more details see the [pre-commit docs](https://pre-commit.com).

### Product Details Initialization

!!! note
!!! note

One of the packages Kitsune uses, ``product_details``, needs to fetch
JSON files containing historical Firefox version data and write them
Expand Down
6 changes: 3 additions & 3 deletions kitsune/community/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from kitsune.forums.models import Thread
from kitsune.products.models import Product
from kitsune.questions.models import QuestionLocale
from kitsune.questions.models import AAQConfig
from kitsune.search.base import SumoSearchPaginator
from kitsune.search.search import ProfileSearch
from kitsune.sumo.parser import get_object_fallback
Expand Down Expand Up @@ -59,7 +59,7 @@ def home(request):

# If the locale is enabled for the Support Forum, show the top
# contributors for that locale
if locale in QuestionLocale.objects.locales_list():
if locale in AAQConfig.objects.locales_list():
data["top_contributors_questions"], _ = top_contributors_questions(
locale=locale, product=product
)
Expand Down Expand Up @@ -117,7 +117,7 @@ def top_contributors(request, area):
results, total = top_contributors_questions(
locale=locale, product=product, count=page_size, page=page
)
locales = QuestionLocale.objects.locales_list()
locales = AAQConfig.objects.locales_list()
case "kb":
results, total = top_contributors_kb(product=product, count=page_size, page=page)
locales = None
Expand Down
4 changes: 2 additions & 2 deletions kitsune/customercare/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ def __init__(self, *args, product, user=None, **kwargs):
if product.slug not in PRODUCTS_WITH_OS:
del self.fields["os"]

def send(self, user, product_config):
def send(self, user, product):
client = ZendeskClient()
return client.create_ticket(user, self.cleaned_data, product_config)
return client.create_ticket(user, self.cleaned_data, product)
4 changes: 2 additions & 2 deletions kitsune/customercare/zendesk.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ def update_primary_email(self, zendesk_user_id, email):
user=zendesk_user_id, identity=ZendeskIdentity(id=identity_id, value=email)
)

def create_ticket(self, user, ticket_fields, product_config):
def create_ticket(self, user, ticket_fields, product):
"""Create a ticket in Zendesk."""
custom_fields = [
{"id": settings.ZENDESK_PRODUCT_FIELD_ID, "value": ticket_fields.get("product")},
{"id": settings.ZENDESK_OS_FIELD_ID, "value": ticket_fields.get("os")},
{"id": settings.ZENDESK_COUNTRY_FIELD_ID, "value": ticket_fields.get("country")},
]
ticket_kwargs = {
"subject": ticket_fields.get("subject") or f"{product_config['name']} support",
"subject": ticket_fields.get("subject") or f"{product.title} support",
"comment": {"body": ticket_fields.get("description") or str(NO_RESPONSE)},
"ticket_form_id": settings.ZENDESK_TICKET_FORM_ID,
}
Expand Down
11 changes: 5 additions & 6 deletions kitsune/dashboards/readouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
from django.contrib.postgres.aggregates import StringAgg
from django.db.models import Count, Exists, F, Max, OuterRef, Q, Subquery
from django.db.models.functions import Coalesce

from django.template.loader import render_to_string
from django.utils.translation import gettext as _
from django.utils.translation import gettext_lazy as _lazy
from django.utils.translation import pgettext_lazy
from django.utils.translation import gettext as _
from markupsafe import Markup

from kitsune.dashboards import LAST_30_DAYS, PERIODS
from kitsune.dashboards.models import WikiDocumentVisits
from kitsune.questions.models import QuestionLocale
from kitsune.questions.models import AAQConfig
from kitsune.sumo.redis_utils import RedisError, redis_client
from kitsune.sumo.templatetags.jinja_helpers import urlparams
from kitsune.sumo.urlresolvers import reverse
Expand Down Expand Up @@ -232,7 +231,7 @@ def percent_or_100(num, denom):

if product:
total = total.filter(products=product)
if not product.questions_locales.filter(locale=locale).exists():
if not product.questions_enabled(locale):
# The product does not have a forum for this locale.
ignore_categories.append(CANNED_RESPONSES_CATEGORY)

Expand Down Expand Up @@ -709,7 +708,7 @@ def get_queryset(self, max=None):

if self.product:
qs = qs.filter(products=self.product)
if not self.product.questions_locales.filter(locale=self.locale).exists():
if not self.product.questions_enabled(locale=self.locale):
# The product does not have a forum for this locale.
ignore_categories.append(CANNED_RESPONSES_CATEGORY)

Expand Down Expand Up @@ -1132,7 +1131,7 @@ class CannedResponsesReadout(Readout):

@classmethod
def should_show_to(cls, request):
return request.LANGUAGE_CODE in QuestionLocale.objects.locales_list()
return request.LANGUAGE_CODE in AAQConfig.objects.locales_list()

def get_queryset(self, max=None):
qs = (
Expand Down
19 changes: 9 additions & 10 deletions kitsune/forums/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,15 @@ def test_posts_fr(self):
pq(response.content)('link[rel="canonical"]')[0].attrib["href"],
)

# TODO: This test should be enabled once the responsive redesign milestone is complete.
# def test_long_title_truncated_in_crumbs(self):
# """A very long thread title gets truncated in the breadcrumbs"""
# t = ThreadFactory(title="A thread with a very very very very long title")
# PostFactory(thread=t)
#
# response = get(self.client, "forums.posts", args=[t.forum.slug, t.id])
# doc = pq(response.content)
# crumb = doc("#breadcrumbs li:last-child")
# self.assertEqual(crumb.text(), "A thread with a very very very very...")
def test_long_title_truncated_in_crumbs(self):
"""A very long thread title gets truncated in the breadcrumbs"""
t = ThreadFactory(title="A thread with a very very very very long title")
PostFactory(thread=t)

response = get(self.client, "forums.posts", args=[t.forum.slug, t.id])
doc = pq(response.content)
crumb = doc("#breadcrumbs li:last-child")
self.assertEqual(crumb.text(), "A thread with a very very very very...")

def test_edit_post_moderator(self):
"""Editing post as a moderator works."""
Expand Down
2 changes: 0 additions & 2 deletions kitsune/groups/jinja2/groups/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ <h1>{{ _('Edit {group} profile information')|f(group=profile.group.name) }}</h1>
{{ content_editor(form.information) }}
<input type="submit" name="save" value="{{ _('Save') }}" />
</form>

{# TODO: Preview <div id="doc-content"></div> #}
</article>
{% endblock %}
1 change: 1 addition & 0 deletions kitsune/products/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def get_products(obj):
list_editable = ("display_order", "visible", "in_aaq", "in_nav", "is_archived")
list_filter = (
ArchivedFilter,
"in_aaq",
"parent",
"slug",
)
Expand Down
8 changes: 4 additions & 4 deletions kitsune/products/jinja2/products/includes/topic_macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ <h3 class="card--title">
</div>
{%- endmacro %}

{% macro topic_metadata(topics, product=None, product_key=None) %}
{% if product_key and not settings.READ_ONLY %}
{% macro topic_metadata(topics, product=None) %}
{% if product and not settings.READ_ONLY %}
<section class="support-callouts mzp-l-content sumo-page-section--inner">
<div class="card card--ribbon is-inverse heading-is-one-line">
<div class="card--details">
Expand All @@ -52,11 +52,11 @@ <h3 class="card--title">
{% endif %}
</p>
<a class="sumo-button primary-button button-lg"
href="{{ url('questions.aaq_step2', product_key=product_key) }}"
href="{{ url('questions.aaq_step2', product_slug=product.slug) }}"
data-event-name="link_click"
data-event-parameters='{
"link_name": "aaq-banner.aaq-step-2",
"link_detail": "{{ product_key }}"
"link_detail": "{{ product.slug }}"
}'>
{% if product and product.has_ticketing_support %}
{{ _('Get Support') }}
Expand Down
2 changes: 1 addition & 1 deletion kitsune/products/jinja2/products/product.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ <h2 class="sumo-page-subheading">{{ _('Frequent Topics') }}</h2>
{{ help_topics(topics) }}
</div>

{{ topic_metadata(topics, product=product, product_key=product_key) }}
{{ topic_metadata(topics, product=product) }}

{% if featured %}
<section class="mzp-l-content mzp-l-content sumo-page-section--inner">
Expand Down
9 changes: 8 additions & 1 deletion kitsune/products/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ def get_queryset(self):

class ProductManager(NonArchivedManager):
def with_question_forums(self, request):
return self.filter(questions_locales__locale=request.LANGUAGE_CODE).filter(codename="")
return (
self.filter(
aaq_configs__is_active=True,
aaq_configs__enabled_locales__locale=request.LANGUAGE_CODE,
)
.filter(codename="")
.distinct()
)
2 changes: 0 additions & 2 deletions kitsune/products/migrations/0010_auto_20240624_0616.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

from django.db import migrations

from kitsune.questions.config import products as PRODUCTS_CONFIG

# The key is the topic slug to migrate to and the value is the list
# of topic slugs to migrate from,
# If the topic for each product does not exist, it will be created
Expand Down
2 changes: 1 addition & 1 deletion kitsune/products/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def has_ticketing_support(self):
return bool(self.codename)

def questions_enabled(self, locale):
return self.questions_locales.filter(locale=locale).exists()
return self.aaq_configs.filter(is_active=True, enabled_locales__locale=locale).exists()

def get_absolute_url(self):
return reverse("products.product", kwargs={"slug": self.slug})
Expand Down
5 changes: 3 additions & 2 deletions kitsune/products/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from kitsune.products.models import HOT_TOPIC_SLUG
from kitsune.products.tests import ProductFactory, TopicFactory
from kitsune.questions.models import QuestionLocale
from kitsune.questions.tests import AAQConfigFactory
from kitsune.search.tests import Elastic7TestCase
from kitsune.sumo.urlresolvers import reverse
from kitsune.wiki.tests import ApprovedRevisionFactory, DocumentFactory, HelpfulVoteFactory
Expand All @@ -19,7 +20,7 @@ def test_products(self):
locale, _ = QuestionLocale.objects.get_or_create(locale=settings.LANGUAGE_CODE)
for i in range(3):
p = ProductFactory(visible=True)
p.questions_locales.add(locale)
AAQConfigFactory(product=p, enabled_locales=[locale], is_active=True)

# GET the products page and verify the content.
r = self.client.get(reverse("products"), follow=True)
Expand All @@ -32,7 +33,7 @@ def test_product_landing(self):
# Create a product.
p = ProductFactory()
locale, _ = QuestionLocale.objects.get_or_create(locale=settings.LANGUAGE_CODE)
p.questions_locales.add(locale)
AAQConfigFactory(product=p, enabled_locales=[locale], is_active=True)

# Create some topics.
TopicFactory(slug=HOT_TOPIC_SLUG, products=[p], visible=True)
Expand Down
13 changes: 1 addition & 12 deletions kitsune/products/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from product_details import product_details

from kitsune.products.models import Product, Topic, TopicSlugHistory
from kitsune.questions import config as aaq_config
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
Expand All @@ -22,15 +21,6 @@ def product_list(request):
return render(request, template, {"products": products})


def _get_aaq_product_key(slug):
product_key = ""
for k, v in aaq_config.products.items():
if isinstance(v, dict):
if v.get("product") == slug:
product_key = k
return product_key or None


@check_simple_wiki_locale
def product_landing(request, slug):
"""The product landing page."""
Expand Down Expand Up @@ -59,7 +49,6 @@ def product_landing(request, slug):
request,
"products/product.html",
{
"product_key": _get_aaq_product_key(product.slug),
"product": product,
"products": Product.active.filter(visible=True),
"topics": topics_for(request.user, product=product, parent=None),
Expand Down Expand Up @@ -105,7 +94,7 @@ def document_listing(request, topic_slug, product_slug=None, subtopic_slug=None)
product = get_object_or_404(Product, slug=product_slug)
request.session["aaq_context"] = {
"has_ticketing_support": product.has_ticketing_support,
"key": _get_aaq_product_key(product_slug),
"product_slug": product_slug,
"has_public_forum": product.questions_enabled(locale=request.LANGUAGE_CODE),
}

Expand Down
Loading

0 comments on commit 7b2b199

Please sign in to comment.