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 139d4e0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kitsune/sumo/static/sumo/img/info.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 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,21 @@

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

#linked-in-product-indicator {
display: grid;
column-gap: 8px;
grid-template-columns: 24px 1fr;
margin-bottom: p.$spacing-xl;
img {
width: 24px;
height: 24px;
}
figcaption {
font-weight: bold;
line-height: normal;
}
}

#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 src="{{ webpack_static('sumo/img/info.svg') }}" alt="{{ _('information icon') }}" />
<figcaption>{{ _("Article is 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 139d4e0

Please sign in to comment.