Skip to content

Commit

Permalink
indicate articles that are targets of in-product links
Browse files Browse the repository at this point in the history
  • Loading branch information
escattone committed Apr 17, 2024
1 parent 1365233 commit 2b88c75
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions kitsune/sumo/static/sumo/scss/components/_wiki.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@

@import 'selectize/scss/selectize.default';

#linked-in-product-indicator {
margin-bottom: p.$spacing-xl;
img {
vertical-align: middle;
}
figcaption {
display: inline;
font-weight: bold;
vertical-align: middle;
}
}

#id_restrict_to_groups {
// Prevents flickering by hiding the un-selectized select
// until selectize uses it to make a new one that's visible.
Expand Down
7 changes: 7 additions & 0 deletions kitsune/wiki/jinja2/wiki/document.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@
{{ search_box(settings, id='support-search-sidebar', params=search_params) }}
</div>

{% if in_staff_group(user) and document.is_linked_in_product %}
<figure id="linked-in-product-indicator">
<img height=24 width=24 src="{{ webpack_static('sumo/img/info.svg') }}" alt="{{ _('information icon') }}" />
<figcaption>{{ _("linked in product") }}</figcaption>
</figure>
{% endif %}

{{ aaq_widget(request, "document") }}

{% if fallback_reason == 'no_translation' %}
Expand Down
12 changes: 12 additions & 0 deletions kitsune/wiki/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from pyquery import PyQuery

from kitsune.gallery.models import Image
from kitsune.inproduct.models import Redirect
from kitsune.products.models import Product, Topic
from kitsune.sumo.apps import ProgrammingError
from kitsune.sumo.i18n import split_into_language_and_path
Expand Down Expand Up @@ -779,6 +780,17 @@ def is_unrestricted_for(self, user, use_cache=True):

return user.id in self.unrestricted_for_user_ids

@cached_property
def is_linked_in_product(self):
if self.parent:
return Redirect.objects.filter(
(Q(locale__in=("", self.locale)) & Q(target__contains=f"kb/{self.parent.slug}"))
| (Q(locale=self.locale) & Q(target__contains=f"kb/{self.slug}"))
).exists()
return Redirect.objects.filter(
locale__in=("", self.locale), target__contains=f"kb/{self.slug}"
).exists()


class AbstractRevision(models.Model):
# **%(class)s** is being used because it will allow a unique reverse name for the field
Expand Down

0 comments on commit 2b88c75

Please sign in to comment.